Dropdown Menu QTY Selector to Update Database

I’m currently trying to get a dropdown as a quantity selector to update product count in the database. The numbers are 1-10, with the maximum quantity allowed being 10.

In the database I’m able to update entries based on incremental values (add 1, subtract 1) but I can’t seem to figure out how to modify the quantity based on the value in the dropdown.

The products are placed as a list in a “Shopping Cart” that is binded to the Current User.

Thank you in advance.

Not sure if this is the best way since it creates a new datatype but I think it works.

Create a new data type that had an item field and quantity field. Then when you add an item to the shopping cat, add a “list item” instead

Then when you change the drop-down value. Change the quantity value on the list item.


Thanks for your help.

I think it’s a start.

When I do that, I also need to update the shopping cart product amounts in the database to match the number shown for the user.

EX: If value of dropdown for Product 1 = 5, update list of products in Shopping Cart for User in database.

This is my current workflow. I provided the first and second screenshot to show what the “plus” button workflow looks like.

My way already updates the quantity in the database and displays it for the user.

Also plays nicely with the plus minus buttons since you can just do quantity +1 or -1 when clicked.

Here is the data type btw:

My setup is more complex than that. And the goal is not to just have the quantity display update on the page but to change the number of products in the database to match the dropdown. It updates the quantity as a number, but it doesn’t actually update the number of products in the cart, which in turn updates the price through a simple formula.

Here’s a better way to put this. If the value of the dropdown is 5 and there is currently one of that product in the shopping cart, add 4 more (so now that the value is 5 the number of products in the cart matches the value in the dropdown). That may not be equivocal in Bubble’s terminology for updating the quantity of an object but the end result is the same

There are 4 data types involved. Product. List of Items in Cart. Shopping Cart and User.

There’s a List of Items data type the Shopping Cart data type draws from, which puts them into a list for a single cart (noted in first screenshot in first post).

I have no qualms with displaying a value based on a dropdown, but updating the shopping cart’s products to match the quantity shown in the dropdown seems to be a real bear.

This is the last thing I have to figure out before I break away from prototyping and actually start building the product.

Mhm yes I’m not really sure what you are asking to be honest.

I feel my solution already does what you are asking. It shows the quantity of items in the database and front end. And it works without changing your products. You can even make them not choose more quantity than you have with some more tweaking.

Here is the shopping cart data type:

I think I have a better understanding of what you’re saying now. But it doesn’t update the Shopping Cart with more products (or less products if they choose less).

See the “List of Items in Cart”? That’s each product that has been added to the cart in this example, each. Every time a plus or minus is pressed, it will either add another one of that product or subtract it.

If Product 1’s QTY changes to a higher number, there needs to be that much more in that cart. Right now it has 3 different products, but what if a user chooses 5 in the dropdown for Product 1? Then it needs to add more of Product 1 in Shopping Cart, not just a number in a separate entry.

I hope that makes more sense. I would have to redo the formula if I changed the way quantities work and this setup works like a charm so far.

Yeah I’m suggesting to change quantity to a number instead of a list of items.

I thought there would be a way to update quantities of an object in a using a specified value in workflows. At least I had hoped thered be a way.

@fayewatson any ideas?

In the meantime I’ll try your idea to see what I can come up with.

Hi @matthewbuilds :slight_smile: @stone’s approach is the best way to set this up. As he stated the data structure could be:

There is one “Product” for each Product available in the application. For example, if a store sells three different kinds of shirts (Red, Green, and Blue), then there would be a single Product Thing created for each of those Shirts.
Name (type: text, field: no)
Price (type: number, list: no)
Image (type: image, list: no)

Cart Product
Product (type: Product, list: no)
Quantity (type: number, list: no)
Price (The Product’s Price * Quantity) (type: number, list: no)
Each time a User wants to add a Product to their cart, a new “Cart Product” thing should be created, in order to keep track of the Product they’d like to order and the specific quantity they need. It is also helpful to store the Price for the Cart Product(s), so the value of the Cart Product’s “Price” field should always equal (The Product’s Price * Quantity that User wants to order).

Order (i.e., Shopping cart)
Cart Products (type: Cart Products, list: yes)
Total Price (type: number, list: no)
Date placed (type: date, list: no)
Paid? (type: yes/no, list: no)
The Order type keeps track of the list of Cart Products that the User has ordered, or wants to order. For example, if a User wants to buy three of the same Green shirts, then you would first create a new Cart Product thing, with the fields to change being:
Product = Green Shirt
Quantity = The quantity value they selected from the dropdown
Price = Green Shirt’s Price * the Quantity selected.

Then, make sure to add this Cart Product Thing to the Order thing for the Current User.

If the Current User needs to change the quantity for a particular Cart Product (e.g., they want to order 10 Green shirts instead of 3 Green Shirts), you can use the Make Changes to a Thing action which updates the Cart Product Thing for the Green Shirt, and then updates the Order Thing.

The first Make Changes to a Thing action would modify the Current cell’s List Item (in this case, the Green Shirt List Item that was created) and the fields to change are:
Quantity = 10
Price = 10 * (Current cell’s Product’s Price).
Since that Cart Item is already in the Order Thing, you can update the Total Price field in the Order thing with this expression:
Total Price = This Cart’s Cart Products’ Total Price:sum

This AirDev example is setup in the same way (just with different names for the data types: Product, Ordered Product and Order). Feel free to let me know if you have any questions! :slight_smile: https://widgets.airdev.co/bubble-widget/shopping-cart-1472621296515x898289732169359900

1 Like

Regarding airdev’s widget though, I wouldn’t pay $12,000 for a Llama. If people are really willing to pay that then I’ll start raising them on our Texas farm. :wink:

The way I handled a similar need was show the inventory count for each item and allow up to that amount to be requested. The inventory was adjusted as soon as an item was requested so someone else couldn’t also request more than available. It also could be updated in the “cart.” If the request was cancelled then the inventory automatically adjusted back. Is that an acceptable strategy, or will I eventually run into issues I haven considered?

@stone @fayewatson

I made that out to be way more complicated than it had to be. My reasoning was likely that the setup was detailed so the solution had to be. Stone’s suggestion worked perfectly. I just added a Quantity field to the List of Items in Cart, then used a workflow based on the condition of the dropdown to create and then change the List of Items in Cart’s fields.

Thank you so much for both of your help! Overthinking at its finest right here. Just have to redo the math for the total cart price and I’m good to go.

Edit: Whoops. Had to get rid of the Create a New Thing action and made some minor workflow edits. I also made some changes according to @fayewatson. Changed the data source for the repeating group on the cart page to be List of Items in Cart instead of products, allowing me to update the quantities and quantity price associated with each individual product within the list. Should be good now!

1 Like

I hear they’re “Codefree Llamas” though! Super rare. :wink:

That sounds like a great setup! I would set it up in that way too :slight_smile: The only thing that could happen is if two people requested the same quantity at the exact same time. It may be helpful to have two fields “Quantity” (which is updated when Users add or remove that item from their carts and “Quantity (total available)” which stays the same until someone actually places an order. This way, you could run a second ‘check’ on the “Quantity (total available)” field when someone makes a purchase, just to make sure it’s in stock before charging the card. Probably more of a corner case though!

No problem at all! :slight_smile: Shopping carts are tricky to set up! So glad to hear it’s working as you needed it to!

1 Like

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