cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frankie70
Post Patron
Post Patron

Design shopping cart and manage items

Hi all,

I am building a webshop and I would like to be able to change the quantity of products or remove them from my gallery.

Frankie70_0-1615994026302.png

I can think of two options:

  1. use a dropdown (when choosing '0' is deleting the product from the list
  2. using buttons (up and down arrow) to modify the quantity or put it to '0' for deletion

Currently the dropdown is configured like this:

 

Sequence(ThisItem.Amount+3,0,1)

 

In my gallery the items ar grouped

 

AddColumns(
    GroupBy(
        basket,
        "itemname",
        "itemopt",
        "itemprice",
        "itemname_rec"
    ),
/*      "Total", Sum(itemname_rec, itemprice), */
    "Amount",
    Sum(
        itemname_rec,
        itemcount
    )
    
)

 

I am really stuck here and any help is appreciated!

40 REPLIES 40
RandyHayes
Super User
Super User

@Frankie70 

Very good.  So then the concept is this, on your Add to Cart, check your collection to see if the item is already in the cart.  If so, increment the count.  If not, add it and set the count to 1.

This will totally eliminate the need to group by anything as it will then automatically be grouped.

 

 

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

@RandyHayes 

Thanks a lot.

I was hoping you could help me with some formula because I am not really sure how to start. This would be awesome.

RandyHayes
Super User
Super User

@Frankie70 

Sounds good...put this concept in play and see how you get along with it. 

_____________________________________________________________________________________
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 @RandyHayes 

Somehow I can not get it to work.

I check if an item already exists in the collection and if so, i want to increment the current amount with the value selected from the dropdown (dd_amount). But it seems that referencing to the same property does not work.

 

 

If(CountRows(Filter(basket, itemname = Gallery4.Selected.Title))<0, 

Collect(basket, {itemname: Gallery4.Selected.Title, itemcat: Gallery4.Selected.Category, itemprice: Gallery4.Selected.Price, itemopt: dd_options_5.Selected.Result, itemid:Gallery4.Selected.ID, itemcount: dd_amount.Selected.Value}), 

Patch(basket, First(Filter(basket, itemname=Gallery4.Selected.Title)), {itemcount: ...??

 

 

Could you please give me a hint?

Hi @RandyHayes ,

I am really stuck on this. Could you please have a quick look?

The "Add to cart" button has the following formula:

OnSelect:

 

Collect(basket, {itemname: Gallery4.Selected.Title, itemcat: Gallery4.Selected.Category, itemprice: Gallery4.Selected.Price, itemopt: dd_options_5.Selected.Result, itemid:Gallery4.Selected.ID, itemcount: dd_amount.Selected.Value})

 

In the gallery below I would like to add and remove items.

Frankie70_0-1616489147766.png

I cannot get this to work.

RandyHayes
Super User
Super User

@Frankie70 

Sorry for delay...

 

Set your formula to:

With({_itm: LookUp(basket, itemname = Gallery4.Selected.Title)},
    If(!IsBlank(_itm.itemcount), 
        UpdateIf(basket, itemname=_itm.itemname,
           {itemcount: _itm.itemcount + Value(dd_amount.Selected.Value)}
        ),
        Collect(basket, 
           {itemname: Gallery4.Selected.Title, 
            itemcat: Gallery4.Selected.Category, 
            itemprice: Gallery4.Selected.Price, 
            itemopt: dd_options_5.Selected.Result, 
            itemid:Gallery4.Selected.ID, 
            itemcount: Value(dd_amount.Selected.Value)
           }
        )
    )
)

This looks up the item in the basket collection first.

If there is an itemcount then there is a record...so updateIf is used to increment the count.

If there is not, then the item is collected.

 

_____________________________________________________________________________________
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!
Frankie70
Post Patron
Post Patron

Hi @RandyHayes ,

that worked really great. But my initial problem is how I can increment and reduce the itemcount in the basket.

Somehow I do not have access to "ThisItem.itemcount" in the gallery.

Frankie70_0-1616521550297.png

 

RandyHayes
Super User
Super User

@Frankie70 

What is the Items property of that Gallery?  I assume it is basket

What is the error you are seeing (when you hover over the error in the formula)?

_____________________________________________________________________________________
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 @RandyHayes ,

yes, its basket.

The itemcount between the two arrows has

Text: ThisItem.itemcount

 

The itemprice on the very right has

Text: Text(ThisItem.itemcount*ThisItem.itemprice, "[$-en-US]###,###.00") & " €"

 

I'm not sure what formula to use for the up and down arrows?

RandyHayes
Super User
Super User

@Frankie70 

Click on this dropdown on the red error:

RandyHayes_1-1616522706004.png

Then choose Edit in the formula bar:

RandyHayes_2-1616522738578.png

Then click into the formula and see what is underlined in red.  Then hover your mouse pointer over that red underline and let me know what the error message is that pops up.

 

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

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,700)