#Help Needed: Cumulative Item Calculation Issue in Bot Development

1 messages · Page 1 of 1 (latest)

polar python
#

@indigo socket
it would help if you share your existing typebot

indigo socket
indigo socket
indigo socket
#

I greatly appreciate it, if you could create a mini example. I've learned a lot from the default templates in Typebot, but I couldn't find any reference for what I need.

polar python
#

@indigo socket
it's a bit difficult for me to understand the exact flow, as your bot is in Portugese, and my browser is not really converting it to English

#

could you instead share the logic/block, where you are adding the new item to the existing list/order?

#

maybe there's an issue there

indigo socket
#
const selectedItem = {{Get_menu_item}};
const selectedQuantity = {{input_quantity}};
const orderJSON = { "items": [], "total": 0 };

// Replace this block with the actual code to find the item in arrItems
const objItem = arrItems.find(item => item === selectedItem);
const price = objItem ? 5 : 0; // Replace 5 with the actual item price

const orderObj = JSON.parse(JSON.stringify(orderJSON));
const newItem = { item: selectedItem, qty: selectedQuantity, unitPrice: price };
orderObj.items.push(newItem);

const total = orderObj.items.reduce((acc, item) => acc + item.unitPrice * item.qty, 0);
orderObj.total = total;

return total;```
#

I just wish I could include cumulative items like a shopping cart.

polar python
#

@indigo socket
i'm unable to look into this in more detail right now

#

but so far, it seems that the logic is broadly correct

#

i'd recommend doing console.log at multiple steps, to find out how the flow is actually getting executed

indigo socket
#

Is the logic of adding the item to the cart simply to return the flow to the menu again?

#

Anyway, I'll wait; I'll keep researching. Any simple examples are welcome for persisting the items on the order ticket.

#

@polar python ty ❤️

indigo socket
#

@polar python In this template, the issue becomes more isolated for you to better understand.

terse totem
indigo socket
#

I don't know why it's not working.

terse totem
#

try removing the emojis and it should work

#

you can always execute on client and check your browser console log to know what is failing

indigo socket
#

It's not possible, haha. I'll remove the emojis and test.

#

I removed the emojis and the error still persists. SadCat

#

@terse totem

terse totem
#

May I know what exactly is the issue?

#

😅 can not seem to understand much what exactly you want to do

#

if u can explain via video that'd be perfect

indigo socket
#

I am not fluent in English, I will edit a photo as I would like it to work because it is showing an error.

indigo socket
#

This is what I wished to accomplish. First, I selected the large pizza with a quantity of 1. Then, I added 2 medium pizzas, and the total was being calculated cumulatively. In the end, the formatted order was delivered to me with the items.

#

Sorry for not explaining better. It's because I'm not fluent in English. Explaining via video would be easier.

terse totem
terse totem
# indigo socket

this seems to be working fine or is this what you want to achieve but can not?

indigo socket