How to stop duplication in shopping cart

Hello everyone , every time the add to shopping cart button is clicked the product is duplicated.

Like this.
Is there any way to prevent this or atleast merge the quantity of the 2 same products?
Ive tried looking everywhere and cant find a solution

Are you using a Cart Plugin or did you create your own cart workflow?

im using my own cart workflow , i wasnt aware that there were plugins for this.

I’m guessing you’re creating a new line item every time the add to cart button is clicked, even if the product is already in the cart.

So the way to prevent that is by not doing that… i.e. only create a new line item if the product is not already in the cart. And if it is, then just update the existing line item.

@adamhholmes Yes i know that is the solution , but i need to know how exactly im supposed to do that. Ive tried trial and error but im not able to figure it out.

Just use the appropriate conditions on your workflows…

Is there a particular aspect of running conditional workflows you’re having rouble with setting up?

See i understand what you are saying but i really need you to dumb it down to me , i understand the logic of why some things are not working but i do not know how to fix them , i need more specific instructions on what to do ie where to go , what to press , what to change.

Here is my workflow.
Everything i try with the only when workflow doesnt work it just turns red.

You’re creating a new shopping cart every time the Add to Cart button is clicked??!

Surely you don’t want to be doing that? (or is that what you’re intending to do?)


Okay i realized how that poses an issue , no thats not what i intend to do.
So i should make it so that every user already has a shopping cart and only the items/products are added to it?

Here’s how I would do it (this is pretty much the established way to do this kind of thing…)

Have a datatype of Shopping Cart and a datatype of Cart Item.

When a User first clicks Add to cart, create a new shopping cart, but only if they don’t already have a shopping cart.

Then create a new Cart Item (which contains data about the product, the quantity, price, subtotal etc) and add it to the Shopping Cart.

Any time a new product is added to the cart, create a new cart item and add it to the cart.

But if an item that’s already in the cart is added again, just update the existing cart item to increase the quaintly accordingly.

1 Like

Thank you so much , is everything correct so far?

Also what am i supposed to put in for the only when condition?

I’m making some assumptions here, as I don’t know your database structure and I can’t see everything you’re doing in your workflow …

But, from what I can see I would continue in the following way…

Step 1
Create a New Shopping Cart
Only when Current User’s Shopping Cart is empty

Step 2
Make changes to Current User
Shopping cart = result of step 1
Only when result of step 1 is not empty

Step 3
Create a New Cart Item
Only when Current User’s Shopping Cart’s Cart Items: filtered (Product = Parent Group’s Product): count is 0

Step 4
Make changes to Cart Item (Current User’s Shopping Cart’s Cart Items: filtered (Product = Parent Group’s Product): first Item
Quantity = This Cart Item’s Quantity + 1
Only when Current User’s Shopping Cart’s Cart Items: filtered (Product = Parent Group’s Product): count > 0

Step 5
Make changes to Current User’s Shopping Cart
Cart Items: Add: result of Step 3
Only when result of Step 3 is not empty

Once the shopping cart is checked out and paid for, remove it from the Current User’s Shopping Cart field.

1 Like

You Shopping Cart field on the User datatype is not a Shopping Cart… it’s a Product…

It needs to be a Shopping Cart

1 Like

Done i changed that , on step three

i cannot find the filtered option.

Also now , i realize that i only have surface level knowledge of bubble and i will educate myself further and properly learn what everything does and means instead of posting because of lack of knowledge.
Im really sorry for being a bother and wasting your time.
I would really appreciate it if you stooped down to my level and helped me with this part though.

No bother at all… that’s what this forum is for…

The forum is a great way to get answers on things you’re having problems with, or can’t work out for yourself… so never be afraid to ask things in here.

But, experimenting and trying things out for yourself is also an excellent way to learn how things work… so keep on building and experimenting, and when you get stuck, post your questions in here.


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