Shopping Cart for Visitors & Customers

I am building an e-commerce, and have a design question about my Shopping Cart.

There are two types of Users: “Visitors” (unreigistered users) and “Customers” (registered users).

I would like to allow Visitors to freely browse and add items to a shopping cart. However, only Customers can check out.

The “shopping cart” for Customers should be “persistent”. (If Joe Customer adds something to his shopping cart, leaves, and comes back next month, the item should still be there.)

Presumably this requires saving info in the database?

But what do I do for Visitors?

Do I save their shopping cart in a cookie?

Do I not save their shopping cart?

Do I save their shopping cart in the database and somehow access it later (which makes no sense)?

What is the best way to tackle all of this?

TomTees

As you suggested yourself I would indeed store the shopping carts of customers in a database, and the shopping carts of visitors in a session/cookie.

This because when you store in the database it is really persistent (does not get deleted unless you want it to), while for visitors it does seem to matter less whether the information is saved (at least that’s what I got from your post) so session/cookies should be fine.

Kind of beside the point, but just wondering, why would you let people put stuff in their shopping cart but not allow them to check out? Why give them a shopping cart at all if they cannot use for anything?
To me it sounds like giving them a car without fuel; nice to look at, but it doesn’t really do anything, so what’s the point?

Seconded. On a user experience note: make sure that the cart transfers cleanly after the person logs in/signs up for an account.

Good luck!

Plus, how would you know how to link the shopping cart back up to a particular visitor without using a cookie?!

Kind of beside the point, but just wondering, why would you let people put stuff in their shopping cart but not allow them to check out? Why give them a shopping cart at all if they cannot use for anything?
To me it sounds like giving them a car without fuel; nice to look at, but it doesn’t really do anything, so what’s the point?

Well, to be more precise, I don’t want to let visitors check out before they create a Customer Account (i.e. register).

(I have seen websites that let you just enter your name and credit card into to place an order?!)

I want visitors to take the time to fill out a profile, including activating their account by being authenticated via e-mail. (I believe that is pretty standard these days?!)

Does that sound more reasonable? :slight_smile:

So, back to my original question…

If you support storing shopping cart info in a cookie for Visitors, then how do I go about transferring that to a persistent shopping cart that uses database tables?

TomTees

I normally have a simple cart object (ID of each of the items, any IDs for options and amount of each item) which I serialise and store in a cookie. I then hydrate this when the user/visitor is viewing their basket to get the actual name, price etc of the items (you dont want to store this in the cookie), making sure that the product is still valid, in stock etc.

When your visitor becomes a customer you just iterate through the cart object to create the order in the db

I second romance’s idea, you can store the cart data as JSON in your visitor’s cookie, that way it’ll be easier for you to translate it into db or cart view.

Storing all the data in JSON format may create big cookies. Maybe it would be better to just store {table, id} tuples with additional data like color and size (if applicable), so you can load the data from the table using the id and populate the other fields.

PS. The official limit for cookies appears to be 4KB

Why don’t you just generate some sort of “cart session id” then store it in a cookie on the client’s computer and store the cart contents as a serialized string in the database.

Then when the user signs up (even after coming back to the page days later) you can just grab their cart and restore it from the database, using the “cart session id” from their cookie.