How To Create A Temporary Shopping Cart?

Hello,

How can I create a temporary shopping cart under the SESSION when the user hasn’t logged in yet that will allow them to browse the website and add multiple items to a shopping cart before having them login or create an account?

Bump…

What about something like this:

data field on the user
= session.id (which would be the current users unique.id)

data field on each purchasable item
= session.id (may have to be a list, in the event of multiple users, creating these temporary carts) (this would be a list of users unique.id’s as well (ie. the users session.id)

The users session.id would be empty during their “not logged in” browsing experience.
Then - when the user logs in, or signs up - you pass the current users session.id to the now logged in or signed up user’s session.id
Then you can populate the shoppinging cart with the same items - by cross refrencing the items session.id with the user’s session.id

Then delete the session.id (whenever you feel the best time to do that would be)


I don’t know the business - but if the primary revenue stream is the purchase of the items - I’d consider just letting them purchase the items without having to log in or sign up. I realize its good for a host of other reasons - to assimilate them to the whole experience though…

  • in that event you could also just stuff a duplicate “sign up” sequence directly into the checkout sequence haha. Or at the least - an email input field to keep them in the loop.

But the first Idea is probably better.

I did some experiments and even the anonymous user has her own unique_id, so I guess it’s safe to save the data into User table, or reference it from elsewhere, but for the current session only. I’m not sure how Bubble decides about generating a new unique_id for the user, maybe with session cookies. If the cookies persist on the client computer, then on the next visit the shopping cart would have the items from the previous visit. I suggest experimenting.

If the user logs in in the middle of the visiting process, then you have to copy or change the references to the ‘anonymous’ cart.

BTW, temporary carts are usually modeled like this:

  • User
  • CartItem
  • Items (on stock)

You can have many cartitems for a user, so each CartItem has a reference to the user, or the User data type can have a list of CartItems. Each CartItem has a reference to a particular Item, and you can add the ‘quantitiy’ field to CartItem.

For confirmed orders, you typically move the necessary data to the structure:

  • Order
  • OrderedItem

To be precise, you just create a new Order with a reference to the User, and move corresponding Cartitems to OrderedItems.

Well, that will persist the cart items ACROSS sessions as well.

You may well want a way to clear it down, or at least give the user the option … “Hey, we noticed you have some items in your cart, do you want to continue with them or not” type of thing.

Anyhow, don’t assume anything :slight_smile: The data might be there for the next visit, or not. Or you can save the data for an anonymous user with known Id, but it can happen that you don’t know who this anonymous is in reality (worst case).

In business, it is essential that you have a record of what a particular customer ordered, when it was ordered, for what total, that somebody cannot deny that he made an order, etc. so think about it thoroughly and, as I said, experiment with various technical solutions :slight_smile:

This topic was automatically closed after 70 days. New replies are no longer allowed.