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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Click to add items to ...
Power Apps
Unanswered

Click to add items to the shopping cart (varNumber)

(0) ShareShare
ReportReport
Posted on by 438

When I click to add items to the shopping cart, the issue arises where clicking on one item's quantity updates all items to the same number. How to get avoid to the same number in all items. 

 

Screenshot 2023-11-12 at 3.57.59 PM.pngScreenshot 2023-11-12 at 3.58.07 PM.png

Categories:
I have the same question (0)
  • SpongYe Profile Picture
    5,603 Super User 2025 Season 2 on at

    Hi @dylandavis09 

     

    I would suggest to create different variables for these categories.

     

    Instead of using varNumber for all three: 

    varNumberInStock
    
    varNumberRemainingLefts
    
    varNumberOutOfStocks

     

    If you have any questions or feedback, please let me know. Have a great day! 😊

    -----------------------
    PowerYsa Power Platform Enthusiast [LinkedIn] | [Youtube]

    I love to share my knowledge and learn from others. If you find my posts helpful, please give them a thumbs up 👍 or mark them as a solution ✔️. You can also check out my [@PowerYSA] for some cool solutions and insights. Feel free to connect with me on any of the platforms above. Cheers! 🍻

  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @dylandavis09😊

     

    As I mentioned in your previous topic, a variable will unfortunately not work when working with a gallery / an array of data. The variable is global and will not be specific to one item - you will need to keep track of the quantity for each item individually. You could create a collection from your gallery data (Items property) and add a column to keep track of the selected quantity.

     

    (1) OnVisible of that screen

    //Should you already use a collection for the gallery - make sure to just add the AddColumns as below (don't create a new collection)
    
    //Add a quantity column to keep track of the added numbers for each item
    ClearCollect(
     colShoppingCart,
     AddColumns(
     <Items property of gallery>,
     "Quantity",
     0
     )
    )

     

    (2) Set your gallery Items property to the new collection

    colShoppingCart

     

    (3) OnSelect of the Up arrow

    Patch(
     colShoppingCart,
     ThisItem,
     // -1 for the down arrow
     {Quantity: ThisItem.Quantity + 1}
    )

     

    (4) DisplayMode of the Down arrow (to avoid quantities below 0)

    If(
     ThisItem.Quantity = 0,
     DisplayMode.Disabled,
     DisplayMode.Edit
    )

     

    If this solves your question, would you be so kind as to accept it as a solution & give it a thumbs up.

    Thanks!

  • EddieE Profile Picture
    4,641 Moderator on at

    @dylandavis09 

    Assuming a collection called colCart is the gallery Items, ie

    ClearCollect(
     colCart,
     { title: "In Stock", amt: 0},
     { title: "Remaining", amt: 0},
     { title: "Out of Stock", amt: 0}
    )

     

    ChevronUp

    Patch(colCart, ThisItem, {amt: ThisItem.amt+1})

     

    ChevronDown code

    If(ThisItem.amt > 0,Patch(colCart, ThisItem, {amt: ThisItem.amt-1}))

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard