views:

73

answers:

4

I am doing shopping cart for my website

  1. Storing purchase information in session

  2. Storing purchase information in table.

Which is better solution? If I store it in table how and when will i delete the records in the table (i.e when not purchased by user but in table)

+2  A: 

Matter of preference. Both are reasonable. DB provides you the ability to analyze what was about to be purchased or at least queued up in terms of interest in your customers, that data is often quite valid as marking keen interest in your offerings and many times that data is NOT deleted, just has an expiration date or at least a session id as an attribute in the table.

As per the DB method, if you do want to delete it is an easy purge that you can run daily or weekly in a cron or other scheduled job to delete all records that have effectively expired.

Xepoch
Thank you, Its very usefull
RSK
In mysql the query might look like "DELETE FROM cartdata WHERE created_date <= (CURRENT_TIMESTAMP - INTERVAL 7 DAY)"
Salman A
+1  A: 

depend what you want to do.

The usal solution use the $_SESSION, this solution is easy to implement and won't hit the performance of your website.

The database session is nice because there is no timeout involved and it a bit more reliable.

I would say if your price tags are kind of expensive it's better to have a DB session because the user usually spend more time to think when he is spending > $10,000.

For normal products the SESSION solution is fine.

RageZ
+1  A: 

Take a hint from Amazon, store the data in a database and never delete it.

How much value to you get from the items in the cart? How much does it cost you to store the contents of the cart? If someone abandons their cart, and then comes back to your site a year later, they may still want the items in the cart.

brianegge
+2  A: 

What I do in my specific case is store the info in a CartOrder table. The status is 'pending'. When the process is finished I insert the info in the Order table and flag the CartOrder as done (or delete it). For me a CartOrder is the intention of a purchase, the Order is the purchase per-se.

Doesn't matter if you don't delete the CartOrder, you can use it later (take a look how amazon or other sites maintain your last cart available even if you didn't finish the purchase). This also would be nice to track how many users enter into the site, look around, start a cart but no finish the purchase. Users loves this.

David Elizondo