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.
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}))
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!
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! 🍻
WarrenBelz
146,658
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,999
Most Valuable Professional