Getting Cart total to reflect price? and qty of items

I am trying to build an instacart type of app. The current road block is in getting the cart total to reflect the total including quantities of items. Same issue for the Total items (doesn’t reflect quantity).

I have tried to return the Repeating Groups Price field sum, return sum of items individual prices, as shown.

I have tried to return Repeating Groups Price field * User’s cart list qty, returns null.

I have tried Input RG Values but it returns 0.00

Is your Cart Items a separate data type? Different than the actual item?

Okay perfect so add a new database field under Cart_Item “Item Total” as a number, and make it so when they press the quantity+ button have it recalc the total to “Grocery_Item’s Price * Quantity”

Then your cart total will just be eachitems Item Total:sum.

Test it out but you might run into issues where pressing the + or - qty button will recalc the item total before it write the quantity to the database, so you might have to recalculate it in the workflow with a +1 or -1 since you need to consider the qty change before it writes to the database.

If they edit the quantity number then do the workflow event “Input value has changed”, pick the quantity input, and recalc the Item Total but recalc it as "Grocery Item’s Price * This input’s value and change the quantity in the database after.

Do you have access to backend workflows (a paid plan?) All the calcs can be done in the backend, it might be a slight delay but more reliable

Not sure I follow "and make it so when they press the quantity+ button have it recalc the total to “Grocery_Item’s Price * Quantity”

I am already doing that in an input on the cart page. Current cell’s cart_item’s Grocery_Items Price * Current cell’s Cart_Item’s Quantity

Okay what is the workflow on your + or - button? If you make the quantity change to your database, and your input is automatically reflecting the change, I believe Bubble doesn’t consider that an input change so it won’t trigger a recalculation. Does the user manually type a quantity if they want or just the + and -?

only + and -

Okay yea so this would update the quantity in the database, but now you have to update the Item Total i was recomending adding to your database. So you could try for step 2 do “Make changes to a thing” Result of step 1, change the field “Item Total” and set it to “This Cart-Item’s Quantity * This Cart Item’s Grocery Item’s Price”

Using the “Result of step 1” should make it wait for the quantity change first before recalculating

it actually does recalculate in the repeating groups individual cells, just cant get it to give a total across the repeating group reflecting quantity and price

It’s recalculating the new Item Total field? If so then your text showing the total can be “Current User’s Shopping Cart each item’s Item Total:sum”

Or it can be RepeatingGroup’s each item’s Cart Item’s Item Total:sum

So I tried that but now it is giving a cart total of 0

Look in your database just confirm the Item Total’s are calculating

I think is see the problem. im going to try something

If you enable the beta feature that allows paranthesis, then when you press the + sign and it set the quantity, you can have it also set the Item Total, and just make it “(This cart’s_Item’s Quantity +1) * This cart’s Item’s Grocery Item’s Price”

So I think I got is working sort of. it seems to be ignoring the first item added and actually adding to the total when i remove the first item

So the issue but rather the second quantity doesn’t register. i think it may be a workflow issue. trying to trace it

Got it all worked out. thank you talking it through with me. It really helped.

1 Like

Hey @yasirchau, what was the workflow you applied finally? It does not really work out for me with the “result of step 1”-solution. Would you mind sharing a screenshot of the successfully implemented workflow please? :slight_smile: