I need to create a shopping cart sort of thing
There's a number of questions in this one, so bear with me...
I need to allow users to add products to a cart, but the cart doesn't take payment. It just submits content for a quote. I was thinking of doing it something like this:
- The user visits the site
- I create a session that has a random generated number. Something like: if session isn't set, then generate a random number.
- When the user adds the product to the cart, the product ID and the random number get stored together in a database table via an insert.
- If the user wants to save the cart contents and return at a later date on a different device, then they to save their email address to a different database table. At the same time as entering the email address, the site inserts the random number into the same record.
- When the user returns, the session will create a new random number because the user hasn't identified themselves yet. When the user signs in using their email address the original stored random number overwrites and repopulates the session ID in order to retrieve cart contents. This allows the user to continue shopping or submit the cart for a quote.
Is this feasible?
Is this a lot of work that could be achieved in a simpler way? Are there any issues that you can foresee that I can't?
Would you store as a DB record or rather use something like a cookie? (I'm not quite sure how to work with cookies and how I might retain more than one product... there be dragons!).
The only problem I can see with the above is if the user is returning and they've added more products to the cart before signing in to retrieve previous cart contents, then any new products added to the cart after logging in might be lost or overwritten, which doesn't make for a very good UX! So (final question), how might I combine the newly added products to those already saved without losing either?
Thanks.