Forum Moderators: buckworks
I the past i have worked on baskets that get stored in a db table - however this table invarably grows over time and needs some kind of cleaning out script / cron thing.
I was thinking about just storing the basket as an array in a cookie (product id & quantity). Does anyone use this technique? Would i be limited by the number of items i can add?
Any thoughts appreciated!
The database solution is, imo, the cleanest. At order creation time, you'd transfer the data from the shopping cart table to order table and delete it from the shopping cart table, so the only growth you'd see in the shopping cart table would be from abandoned carts. And you can take care of that every now and then by deleting all rows that haven't been touched "recently." (keep a timestamp on every item in the cart so you can identify those that are old and not a customer in progress.)
With the database solution, the only cookie you need to pass back and forth is the cart ID (I'd use a GUID to ensure uniqueness). Store the cart ID in a session variable and you don't even have to pass it around as a cookie (though you run the risk of customers losing their cart unexpectedly if the server restarts your web app).