Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building 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

  • EddieE Profile Picture
    4,641 Super User 2025 Season 1 on at
    Re: Click to add items to the shopping cart (varNumber)

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

     

  • LaurensM Profile Picture
    12,510 Super User 2025 Season 1 on at
    Re: Click to add items to the shopping cart (varNumber)

    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!

  • SpongYe Profile Picture
    5,580 Super User 2025 Season 1 on at
    Re: Click to add items to the shopping cart (varNumber)

    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! 🍻

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,658 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard