frances Posted October 12, 2009 Share Posted October 12, 2009 Does anybody knows how can I easy automatic empty hide categories? Thank you for responses. 1 Link to comment Share on other sites More sharing options...
PrestaNewbie75 Posted October 13, 2009 Share Posted October 13, 2009 *bump*Due to the lack of filtered/guided navigation we're having to create lots of categories and subcategories - having a category hide itself when empty would massively ease maintenance. Link to comment Share on other sites More sharing options...
rocky Posted October 13, 2009 Share Posted October 13, 2009 Good idea. I'll add it to the Categories block v2.0 module I'm working on. I've already added the option to put the number of products in brackets after the names, so it should be easy. I just need to know what should happen when a category is empty, but it contains subcategories that are not empty. Should I hide the category, causing subcategories with products to also be hidden, or should I display these empty categories and only hide the ones where all subcategories are also empty? Link to comment Share on other sites More sharing options...
kju Posted October 14, 2009 Share Posted October 14, 2009 I'd say that the best would be if the admin could make that choice but if its not possible or to much work then show empty categories with non-empty subcategories.Another thing if you have the time is the option to hide all main categories and their subcategories if they are not selected. (only showing sub-categories of the selected main category). Link to comment Share on other sites More sharing options...
rocky Posted October 14, 2009 Share Posted October 14, 2009 Thanks kju. I'll see what I can do. Link to comment Share on other sites More sharing options...
zomigi Posted October 20, 2009 Share Posted October 20, 2009 I really need this feature too, and am really looking forward to this updated module. Thanks for working on it! Link to comment Share on other sites More sharing options...
shaiss Posted February 26, 2010 Share Posted February 26, 2010 I need this option too as we have categories that we currently dont have stop for, and others the are high turn over. No sense in showing a customer a category with no items in it or its subcategories. Link to comment Share on other sites More sharing options...
rocky Posted February 27, 2010 Share Posted February 27, 2010 Since my previous post in this topic, I've released my category module here. It has the option to hide empty categories. Link to comment Share on other sites More sharing options...
ruppon Posted March 1, 2011 Share Posted March 1, 2011 Does anybody knows how can I easy automatic empty hide categories? Thank you for responses. You can achieve this executing the following single query:UPDATE ps_category AS c SET c.active=0 WHERE c.id_category IN ( SELECT tmp.id_category FROM ( SELECT id_category FROM ps_category ) AS tmp WHERE tmp.id_category NOT IN ( SELECT cp.id_category FROM ps_category_product AS cp GROUP BY cp.id_category ) ) where "ps_" is your table prefix. 2 Link to comment Share on other sites More sharing options...
ruppon Posted March 2, 2011 Share Posted March 2, 2011 What happens tomorrow morning, when Susie restocks a product assigned to a currently empty category?She just needs to do 1 click on the inactive category's activating icon ("X"), simple as that how aboutSELECT DISTINCTplus, isn't the GROUP BY superfluous here? Yes, you are right, good note! You can execute that query as SELECT DISTINCT, not GROUP BY as it returns only 1 column. Also, if we just look to the category_product table, we're blind to the possibility that all products in a given category are either out-of-stock or have been flagged as inactive products.You can't find in category_product table a category that has no products. That's the point Link to comment Share on other sites More sharing options...
Rohit Singhal Posted February 9, 2013 Share Posted February 9, 2013 Check out my module to hide empty categories in the sidebar and footer Non-empty Categories Module v1.0 1 Link to comment Share on other sites More sharing options...
ValeriySh Posted August 7, 2013 Share Posted August 7, 2013 There is a bit easier method that could be also used to show how many items are in the category. I have found most information for the steps 1 & 2 here on the forum: http://www.prestasho...post__p__771194 Step 1 - get product count File: /modules/blockcategories.php Find: getTree After the code if (!isset($resultIds[$id_category])) return false; add following $ProductsCount = 0; $ProductsCount = (int)Db::getInstance()->getValue('SELECT COUNT(cp.id_category) FROM '._DB_PREFIX_.'category_product cp, '._DB_PREFIX_.'product pr WHERE cp.id_category = '.$id_category .' AND cp.id_product = pr.id_product AND pr.active = 1' ); Before the end of the function (before return $return) find a $return = array(... and modify the end as follows: $return = array(.... 'children' => $children, 'products' => $ProductsCount); Step 2 - show product count File: themes\YOUR_THEME\modules\blockcategories\category-tree-branch.tpl Optionally, you can show how many items are in the category. Find first A after the first LI and before the /A closing tag add the following: ({$node.products}) You may use usual space instead of non-breaking one. Step 3 - hide empty categories In the same file, just before the code begins (before the very first LI) add following: {if $node.products > 0} and at the end add this {/if} Find the next line {if $node.children|@count > 0} and add a condition into it && $node.products > 0 Entire code will look like that: {if $node.products > 0} <li {if isset($last) && $last == 'true'}class="last"{/if}> <a href="{$node.link|escape:'htmlall':'UTF-8'}" {if isset($currentCategoryId) && $node.id == $currentCategoryId}class="selected"{/if} title="{$node.desc|escape:'htmlall':'UTF-8'}">{$node.name|escape:'htmlall':'UTF-8'} ({$node.products})</a> {if $node.children|@count > 0 && $node.products > 0} <ul> {foreach from=$node.children item=child name=categoryTreeBranch} {if $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} Recompile/clear your cache and now your CATEGORIES should look like that: 4 Link to comment Share on other sites More sharing options...
tdc666 Posted January 6, 2014 Share Posted January 6, 2014 i'm looking for a way to hide empty categories, the above seems to work for me when there are no subcats, but for what ever reason not when there are. most of my cats have one, sometimes two, subcats; when i add the product number to the cat tree using the above method it shows (0) on my parent cats even when there are many products in a subcat. it works fine when there are products in a cat with no subcats, so i'm not totally goofing it up. anyone have any ideas? Link to comment Share on other sites More sharing options...
ventesites Posted November 13, 2014 Share Posted November 13, 2014 i am having the same problem with prestashop 1.6.9, it is just impossible to hide empties sub-categories which really doesn't make ANY sense, who would like to display nothing for sale? anybody knows how to hide those empties sub-cat? thanks Link to comment Share on other sites More sharing options...
Programmers Direct Posted November 13, 2014 Share Posted November 13, 2014 There are many ways to do this one using database and looping. Link to comment Share on other sites More sharing options...
ventesites Posted November 13, 2014 Share Posted November 13, 2014 do you have one working example? Link to comment Share on other sites More sharing options...
Programmers Direct Posted November 13, 2014 Share Posted November 13, 2014 Not off hand, but one could Get all category id's Now go through one by one see if a product is associated with it see if it has sub categories and do they have products If both are there skip action else disable it This is a simple layout of what you could do. I have a module that is coming out soon for this exact thing as I needed it because the maintaining of categories is very time consuming at times. Link to comment Share on other sites More sharing options...
Programmers Direct Posted November 25, 2014 Share Posted November 25, 2014 I have a module for this but trying to set a price and see if it will even be wanted. I was thinking 50 nut you decide and tell me if it's worth adding it to addons site. Link to comment Share on other sites More sharing options...
santi00 Posted November 27, 2014 Share Posted November 27, 2014 (edited) I have the same problem. I need to hide empty categories and subcategories. Do you have a module to make this? I use prestashop 1.6 Tank you. Edited November 27, 2014 by santi00 (see edit history) Link to comment Share on other sites More sharing options...
mickeyboy1 Posted November 27, 2014 Share Posted November 27, 2014 I might be missing something here but why not just disable the categories or sub- categories in back office until you have products to fill them then just click enable. Link to comment Share on other sites More sharing options...
ventesites Posted November 27, 2014 Share Posted November 27, 2014 yep but problem is : they show back..... in my case i can disable as much i want but as long as there is something inside even if this is only 1 disabled product, they end up as availables and show up in the store. I have a bunch of categories i want to be disabled, they contain disabled products that i do not want to delete because they will be back in stock at some point.... Link to comment Share on other sites More sharing options...
santi00 Posted November 28, 2014 Share Posted November 28, 2014 Any news for this module? I need this work!!! Tank you. Link to comment Share on other sites More sharing options...
Programmers Direct Posted November 28, 2014 Share Posted November 28, 2014 I will add it to addons prestashop today after the last leg of testing. Link to comment Share on other sites More sharing options...
Programmers Direct Posted December 1, 2014 Share Posted December 1, 2014 (edited) I added it to addons site on friday or saturday so it should be released soon. it even cleans top horz menu if enabled too after maintenancing the categories. Edited December 1, 2014 by ShopSaveNEarn (see edit history) Link to comment Share on other sites More sharing options...
Krzewka Posted December 3, 2014 Share Posted December 3, 2014 (edited) Please write here when your module will be ready to download and use. I hope it will work also with PS 1.5Regards! Edited December 3, 2014 by Krzewka (see edit history) Link to comment Share on other sites More sharing options...
Programmers Direct Posted December 3, 2014 Share Posted December 3, 2014 It sure does, and I am just waiting on approval as there were some issues that were my fault because I was trying to add other languages, but 2 was incorrect becasue of auto translation. I am sure it will be any time now. 1 Link to comment Share on other sites More sharing options...
Programmers Direct Posted December 5, 2014 Share Posted December 5, 2014 (edited) Category maintenance module was approved and the link is below http://addons.prestashop.com/en/administration-tools-prestashop-modules/18334-auto-category-maintenance.html Edited December 5, 2014 by ShopSaveNEarn (see edit history) 1 Link to comment Share on other sites More sharing options...
Programmers Direct Posted December 8, 2014 Share Posted December 8, 2014 Please, let me know if you are still interested in this module. Working on some New ones too if you got any idea's. Thanks William Link to comment Share on other sites More sharing options...
Konrad90 Posted February 20, 2015 Share Posted February 20, 2015 (edited) Edit: removed Edited February 20, 2015 by Konrad90 (see edit history) Link to comment Share on other sites More sharing options...
Devendra Posted February 21, 2015 Share Posted February 21, 2015 Hi, In My case *No products in Category *But products available in subcategory *Now main category display "There are no products in category" Please tell me how to remove this message. Because if new customer will come to my site & check main category message then may be he will not visit in sub category. Please suggest me how to remove this message from main category. I am using PS 1.4.8.3 for reference please check www.uthmart.com Thanks in advance. Devendra Link to comment Share on other sites More sharing options...
Programmers Direct Posted February 21, 2015 Share Posted February 21, 2015 (edited) You need to ad a check to se if a category has products in its children and if it does it has to be active and it will go away. Like below if(categorychild check > 0) sqlCayegoryupdate('1'); //activate category else sqlCayegoryupdate('0'); //deactivate category Edited February 21, 2015 by ShopSaveNEarn (see edit history) Link to comment Share on other sites More sharing options...
ventesites Posted February 21, 2015 Share Posted February 21, 2015 In my case i need to hide empties categories + empties sub-categories AND categories and sub-categories containing disabled products will your module do this? Link to comment Share on other sites More sharing options...
Programmers Direct Posted February 21, 2015 Share Posted February 21, 2015 Yes, it's is based on products that are active and and should not activate them if only disabled products are associated. Link to comment Share on other sites More sharing options...
ventesites Posted February 23, 2015 Share Posted February 23, 2015 are they any feedback somewhere from users of your module? i see what you suggested to Devena who obviously bought it, I wouldn't like to buy an add on and out of the box having to start adding queries especially with the little explanation you provide... quote "You need to ad a check to se if a category has products in its children and if it does it has to be active and it will go away. like below..." don't know if Devena was able to fix his problem ... Link to comment Share on other sites More sharing options...
Programmers Direct Posted February 23, 2015 Share Posted February 23, 2015 Actually this has not been purchased yet but it's inspected by prestashop and tested too before they allow it to be sold. Link to comment Share on other sites More sharing options...
Programmers Direct Posted February 23, 2015 Share Posted February 23, 2015 No in my module you have to add nothing. That was without my module and to do it on your own. My module is complete and there is no edits, but if your doing it yourself you need to add checks and such to make it happen and that's what I was explaining to devina and it was nothing to,do with my module. Link to comment Share on other sites More sharing options...
ventesites Posted February 23, 2015 Share Posted February 23, 2015 hope someone buy it and give feedback, i am very cautious about module inspected by Prestashop after the mess I went through with Google analytics add-on.... Link to comment Share on other sites More sharing options...
Programmers Direct Posted February 23, 2015 Share Posted February 23, 2015 Oh wow sorry you had issues with them. I know here soon I am opening my webdesign website and it will have all my modules and custom design or services and I always make sure my modules work great and the customer is satisfied. I even do the edits, but like to customize the modules to the customer. I could do a custom one for you too but rest assured if you buy my module I will ensure it works accordingly to its description and purpose. If there by chance was an issue I would fix it personally and give you a new module with the fixes, but it is rare that I need to do so. Link to comment Share on other sites More sharing options...
Programmers Direct Posted July 20, 2016 Share Posted July 20, 2016 (edited) Great article. But just in case you want an instant fix this module is available on the Prestashop Addons webite - http://addons.prestashop.com/en/18334-auto-category-maintenance.htmlWe are working on making all our modules available on other carts as well so check out the Programmers Direct website. Edited August 23, 2016 by Programmers Direct (see edit history) Link to comment Share on other sites More sharing options...
hootersam Posted August 23, 2016 Share Posted August 23, 2016 (edited) SIMPLE WORKING SOLUTION FOR PRESTASHOP 1.6.x.x Modification adjusted to PS 1.6.x.x (tested on 1.6.1.5) for hiding categories and / or subcategories if there are no products in them. Based on solution from first page, but more elegant - using internal PS category class instead of SQL query. Open file: /modules/blockcategories/blockcategories.php Find getTree function, it should look similar to this: 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])) { $link = $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']); $name = $resultIds[$id_category]['name']; $desc = $resultIds[$id_category]['description']; } else $link = $name = $desc = ''; $return = array( 'id' => $id_category, 'link' => $link, 'name' => $name, 'desc'=> $desc, 'children' => $children ); return $return; } Add new lines from below or just replace whole function with this one: 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])) { $link = $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']); $name = $resultIds[$id_category]['name']; $desc = $resultIds[$id_category]['description']; } else $link = $name = $desc = ''; /* new 2 lines to add below */ $CategoryObj = new Category($id_category,$this->context->language->id,$this->context->shop->id); $ProductsCount = $CategoryObj->getProducts($this->context->language->id,1,1000,null,null,true,true,false,1,false,$this->context); $return = array( 'id' => $id_category, 'link' => $link, 'name' => $name, 'desc'=> $desc, 'products' => $ProductsCount, // new line to add 'children' => $children ); return $return; } Open file (if you are not using default theme your path will be different in place where it says "default-bootstrap") themes/default-bootstrap/modules/blockcategories/category-tree-branch.tpl Replace all contents in this file with this below (there are only added 2 lines - first and last, and one additional condition at line 7) {if $node.products > 0} <li {if isset($last) && $last == 'true'}class="last"{/if}> <a href="{$node.link|escape:'html':'UTF-8'}"{if isset($currentCategoryId) && $node.id == $currentCategoryId} class="selected"{/if} title="{$node.desc|strip_tags|trim|escape:'html':'UTF-8'}"> {$node.name|escape:'html':'UTF-8'} </a> {if $node.children|@count > 0 && $node.products > 0} <ul> {foreach from=$node.children item=child name=categoryTreeBranch} {if $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} Save, refresh, done. Remember when you update block categories module those modifications in your php file will be overwriten. Simply don't update block categories module or reapply solution after each update. Hope this helps someone. Edited August 23, 2016 by hootersam (see edit history) 4 Link to comment Share on other sites More sharing options...
Programmers Direct Posted August 23, 2016 Share Posted August 23, 2016 Great free solution. Good contribution. Thank you. Link to comment Share on other sites More sharing options...
kafeinstudio Posted July 3, 2017 Share Posted July 3, 2017 Thanks @hootersam it's a great solution Remember when you update block categories module those modifications in your php file will be overwriten. Simply don't update block categories module or reapply solution after each update. A little advice here : you could consider overriding the gettree function in order to keep the changes even after updating the module or prestashop.Just create the following file "override/modules/blockcategories/blockcategories.php" : <?php if (!defined('_PS_VERSION_')) exit; class BlockCategoriesOverride extends BlockCategories { /** THE NEW GETTREE FUNCTION GOES GERE **/ } 2 Link to comment Share on other sites More sharing options...
polbulva Posted August 22, 2017 Share Posted August 22, 2017 It works great, I just hide the empty categories in the left column, but it is still in the product column. How do I hide it from here? Link to comment Share on other sites More sharing options...
Programmers Direct Posted August 23, 2017 Share Posted August 23, 2017 Personally, I would just buy the module it cleans the categories all for you and you can set it up to do automatically too. https://addons.prestashop.com/en/administrative-tools/18334-auto-category-maintenance.html Link to comment Share on other sites More sharing options...
Recommended Posts