Forum

Thread tagged as: Question, Shop

Add to cart - added

Hi How would I change my add button in my product list template to added when clicked on? I know it should be something like.. if product exists in cart show 'added' button, else show 'add' button but I can't quite figure it out which tags I must use to identify whether or not something is in the cart.
I was thinking it may be along the lines of if 'product_count' (tag) is ' => 1' show 'added' but i'm not sure where to put that.

William Chicken

William Chicken 1 points

  • 5 years ago

Found it. Of course the same code I was looking for is used in the cart itself.

<perch:if id="product_count" match="gt" value="0">

Can't make it work though..

Drew McLellan

Drew McLellan 2638 points
Perch Support

That will work in cart templates, but not for the form itself. I can't think of a way to do it without inspecting the contents of the cart first.

Of course ' product count ' would be all products, not just individual items. So even if it did work, all my add buttons would become added.

Hi Did you think of a solution for this after? My client is worried that if the product doesn't show added, change colour or disappear even, her customers may get confused as to which products have been added already. The product is mainly greetings cards sold to the trade so her clients will probably browse back and forth whilst choosing from many different designs.
I currently have it to count on the page without taking them away from the page and they can narrow down the selection via categories or search but some of the cards cross into other categories eg. birthdays and welsh.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can get the contents of the cart - so you have a means to do this if you need to.

Sorry if I'm being a pain. You couldn't give me a little pointer? I can't seem to find the right function.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can use perch_shop_cart(['skip-template'=>true]) to get the cart contents.

Where would I use this?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You'd use it on your product page to test to see what's in the cart and therefore what state your button should have.

If that's not something you're able to do yourself it might be a good idea to bring in someone to help. We're not in a position to help with the detail of how you build your site.

Ok, I'll look into it. Sure I can figure it out. I know most things are relatively simple with perch and so I don't want to go about recreating the wheel if I don't have to. There are a few concepts I don't quite get but it is starting to make sense. Cheers!