shaamt Posted September 25, 2013 Share Posted September 25, 2013 Hello,May i know how to display total product numbers at the end of each category name?For example :Product1 (4)Product2 (9)Product3 (12)The number in the bracket is the total number of product for that particular category.I'm using the latest version of Prestashop which is 1.5.5.0. I've tried searching for the answer in this forum but most of it are related to the older version of prestashop.I'm hoping that someone has solved this problem and has a good heart in sharing the success.Best regardsShaamt. Link to comment Share on other sites More sharing options...
shaamt Posted October 1, 2013 Author Share Posted October 1, 2013 Wow! It seem that no even one member on this forum knows how to solve the problem. Link to comment Share on other sites More sharing options...
vekia Posted October 1, 2013 Share Posted October 1, 2013 hope that you're talking about blockcategories module. open: /modules/blockcategories/blockcategories.php instead of this: public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0) { global $link; $children = array(); if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $currentDepth < $maxDepth)) foreach ($resultParents[$id_category] as $subcat) $children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1); if (!isset($resultIds[$id_category])) return false; return array('id' => $id_category, 'link' => $link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']), 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'], 'children' => $children); } use: public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0) { global $link; $children = array(); if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $currentDepth < $maxDepth)) foreach ($resultParents[$id_category] as $subcat) $children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1); if (!isset($resultIds[$id_category])) return false; $productsCount = (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'category_product WHERE id_category = '. $id_category); return array('id' => $id_category, 'link' => $link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']), 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'], 'children' => $children, 'productsCount'=>$productsCount); } then in: /modules/blockcategories/category-tree-branch.tpl instead of: <a href="{$node.link}" {if isset($currentCategoryId) && ($node.id == $currentCategoryId)}class="selected"{/if} title="{$node.desc|escape:html:'UTF-8'}">{$node.name|escape:html:'UTF-8'}</a> use: <a href="{$node.link}" {if isset($currentCategoryId) && ($node.id == $currentCategoryId)}class="selected"{/if} title="{$node.desc|escape:html:'UTF-8'}">{$node.name|escape:html:'UTF-8'} ({$node.productsCount})</a> 1 Link to comment Share on other sites More sharing options...
shaamt Posted October 2, 2013 Author Share Posted October 2, 2013 (edited) Thanks for your reply. I've tried it before but but failed because the Categories Block are not showing any product categories. It seem that the replaceable code is not the same as mine. The code that you gave me for blockcategories.php is: public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0) { global $link; $children = array(); if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $currentDepth < $maxDepth)) foreach ($resultParents[$id_category] as $subcat) $children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1); if (!isset($resultIds[$id_category])) return false;z return array('id' => $id_category, 'link' => $link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']), 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'], 'children' => $children); } but mine (Prestashop 1.5.5.0) is: public function getTree($resultParents, $resultIds, $maxDepth, $id_category = null, $currentDepth = 0) { if (is_null($id_category)) $id_category = $this->context->shop->getCategory(); $children = array(); if (isset($resultParents[$id_category]) && count($resultParents[$id_category]) && ($maxDepth == 0 || $currentDepth < $maxDepth)) foreach ($resultParents[$id_category] as $subcat) $children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1); if (!isset($resultIds[$id_category])) return false; $return = array('id' => $id_category, 'link' => $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']), 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'], 'children' => $children); return $return; } In category-tree-branch.tpl your code is: <a href="{$node.link}" {if isset($currentCategoryId) && ($node.id == $currentCategoryId)}class="selected"{/if} title="{$node.desc|escape:html:'UTF-8'}">{$node.name|escape:html:'UTF-8'}</a> but mine (Prestashop 1.5.5.0) are <a href="{$node.link|escape:'htmlall':'UTF-8'}" {if isset($currentCategoryId) && $node.id == $currentCategoryId}class="selected"{/if}title="{$node.desc|strip_tags|trim|escape:'htmlall':'UTF-8'}">{$node.name|escape:'htmlall':'UTF-8'}</a> Are you able to synchronized the modified code with the code as in prestashop 1.5.5.0? Anyway thanks for your help. Edited October 2, 2013 by shaamt (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted October 2, 2013 Share Posted October 2, 2013 it is for prestashop 1.5.5.0 just use code that i suggested, have you tried it? replace getTree function with mine, and also .tpl file code with mine Link to comment Share on other sites More sharing options...
shaamt Posted October 2, 2013 Author Share Posted October 2, 2013 it is for prestashop 1.5.5.0 just use code that i suggested, have you tried it? replace getTree function with mine, and also .tpl file code with mine Yes. I've tried it and it display a blank categories name as shown here. instead of Link to comment Share on other sites More sharing options...
vekia Posted October 2, 2013 Share Posted October 2, 2013 hello i prepared own module for this, take a look: 1 Link to comment Share on other sites More sharing options...
shaamt Posted October 2, 2013 Author Share Posted October 2, 2013 hello i prepared own module for this, take a look: I've tried your module and it looks really great. But the module include the "disabled" products in the calculation. Could you modify the module a bit by only calculating the "enabled" product. Thanks for your help. Link to comment Share on other sites More sharing options...
vekia Posted October 2, 2013 Share Posted October 2, 2013 I've tried your module and it looks really great. But the module include the "disabled" products in the calculation. Could you modify the module a bit by only calculating the "enabled" product. Thanks for your help. hello ohh you've got aboslutely right, sorry for this it will be available to download ASAP. i will let you know! Link to comment Share on other sites More sharing options...
vekia Posted October 3, 2013 Share Posted October 3, 2013 done. modification ready here is the link: blockcategories with products counter 1 Link to comment Share on other sites More sharing options...
shaamt Posted October 3, 2013 Author Share Posted October 3, 2013 done. modification ready It is currently installed and running great. Thanks for the module. You are the best! Link to comment Share on other sites More sharing options...
vekia Posted October 3, 2013 Share Posted October 3, 2013 thank you for your kind words im glad that i could help you im going to mark this topic as solved with regards, Milos 1 Link to comment Share on other sites More sharing options...
pulse1981 Posted January 24, 2014 Share Posted January 24, 2014 Hi, i've looking for something like this. In my web, i'll have a few products, 10 items, and id like to modify blockcategories to show instead the counting items, a list of category items. Is possible with this module? Thank you in advance Link to comment Share on other sites More sharing options...
vekia Posted January 26, 2014 Share Posted January 26, 2014 so just empty category-count.tpl file and you will remove the counter. Link to comment Share on other sites More sharing options...
abdul malik Posted January 27, 2015 Share Posted January 27, 2015 can i use this add-on for prestashop 1.6? Link to comment Share on other sites More sharing options...
SLiCK_303 Posted February 1, 2015 Share Posted February 1, 2015 I'm running 1.6.0.12, and made the edits by hand. For the most part it works, but it would be nice if there where either no numbers by main cats, or better yet show a total of all the sub-cats. 1 Link to comment Share on other sites More sharing options...
lateral Posted February 14, 2015 Share Posted February 14, 2015 Hi guys I agree with Click_303, this Vekia's modules works 95% except that if the parent category does not have any products and the sub-categories do have products, the sub-categories are displaying the total number of products correctly but the parent category display "0". Vekia, can you please change the code so that if the number of products count is "0" then do not display anything???? This fix will make the module work correctly and more people will be in a position to use it! Thanks Regards Greg Link to comment Share on other sites More sharing options...
StefArts Posted November 21, 2016 Share Posted November 21, 2016 Hello, Is it possible to have this module for prestashop 1.6? Thank you. Regards Link to comment Share on other sites More sharing options...
Recommended Posts