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

Community site session details

Session Id : sbtoR56K46subt8Nz2m7LS
Power Apps - Building Power Apps
Answered

Collection of shopping cart not updating accordingly

Like (0) ShareShare
ReportReport
Posted on 5 Apr 2024 17:27:11 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 15 Apr 2024 at 18:24:38
    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 Moderator on 06 Apr 2024 at 07:35:15
    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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410 Super User 2025 Season 2

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 2