Jump to content

How to display product count on subcategory (product list)


Santori

Recommended Posts

Hello, i require some help of the community. Prestashop 1.6

We have dome a modification in Classes/Category.php for show a counter of products by subcategories. to show them so in category.tpl:

 

Category: A There are 100 products

Subcategory a -

Subcategory b- 30 products

Subcategory b- 20 products

This is the code into Classes/Category.php

In foreach ($result as &$row) {
            $row['id_image'] = Tools::file_exists_cache(_PS_CAT_IMG_DIR_.$row['id_category'].'.jpg') ? (int)$row['id_category'] : Language::getIsoById($id_lang).'-default';
            $row['legend'] = 'no picture';
            $categ = new Category((int)$row['id_category'], (int)$id_lang);
            $row['nbproducts'] =$categ->getProducts(1, 1, 10000,  NULL,  NULL, true);
            
        }

 

 And the code into category.tpl

 {if $subcategory.nbproducts >0 }
                    <span>({$subcategory.nbproducts}) {l s='Prods.'}</span>
                    {else} -   
                    {/if} 

 

The Subcategory a have 2 subcategories with 25 and 25 products but because the parent category have no products associated is empty.

We need the code count the products in this subcategory or summatory of the categories under.

Can someone help tp fix it)?

Link to comment
Share on other sites

  • 4 weeks later...
  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...