crbwi Posted September 25, 2013 Share Posted September 25, 2013 (edited) Hello:-D, I have a question, need to hide the categories that all products are out of stock ( 0 stock), Is it possible to do that automatically? not want to disable the categories because google can not access, I just want to hide. I've found a way to hide products with 0 stock, but not the categories. Thanks :-D Edited September 25, 2013 by crbwi (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted September 25, 2013 Share Posted September 25, 2013 in this case it is necessary to hide categories links, the questions is: where you've got these links? blockcategories ? top horizontal menu? it will not be as easy as it seems, unfortunately Link to comment Share on other sites More sharing options...
crbwi Posted September 25, 2013 Author Share Posted September 25, 2013 in this case it is necessary to hide categories links, the questions is: where you've got these links? blockcategories ? top horizontal menu? it will not be as easy as it seems, unfortunately in my case I need to hide in the blockcategories, my version of prestashop is the 1.4 I hope someone can help Link to comment Share on other sites More sharing options...
vekia Posted September 25, 2013 Share Posted September 25, 2013 ok, here is the solution: open file: /modules/blockcategories/category-tree-branch.tpl paste there this code: {if $node.productsCount > 0} <li {if isset($last) && $last == 'true'}class="last"{/if}> <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> {if $node.children|@count > 0} <ul> {foreach from=$node.children item=child name=categoryTreeBranch} {if isset($smarty.foreach.categoryTreeBranch) && $smarty.foreach.categoryTreeBranch.last} {include file="$branche_tpl_path" node=$child last='true'} {else} {include file="$branche_tpl_path" node=$child last='false'} {/if} {/foreach} </ul> {/if} </li> {/if} and then, 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;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); } 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); } 1 Link to comment Share on other sites More sharing options...
pawlo884 Posted September 26, 2013 Share Posted September 26, 2013 try this http://www.prestashop.com/forums/topic/30873-automatic-hide-empty-categories/?do=findComment&comment=1331113 Link to comment Share on other sites More sharing options...
vekia Posted September 27, 2013 Share Posted September 27, 2013 so we have two working solutions thank you for your url, im convinced that it will be hlepful for other merchants with regards, Milos Link to comment Share on other sites More sharing options...
crbwi Posted September 30, 2013 Author Share Posted September 30, 2013 Hello, thank you very much for your answer :rolleyes: ok, here is the solution: open file: /modules/blockcategories/category-tree-branch.tpl paste there this code: {if $node.productsCount > 0} <li {if isset($last) && $last == 'true'}class="last"{/if}> <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> {if $node.children|@count > 0} <ul> {foreach from=$node.children item=child name=categoryTreeBranch} {if isset($smarty.foreach.categoryTreeBranch) && $smarty.foreach.categoryTreeBranch.last} {include file="$branche_tpl_path" node=$child last='true'} {else} {include file="$branche_tpl_path" node=$child last='false'} {/if} {/foreach} </ul> {/if} </li> {/if} and then, 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;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); } 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); } In this method duplicates the categories . And not hide empty categories, O_O why that may be?, Ahh, the counter does not appear. try this http://www.prestashop.com/forums/topic/30873-automatic-hide-empty-categories/?do=findComment&comment=1331113 And in this way I get the counter products but not display the subcategories. Attached are my two unchanged files so you can see them.Greetings and many thanks for helping :) blockcategories.zip Link to comment Share on other sites More sharing options...
pawlo884 Posted September 30, 2013 Share Posted September 30, 2013 (edited) try this http://www.prestasho...s/#entry1331113 And in this way I get the counter products but not display the subcategories. Solution is easy. You must go to the back office, when you create new product or editing existing one check in category tree all categories and subcategories where this product belong. Like this: Category 1 --Subcategory 1 ----Product 1 ----Product 2 --Subcategory 2 Category 2 Category 3 In this case PRODUCT 1 belongs to Subcategory 1 and Category 1 and you must check both in category tree. Edited September 30, 2013 by pawlo884 (see edit history) Link to comment Share on other sites More sharing options...
crbwi Posted September 30, 2013 Author Share Posted September 30, 2013 Solution is easy. You must go to the back office, when you create new product or editing existing one check in category tree all categories and subcategories where this product belong. Like this: Category 1 --Subcategory 1 ----Product 1 ----Product 2 --Subcategory 2 Category 2 Category 3 In this case PRODUCT 1 belongs to Subcategory 1 and Category 1 and you must check both in category tree. What? I do not understand. What this does is show the products in all categories. not? Link to comment Share on other sites More sharing options...
pawlo884 Posted September 30, 2013 Share Posted September 30, 2013 (edited) You change the code and now empty categories and subcategories are hide automatically. You must assiociate some products to categories. Like this: Edited September 30, 2013 by pawlo884 (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now