Hi guys, I am attempting to create a shopping cart, however I am trying to make it a little more advanced.
This is an image of the shopping cart screen. Currently when I add a new item to the shopping list my + and - buttons are altering all of the items quantities within the shopping cart because the variable is the same. I was wondering if it would be possible to make it so that every time a new item is added to the gallery it assigns the variable to a unique variable. The example:
UpdateContext({quantity:TextInput4 +1})
This is the code inside of the + and - button (With the subtract being -1 instead of +1), then I call that variable into the textbox. Is it possible to create a loop or something similar that says for each item in the gallery assign the quantity variable to quantity1, quantity2 etc.
I realise that it would be easier to just remove the + and - buttons and just allow the user to enter the value but I would like to explore this option if it is possible.
Thanks in advance guys!
Solved! Go to Solution.
So then when you create that collection, add a new column to it called Qty - default of 0
Then, your label (I believe that is a label you have in the picture) in the Gallery should have a text property of : ThisItem.Qty
Your Plus icon OnSelect : Update(ColProductOrder, ThisItem, {Qty: ThisItem.Qty + 1})
And your minus icon: Update(ColProductOrder, ThisItem, {Qty: ThisItem.Qty - 1})
As a bonus, you might set your minus Icon display mode property to:
If(ThisItem.Qty<1, Disabled, Edit)
I may be doing something wrong but I seem to be running into an error that says: "The Qty column inside of your data source expects a record column and not a number".
The code to create my collection is:
Collect(ColProductOrder,{Name:ThisItem.Title,Price:ThisItem.Price,Brand:ThisItem.Brand,Colour:ThisItem.Colour,Size:ThisItem.Size,Qty:ThisItem})
The code in the +/- button is:
Update(ColProductOrder, ThisItem, {Qty:ThisItem.Qty + 1})
The collection is used to pull specific columns of data from my SharePoint List.
You will need to skip the variable in this scenario and have an additional column in your gallery Items table.
What is your current Items property for the gallery?
Hi Randy, thank you for getting back so quickly. In the Items property for my gallery I am calling a collection: ColProductOrder.
So then when you create that collection, add a new column to it called Qty - default of 0
Then, your label (I believe that is a label you have in the picture) in the Gallery should have a text property of : ThisItem.Qty
Your Plus icon OnSelect : Update(ColProductOrder, ThisItem, {Qty: ThisItem.Qty + 1})
And your minus icon: Update(ColProductOrder, ThisItem, {Qty: ThisItem.Qty - 1})
As a bonus, you might set your minus Icon display mode property to:
If(ThisItem.Qty<1, Disabled, Edit)
I may be doing something wrong but I seem to be running into an error that says: "The Qty column inside of your data source expects a record column and not a number".
The code to create my collection is:
Collect(ColProductOrder,{Name:ThisItem.Title,Price:ThisItem.Price,Brand:ThisItem.Brand,Colour:ThisItem.Colour,Size:ThisItem.Size,Qty:ThisItem})
The code in the +/- button is:
Update(ColProductOrder, ThisItem, {Qty:ThisItem.Qty + 1})
The collection is used to pull specific columns of data from my SharePoint List.
In that first formula, you are assigning the full record to a numeric column.
That formula is not clear as you are referring to ThisItem in all of the columns to add a record to a collection. But wouldn't the row you are on in the gallery already have that row in it? Why are you creating a new row in the collection there?
This is my shopping page (Apologies for no images to make it look nicer). Basically When I select an Image you get a popup (Using updatecontext) to make a button appear and some information that allows you to add that item to the cart. So in order to take the selected item and add it to the cart I created a new collection that will then pull only certain columns that I need to display on my cart screen. I apologise if my code is not the greatest or a little confusing as I am still trying to get to grips with using PowerApps.
Hi @Seanan ,
The logic from @RandyHayes is all good. I'm here to help incase he is too busy to get back to this thread in time.
I assume the default quantity of items added to the shopping cart will always be set to 1, then the collection creating formula should be as follows:
Collect(ColProductOrder,{Name:ThisItem.Title,Price:ThisItem.Price,Brand:ThisItem.Brand,Colour:ThisItem.Colour,Size:ThisItem.Size,Qty: 1})
The Qty column should include the default value you want in the shopping cart. Other formulas will exactly like in @RandyHayes 's reply.
Hope this helps.
Best regards,
Community Support Team _ Jeffer Ni
If this post helps, then please consider Accept it as the solution to help the other members find it.
Community Support Team _ Jeffer Ni
If this post helps, then please consider Accept it as the solution to help the other members find it.
Hi @v-jefferni,
I apologise for not getting back to you sooner as I have been away.
You solution worked almost perfect and the plus and minus buttons are now working independently. However, it seems that when I click on the plus button it now removed my "title" and "brand" labels. An example is below.
The code I have in my title is
ThisItem.Name & " " & ThisItem.Colour.Value
And for the Brand it is:
ThisItem.Brand.Value
Is there any obvious mistake I have made? I copied in the collection creating formula you suggested and also used the formula Randy mentioned for the +/- buttons.
I have managed to fix the issue now. I realised I needed to call all of the variables into the Update() formula and that seemed to fix it.
Thank you once again for your help guys.
User | Count |
---|---|
122 | |
87 | |
86 | |
75 | |
67 |
User | Count |
---|---|
214 | |
181 | |
137 | |
96 | |
83 |