I am developing a Shopping cart application and I am needing help about storing cart items using $_SESSION.
The Concept
When user clicks on Add to Cart, the following information is stored: Product ID e.g. 5312, Product Name, Product Quantity, Product Rules (e.g. color : white, size : medium and so on)
The problem
The problem is that when I save the entry in $_SESSION by item ID. I want to assume the following:
- User adds 1 item of product #11 which color is white
- User then adds 2 items of product #11 which color is blue
If I save by item ID, the info will be overridden always, I want to make each call / each add to cart unique because I am assuming he may add different sizes, different colors of the same product.
How can I come over such a problem?
Any ideas or inputs are greatly appreciated.
You can do a multidimensional array with your SESSION variable.
Or if the
$product_idisn’t unique:With something like this, you can have a unique product id as the array key, then store the count, options, and other info you need.
Another option would be to create a table for your shopping cart, and then have the session store the cart ID. Then you would simply check the mysql table for your cart info.