I have a shopping cart setup and i cant quite figure out how to use the logic to add quantity to an existing item inside the shopping cart.
Shopping Cart contains Shopping Cart Items.
If the item is not in Shopping Cart it creates a new Shopping Cart Item with the product and adds it to the Shopping Cart.
But when the item IS IN the shopping cart, how do I do a search for the Shopping Cart Item inside of the Shopping Cart and add a quantity number to it?
Shopping Cart is a thing
Item is a thing
Catalog Item is a thing
Item has field “Shopping Cart” - which is type Shopping Cart
Item has field “Catalog Item” - which is type Catalog Item
Shopping Cart has a field “Items” with a list of Items
When the user adds a catalog item to their cart bubble creates a new Item and assigns the current cart as that item’s Shopping Cart and that catalog item as the Catalog Item field. It then adds the result of the first step (Create a new Item) to the Shopping Cart’s Items list.
For multiple items of the same Catalog Item you could display the cart as a repeating group:
This Shopping Cart’s List of Items’s Catalog Items:unique elements
Inside each cell put a quantity text field that does a count of all items in that Shopping Cart that match that cell’s Item’s Catalog Item.
When you subtract Items, remove the Item from the Shopping Cart’s List of Items and delete the Item.
Gaby Roman showed me this a long time ago and I use it for many similar uses!
It creates shopping cart line items and keeps a running tally of the shopping cart total.
To test it:
Hit the log in button - it logs you in as the sole user of the app, [email protected]
Hit the create new cart button - User has field “Shopping Cart” - this resets your shopping cart
The first repeating group is the online catalog. You can enter a number (QTY) of how much you want of an item and hit the + icon. That runs an API worklfow on a list (Thanks to Nigel’s help! on this) and creates QTY’s number of line items, they get added to your cart.
If the QTY input is blank, the + icon creates one item only.
The next repeating group is your cart’s list of line items. You can add more or subtract items using the - and + icons inside the cart repeating group.
There’s a total shop cost in USD below.
Is this at all useful? It solved a problem I’ve run into in one of my own projects, so at least one of us got something out of this exercise. I hope it is useful for you as well!
I plan to go back to the shopping cart exercise in a bit and rework some of its logic check for hideous bugs that may exist. It’s open for anybody to edit - surely some shopping cart fanatic will chime in and create the greatest shopping cart the world has ever seen on bubble. This is a humble start- feel free to improve it!