Jump to content

Product count on SubCatergories


Recommended Posts

Well, if I had to do it, I will probably override classes/Category.php. I would add a subcategory count directly in function getSubCategories();

 

On line 483, after $row['legend'] = 'no picture';

I would add the following

$categ = new Category((int)$row['id_category'], (int)$id_lang);

$row['nbproducts'] =$categ->getProducts(NULL, NULL, NULL,  NULL,  NULL, true);

I didn't test it

Link to comment
Share on other sites

Well, if I had to do it, I will probably override classes/Category.php. I would add a subcategory count directly in function getSubCategories();

 

On line 483, after $row['legend'] = 'no picture';

I would add the following

$categ = new Category((int)$row['id_category'], (int)$id_lang);

$row['nbproducts'] =$categ->getProducts(NULL, NULL, NULL,  NULL,  NULL, true);

I didn't test it

 

Hi, Thanks for your response.

 

I am running PS v1.3.2.3 and my code is as follows in classes/catergory.php:

 

 /* Modify SQL result */
 foreach ($result AS &$row)
 {
  $row['name'] = Category::hideCategoryPosition($row['name']);
  $row['id_image'] = (file_exists(_PS_CAT_IMG_DIR_.$row['id_category'].'.jpg')) ? intval($row['id_category']) : Language::getIsoById($cookie->id_lang).'-default';
  $row['legend'] = 'no picture';
 }
 return $result;
}
private static function getAllSubCats(&$all_cats, $id_cat, $id_lang)
{
 $category = new Category(intval($id_cat));
 $sub_cats = $category->getSubcategories($id_lang);
 if(count($sub_cats) > 0)
  foreach ($sub_cats AS $sub_cat)
  {
$all_cats[] = $sub_cat['id_category'];
self::getAllSubCats($all_cats, $sub_cat['id_category'], $id_lang);
  }
}

 

Where would i insert your code and how do i call it in catergory.tpl?

 

Cheers

Link to comment
Share on other sites

Great! Your code works fine, just one request / question.

 

I have catergories set up like this:

 

Home > Bulbs (0) > Single End (0) > BLV (10)

 

Home > Bulbs (0) > Double End (0) > BLV (5)

 

On the bulbs cat it shows 0 products as they are within child subcats, is it possible to show like this:

 

Home > Bulbs (15) > Single End (10) > BLV (10)

 

Home > Bulbs (15) > Double End (5) > BLV (5)

 

Thanks for your help!

Link to comment
Share on other sites

  • 4 weeks 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...