I am creating a basic shopping cart. I have the following method of creating the cart in my mind. I would like to know if this is how the standards work or if there's some other better option available:
My way of how cart works:
Create 2 tables in database named "orders" and "orders_content".
When user presses Add to Cart button then the product is added into the "orders_content" table with user's current session id so we recognize its this user's items.
After adding item(s) into the cart using the way above then when user presses the checkout button we ask their details like shipping / billing details and add those details are entered into the "orders" table and the "orders" table has a autonumber field and the generated number is taken and we overwrite the session id (we stored for items in orders_content table) with this auto generated number.
Now as we have a order number which is unique and generated by system we take the user to the payment page and process payments accordingly.
The only flaw this system has that once the user has crossed the checkout part and we have replaced session id with order id then if user presses their browser's back button they cannot see their products they added to cart becuase our system is trying to find the particular user's product using session id ...but as we have replaced it with order id so the system cannot find it and user cannot see them.
Please let me know your thoughts on this one. If you have something better then please let me know your concept or the way standard shopping cart sytems work.
Please note that we don't want user to register...its come, choose, enter details and pay.
are you saying you want the user to be able to use thier back button and see thier shopping cart contents after the order is completed?
i would destroy thier shopping cart once the order is completed. if they want to see what they ordered, provide some kind of an order lookup page where they enter thier orderid and thier email address to verify its them.
I store my cart data in a session untill such time the order is finalised, at which point I then write the contents to db for my invoice system. Seems to work fine.
Also within the admin area I added a function to alter the status from "waiting for payment" to "shipping" then "completed", allowing clients to follow their order status online, also makes it easy to remove uncompleted orders keeping the database clean with only successfull purchases.