Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Collection of shopping cart not updating accordingly

(0) ShareShare
ReportReport
Posted on by 27

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))
 )
)

 

 

 

 

 

  • Eldor488 Profile Picture
    27 on at
    Re: Collection of shopping cart not updating accordingly

    Sorry it took me so long to accept your response. It is working as expected, yeah, the inventory is on one gallery and the shopping cart is another gallery. 

  • Verified answer
    james1994 Profile Picture
    222 Super User 2025 Season 1 on at
    Re: Collection of shopping cart not updating accordingly

    Hey @Eldor488,


    Please correct me if I'm incorrect in how your gallery is set up, but from what I understand, you have 2 galleries:

     - One containing the Inventory ('Inventory(VendingMachine)') and;

     - Another containing the selected items (your shopping cart) (ItemQuantities) and the '-' and '+' buttons are inside this gallery containing that collection.

     

    If this is the case, I believe it's due to the ItemQuantities collection not containing a 'Price' property/column, as your formula is calculating TotalPrice from ThisItem.Price. As the collection doesn't contain 'Price', it is multiplying quantity by 0. If you change it to the below, it should calculate the total using the item's price. 

    ThisItem.Price -> ThisItem.ItemPrice
    
    // + 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.ItemPrice
     }
     )
     ,
     // Else notify the user that no more stock is available
     Notify("Not enough stock available", NotificationType.Error)
    )

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,537 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,908 Most Valuable Professional

Leaderboard