web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Collection of shopping...
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))
 )
)

 

 

 

 

 

Categories:
I have the same question (0)
  • Verified answer
    james1994 Profile Picture
    231 Moderator on at

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

     

  • Eldor488 Profile Picture
    27 on at

    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. 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 337 Most Valuable Professional

#2
11manish Profile Picture

11manish 173

#3
Valantis Profile Picture

Valantis 86

Last 30 days Overall leaderboard