Catalog

Provides a full catalogue, with multi-categories and your own custom fields.

Back to Catalog Support

Fibonacci
Fibonacci

How to display category and subcategory of product when we display list of products?

I need it to create a link to product detail. I have to set mydomain/:category/:subcategory/:slug on the right way. For now, I only can set the slug.

Tiipiik
Tiipiik

Hi,

Did you look at the default product_list component view ?

You should try {{ SELF.productPage|app }}/{{ product.slug }} to get the product full slug, with category. Due to Markdown, replace "SELF" by " SELF " without spaces.

Actually I'm not sure it will display subcategories as well. I'll check that, and plan to make a more convenient way of getting products full slug.

Last updated

Fibonacci
Fibonacci

I found the answer. Here's my code:

use Tiipiik\Catalog\Models\Product; function onStart() { $this['products'] = Product::with('categories')->whereHas('categories', function($q) { $q->whereSlug('featured'); })->get(); }

Last updated

Tiipiik
Tiipiik

Yes, that will return a collection of products of the category "featured".

Fibonacci
Fibonacci

Please provide it on the next update of your plugin.

Tiipiik
Tiipiik

To achieve that you can use the filter functionnality of the product_list component. You put the category slug in the filter field and the product list would be filtered only for that category. This is usefull for making product list outside of the dynamic catalog.

Or you can have dynamic product list for each category displayed. Take a look at the default product_list.htm inside the component product_list, you will have an example.

And, I know, I have to make better documentation.

1-6 of 6