I am having a problem with my power app, my app is simulating a store, where you can add items to a shopping cart, here are the parts of it, first when you click on the image of the item, this gets added to the cart, here is the code for the on select property for the button behind the image:
If(
LookUp('Inventory(VendingMachine)', Title = ThisItem.Title).'Quantity Available' > LookUp(ItemQuantities, Title = ThisItem.Title).QuantitySelected,
// If there is stock available, add or increment the item
If(
CountRows(Filter(ItemQuantities, Title = ThisItem.Title)) = 0,
Collect(
ItemQuantities,
{
Title: ThisItem.Title,
QuantitySelected: 1,
ItemPrice: ThisItem.Price,
TotalPrice: ThisItem.Price,
ItemImageURL: ThisItem.'Image URL'
}
),
Patch(
ItemQuantities,
LookUp(ItemQuantities, Title = ThisItem.Title),
{
QuantitySelected: LookUp(ItemQuantities, Title = ThisItem.Title).QuantitySelected + 1,
TotalPrice: (LookUp(ItemQuantities, Title = ThisItem.Title).QuantitySelected + 1) * ThisItem.Price
}
)
),
// Else notify the user that no more stock is available
Notify("Not enough stock available", NotificationType.Error)
)
so this adds them to the shopping cart, fine: then when the items are on the cart, each item has a - and + button underneath it, where you can either add or decrease the amount of items in the shopping cart, there is also another button that works for clearing the cart: Clear(ItemQuantities), here is the issue though, the cart works perfectly, but when I clear the cart and add any item item, the + and - button do not work properly, they are not adding up the prices for the items, the price becomes 0.00, also the collection that serves as the shopping cart is called ItemQuantities, what is the issue here? here is the code for the + button:
If(
LookUp('Inventory(VendingMachine)', Title = ThisItem.Title).'Quantity Available' > ThisItem.QuantitySelected,
// If there is stock available, add or increment the item
Patch(
ItemQuantities,
LookUp(ItemQuantities, Title = ThisItem.Title),
{
QuantitySelected: LookUp(ItemQuantities, Title = ThisItem.Title).QuantitySelected + 1,
TotalPrice: (LookUp(ItemQuantities, Title = ThisItem.Title).QuantitySelected + 1) * ThisItem.Price
}
)
,
// Else notify the user that no more stock is available
Notify("Not enough stock available", NotificationType.Error)
)
, here is the code for the - button: If(
LookUp(ItemQuantities, Title = ThisItem.Title).QuantitySelected > 1, // Check if more than one item is selected
Patch(
ItemQuantities,
LookUp(ItemQuantities, Title = ThisItem.Title),
{
QuantitySelected: LookUp(ItemQuantities, Title = ThisItem.Title).QuantitySelected - 1,
TotalPrice: (LookUp(ItemQuantities, Title = ThisItem.Title).QuantitySelected - 1) * ThisItem.Price
}
),
// If only one item is selected, remove it from the collection
If(
LookUp(ItemQuantities, Title = ThisItem.Title).QuantitySelected = 1,
Remove(ItemQuantities, LookUp(ItemQuantities, Title = ThisItem.Title))
)
)