I use the following PHP Session Shopping Cart (it's ready to use)
Example of usage:
cart.php?action=add&id=1 = Adding a new product in the cart with ID 1
cart.php?action=delete&id=1 = Deleting a new product in the cart with ID 1
cart.php?action=update&id=1&qty=5 = Updating the quantity of product with ID 1
Everything is fine, but now I want to add sizes, something like: cart.php? action=add&id=1&size=XXXL
Please help me, I'm very confused how this can be done
If you want to build this up in a more scalable way, you might consider making your cart an object.
Then I'd turn the items into objects, with different properties. That would take care of the different "product attributes" (sizes for now, but what about different colors for later? Or printable text? etc).
If you abstract it so that each part does what it's supposed to do, independent of the other parts (orthogonal programming), you'll make your life easier now, and in the future.
Since you're using PHP, I'm guessing you're also using MySQL for storage. It's typically inefficient to store objects in the $_SESSION
, but more efficient to store them in the database and unpack/unserialize/wake them up when that session is in use again (i.e. next page load).
Those are things for down the road. But right now, I'd take a good look at how scalable you intend on making this, and if you're seriously going to use it in production. There's a book called 'Usable Shopping Carts' that you can get on Amazon.com (it used to be cheap! http://www.amazon.com/Usable-Shopping-Carts-Jon-Stephens/dp/1904151140).
There are tons of different resources for this type of thing out there, but what you're always going to come back to is how it was originally designed. Because that's where you'll find yourself either making a hack to accomplish what you want, or implementing properly what you want.