I am working on an e-commerce website. When the user is not logged into my website and clicks on "Buy Now" button, I want to store this information into the cookie as well as in the database. The table for the shopping cart looks like
SHOPPING_CART
(
sessionid int(10),
itemid int(10),
quantity tinyint(10) unsigned
date_added datetime
);
Primary key is: (sessionid, itemid)
When the user closes the browser then also the shopping cart items should be preserved. Now my question is the following:
- When the user is not logged into my website, on what basis I should identify the user?
- Should I store the information using the
IP address
? If yes then HOW? In this casesessionid
in the above mentioned table would be the IP address of the user. Right? - Should I create a temporary session for each and every user who visits my website and then store the information? If yes then HOW?
- How can the shopping cart items be preserved even when the user closes the browser window? Should I retrieve from database or cookie?
- Any other better method to store and retrieval of the information?
Note1: I can use plenty of Shopping Cart softwares/codes/libraries available. But I want to know: How to identify the user? And storing/retrieval of data.
Note2: The price of each item, ordering, shipping information all are stored in different tables.