Hi there

I'm new to using sessions and I'd like some input on what the best method is for my situation.

The site I'm building requires a shopping cart. A very simple one I might add. There will be no credit card facility or login system (explained in next paragraph). The user will click on items he/she would like to order which is added to the shopping cart and when the user decides he/she is done then he/she clicks on the checkout button which takes them to the checkout form where he/she fills out their information and then clicks submit which then sends off an email to the owner of the site with the order details etc.

Now the way I'm thinking of building this is when a user clicks on "Order" for a product a session is started and a row is inserted (with the session id and the product he/she click the order button for) into a table called sessions inside the DB. This process happens for each product that is ordered with the exception of creating a new session unless one doesn't exist.

Then when a user clicks on the checkout button it takes them to the checkout page where the sessions table is search for all entries with the current session's id and shown on the page. The user fills out his/her details (such as contact numbers, name, surname address etc) and clicks submit and an email is then sent off with all the details.

Any constructive criticism would be great.
Thanks

Doing shopping cart with sessions is best way to load our site fastly than storing them into a database table..But its must to store ordered data finally in database table for future reference of orders ,order user details and status of order...
In my way, i hope the best method is-
creating one session array for one user session and storing all the data like product_id,price,quantity,user details etc ..And update that session array between that user shopping navigations..and finally storing the session data into a table...
if this is not your requirement..let me know...

I've always wanted to find an excuse to create a class and serialize that class into a session. This class would store the current shopping cart for that user and would also include functions like addToCart(), emptyCart(), updateCart(), getCart(), processCart() etc... and would just update an array variable inside the class. It would be nice because the class would store all of the information that has been processed thus far and could possibly help with organization. Of course I think you would want to refrain from storing any vital info in the class like database connection info which wouldn't be too hard because you would only really need to connect to the database at the time the user wishes to check out.

I don't know, just sometimes I see different projects in these forums that I wish I could be doing instead of creating pdf reports all day and client management tool development and modifying or taking a project over that has already been developed and having to adhere to the development style of the previous developer. Hardly ever to I get to start my own project from scratch, I would say about once a year.

Well, there's my envy statement. Anyway, I think that would be cool.

This article has been dead for over six months. Start a new discussion instead.