Home » Php » php – Magento: Display products from childcategories if parent category is empty

php – Magento: Display products from childcategories if parent category is empty

Posted by: admin July 12, 2020 Leave a comment

Questions:

I have the following categories

Car parts (0)
Tires (0)
Rims (5)

Now in the product listing obviously the car parts en tires listing returns 0 products. But for the user this is ankward. Is it possible to show child items if a category is empty?

Kind regards

How to&Answers:

Have you marked the category as an anchor category in the administrative interface? That should allow child categories’ products to show up in the parent category listing.

Hope that helps.

Thanks,
Joe

Answer:

I’ve been looking for hours for an answer to this myself, and finally found the solution.

As many sites and questions give the solution “set the parent category to ‘is anchor=yes’ or ‘try re-indexing your products’, you might find that neither of these work. However, you need to combine these:

1. First, set the categories of which you want to show its sub-categories’ products, to ‘is anchor -> Yes’. (Catalog > Manage categories’ in admin)
You will now see that this category has the number of products all the sub-categories together contain.

2. To show this on your website, you have to reindex the data now. In admin, go to System > Index Management and tick the ‘Category products’ checkbox. Hit ‘send’ and it’ll reindex.

Voilà, your products show where you want them to show. One downside is that the page will now also show ‘layered navigation’, but if you don’t want this you can simply set the div that contains this to display:none in CSS.

We owe it all to this site where I found it:
http://sheldonrcohen.com/Blog/tabid/88/EntryId/12/Magento-parent-category-not-showing-sub-category-products.aspx

Thanks Sheldon Cohen! 🙂