Forum Academy Marketplace Showcase Pricing Features

Temporary User / Current User - Shopping Cart Items

Hello all,

Yes it’s another one of these threads but none of the other threads on this have answered the question for me so thank you for your patience.

I am building a giftcard website and I am trying to enable a guest (not logged in) to add an item to their cart.

Q1: is this possible without plugins? (I prefer to do this ‘natively’)
Q2: is this possible without cookies? (regardless of GDPR)

My relevant data structure is as follows:

GIFT

  • value
  • card_color
  • recipient_name

USER

  • shopping_cart (this is a List of GIFTs)

When the user on my website selects some options and clicks ‘Add to cart’, it correctly creates a new GIFT in my database (via a workflow of ‘Create a new GIFT’), however it does not assign it to the USER’s shopping_cart.

Q3: How would i go about assigning that GIFT created to the USER? (or the USER shopping_cart)

I think this issue would have the same solution whether they are logged in or not but I’m not 100% sure.

Many thanks in advance!

@ben12

Bubble assigns data to an unidentified current user for 3 days. After that the info will be lost unless the user is a signed up user so that Bubble knows who he/she is and the data will not be erased after 3 days.

Suggested dB structure:

Gift
Title (text)
Price (number)

Cart
User (user)
Line items (list of cart line items)

Cart line item
Gift (Gift)
Cart (Cart)
Quantity (number)

Nope. If you tell Bubble to store some user data and that user is not logged in, it will use cookies to track that data temporarily until either they set up an account or the cookie expires (3 days as @cmarchan mentioned)

Ok great thanks - so if I understand correctly:

When the unidentified current user hits submit, I should do the workflow of: “Create a new Cart line item”? Will this be assigned to the user in the DB?

I find it interesting that the Cart has a User rather than the other way around. I’m not understanding how Cart is unique to the current user in this structure - also not clear on why we need a Cart line item vs just having multiple Gift’s.

For the benefit of anyone who lands on this thread later:

I have now fixed the issue of recognising the current user (logged out) cart items by creating my cart counter text element with:

Do a search for… ‘Gifts’, with constraint Created by = ‘Current user’

(found this method in this thread: 'How To' create a new thing 'by user' (created by field) before user logs in)

I am still a little confused as to the optimal database setup for my items based on @cmarchan comment above.

Why does the Cart Line Item have a Cart field? I would have expected the following relationship:

User > has a Cart Attribute(does this need to actually be created at any point or is that implied by the default attributes of the User?)
Cart > has a List of Product Attribute
Product > has Price / Colour / Name etc. Attributes

Is a Cart Item also needed between Cart and Product here and if so why? If it is only for quantity, is that not implied by having 2 items in the Cart of the same exact attributes?

Many thanks again

@ben12

The suggested structure is one way to do it.

I would even attempt to do it without a list of cart line items in the cart object, as the inverse relationship of having the cart in each cart line item would suffice.

I did not go in detail into your structure. I just noticed by your comments, that the relationships between objects that I would look for apparently may not have been there. That is why I suggested a way that I would approach your build with.

Okay thank you for explaining @cmarchan !

1 Like

Do you know, specifically, what user data bubble captures? Is it simply an IP address, or is it any other identifier like a previously submitted email address?

I cannot find that info anywhere.

Thanks,

Ken