cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Seanan
Regular Visitor

Assign each new item in a galley a unique variable

Hi guys, I am attempting to create a shopping cart, however I am trying to make it a little more advanced.

 

n0tOm6nGFc.png

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!

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
RandyHayes
Super User
Super User

@Seanan 

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)

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

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.

View solution in original post

9 REPLIES 9
RandyHayes
Super User
Super User

@Seanan 

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?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Hi Randy, thank you for getting back so quickly. In the Items property for my gallery I am calling a collection: ColProductOrder. 

RandyHayes
Super User
Super User

@Seanan 

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)

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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.

RandyHayes
Super User
Super User

@Seanan 

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?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

msedge_ZjVbIzM7WY.png

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.

Seanan
Regular Visitor

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.

 

msedge_86klUKwT7B.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (2,194)