Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shopping cart for non registered users

Tags:

I am in the process of making a website that involves a shopping cart. There are two major requirements:

  1. The user experience guys want login/authentication to be the very last step in the entire work flow. The user gets to do all the shopping and is asked to login only at the time of checking out.

  2. The shopping cart shouldn't expire(not even on browser close) unless the user (registered or not) does check-out.

In the above context, I have the following question with respect to maintaining the cart's state:

Should I go with file based or database sessions? Please keep in mind this would be for unregistered users. My apprehension is that I'll end up having lots of records in the database.

Another option seems to be to put the cart contents in an encrypted cookie, but then there's a size limitation on the cookie file.

What would you do in this case ? I would really appreciate your answers.

like image 527
nano Avatar asked Sep 03 '09 22:09

nano


People also ask

What is a third party shopping cart?

These are shopping cart solutions hosted by a third-party provider. Thus, the third-party provider looks after server management, server backups, server security, and platform updates. This means you don't need much - or any - technical expertise to setup an online store with a hosted shopping cart.


2 Answers

  1. Tracking a user. Use a GUID encoded into a cookie with an nYear expiry.

  2. Storing a Shopping Bag. You don't want to store the bag in the cookie, mainly due its possible size. This leaves the option of persiting it to a medium and retrieving it from the medium. Using anything except a database for this would be like going back in time, databases excel at storing and retrieving data.

  3. Managing you Shopping Bag. Now, the question of your schema, firstly, if your going to be running queries against the shopping bags in the database (i.e. how many shopping bags contain item x) you probably want a traditional relational schema. However this has overheads in terms of inserting. updating, selecting (and joining) and deleting bag data (at some point you'll have bags that will never be used again but are taking up precious disk space). With a busy site, this is a fair few Traranactions Per Second, but any database should be able to cope. If you don't need to query the shopping bags in the database, then you can store it as XML. Just serialize the bag and dump it into a table, with the PK as the GUID as stored in the users cookie. This would be a lot faster than a traditional schema, plus you could always tear apart the XML in the future if a requirment did come up for a relational schema.

This is what we do (Xml Bag), and we have a million+ customer base.

like image 120
Jaimal Chohan Avatar answered Oct 11 '22 11:10

Jaimal Chohan


I would go with database managed sessions over file managed sessions. Make sure you have a session timestamp so that you can eventually kill old sessions (if it's been 12 months, the shopper is possibly not coming back for the items originally in the cart).

Doing this with a database instead of files will make it easier to eventually expire the very-old information.

Note that the database session will only ever be valid as long as the cookie it's tied to on the user's computer. If the user comes back to the store from a different browser, they will not find their session. If two people are sharing the same computer, they will find each other's session. Hopefully no potentially embarrassing items will be in the cart...

like image 20
Eric J. Avatar answered Oct 11 '22 09:10

Eric J.