Forum
Product filtering by category
Hello, For the Perch Shop App I have a category set called "Products" and a few categories and sub categories within.
I'd like to display all of the products within a particular category, but I don't think I'm filtering correctly and I've tried a ton of combinations.
Up to now I've been filtering on sku and that works fine:
<?php perch_shop_products([
'filter' => 'sku',
'match' => 'eq',
'value' => $walletSku,
]); ?>
So, (and pls forgive the simplistic question) one of my product categories is 'wallets'' ; how can I display the 3 products within that category?
Thanks very much!!
Add
To your filter
EDITED: sorry, I missed the "Set" products, "Category" wallets
Thanks Robert! I was hoping to get rid of the sku filtering and just filter on category. I've been trying something like this to no result:
Apologies if this is unrelated but perhaps something is off with my categories on the whole...?
I set the URL pattern to:
with links:
but the links aren't pulling in the category and look like
shop//[slug]
When I key the catSlug into the browser url the page appears without issue
Incidentally, this line in product.html displays the category slug just fine when I use
perch_shop_product('my-product');
sorry, I missed something. EDIT on my first response
https://forum.grabaperch.com/forum/12-01-2015-product-filtering-by-category?#reply-27291
:(
Thank you!! Should we give Robert the mark for solution?! :)
The filtering works now. I guess I could use a little assistance with the routes.
I'd like to have a main shop page (/shop) that displays all products organized by category (got that!) When I select a product I want to be taken to /shop/[category]/[slug]
I can't get the template to pick up the category. I'm assuming this set up or similar should work..?
At one point it was pointing to 'products' as the category, but I couldn't get to a lower lever.
UPDATED:
You have to get <perch:category> while inside <perch:categories> ... but I am a bit unsure if this works...
I tried the above and also the following, but they didn't work.
I'm still getting
/shop//[slug]
Could you please post your product.html template
Try:
man, Drew nails it again...
I am guessing <perch:shop> cant be inside <perch:categories>??
Yay, success! Thanks to you both.
It was missing a slash though, so:
I was in two minds - looks like I chose wrong! I was thinking of the
catPath
, which would end in a slash. :)Ah-ha, I think being reminded of that could prove helpful in the future though!!
..also that was a good guess, I feel like the queen of catPath!