Create a shopping cart using custom states

I’ve looked around on the forums looking for a method to create a shopping cart using custom states. Since the “:PlusItem” feature does not allow duplicate entries, it was not possible to create a checkout method which adds multiple of the same item to the shopping cart. I’ve seen many posts and none addressed the issue ( Perhaps i missed them). After some testing, i realized i could create a data field in the Item/Product Database called “CartQuantity”. This field is adjusted via input when you add an item to the cart and this input is later taken to be multiplied with the price of the item allowing you to create a shopping cart in which all data is stored in custom states until the items are checked out and the information is copied onto a receipt database.

I’ll add a tutorial later if anyone’s curious.


Using custom states to store a cart is generally not a good idea.
When a user closes the browser before checkout the cart is lost.
It’s better to be saving the cart to thr database so that the user can always continue from where they left off even on a different device or browser.

Not sure where you got the plusitem idea from but normally you simply add or subtract from the quantity as you later said and you can save this into your database instead of a custom state.

Why not just create a data field that is a list, with another that is text

the list is the cart, and you can add things to the list.
the text is the user’s name, then you can do a search for “carts” whose userName = current user’s name

I am doing this but I am facing the issue that if the user CLICKS repeatedly/super fast the button to add/substract qty then the DB gets messed up, I assume bubble processing is not fast enough to complete the previous writing in the db, have you had this issue?

I would solve it with aggregating a list but bubble doesn’t allow :plusitem to add a repeated item

Perhaps change the workflow and UI? When a customer clicks plus/minus (generally a rarity in day to day e-commerce), have a highlighted button appear to the right that says “update”. They can click until their hearts content then (usually behaviour of someone testing only or someone who wants a 1000 of something and doesn’t have the ability to type it).

1 Like

I’m very interested in how do you make this. I don’t need to store the data before finish the receipt. Could you please help me?

Hi Natserrano, were you able to get it to work? I have challenges where my + , - is incorrectly adding the quantity, and that the value shown in the database does not match up with what is shown on the UI.

Hi try using endpoint API to update database when user - or + unit. It works seamless

Yes, the problem was my UI.
I changed it to plus adds a record in a RG (this is specific to my use case)

if I want to click repeatedly a plus and add up to a counter I would use a custom state
(custom state = custom state +1)

if you add screenshots I can try to help