How to save cart data?

I want to create a shopping cart just for my use.on first page they use product, on second page they may use addons, but if they want to change currency it needs to resubmit the form so all data will be destroyed as they were sessioned. How to solve the issue? I should use cookie or db instead of session? If db, after a while it be full of garbage data how to detect garbages to delete them?

That is rather a complicated question but for the database as long as you add a time stamp you can delete it after a certain amount of days. You could use a cron job or build it into your code so when you save something to the database it also checks for anything over a certain age and deletes it.

Does it make sense to use db at all? What about cookie? I guess cookie updating like update number of products on cart in cookie data does not make sense?
How other carts handle it? All of them with db? Cookie?

Yes you can do it with cookies, but user can clear cookies anytime or disable it.
If you want permanent storage go for database if you want temporarily storage go for sessions (sessions relies on cookies).

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.