mmsh Posted November 21, 2012 Share Posted November 21, 2012 (edited) hi, obviously not the main... and not the 2nd level... but the 3rd only. How to hide the empty categories at the 3rd level? thanks Edited November 25, 2012 by mmsh (see edit history) Link to comment Share on other sites More sharing options...
mmsh Posted November 21, 2012 Author Share Posted November 21, 2012 anyone? I'm able to show the number of products for every category <li><a... ...but i don't have clear how to access the last depth <li> to add an (example) {if $products > 0} show {else} nothing.... Link to comment Share on other sites More sharing options...
musicmaster Posted November 22, 2012 Share Posted November 22, 2012 In the ps_category table in the database you have a "level_depth" field. Is that what you are looking for? Link to comment Share on other sites More sharing options...
mmsh Posted November 22, 2012 Author Share Posted November 22, 2012 (edited) thank you...anyway i was able to count products and then do it passing the $currentDepth variable to the tpl file but i have another problem: when i'm at level 2 and all the subcategories (level 3) do not contain products... how to hide the 2nd level <li> completely, too? it's not easy to me...if someone can help is really appreciated. thanks code example: <li {if $node.curd == 3 && $node.products == 0} style="display:none"{/if} class="{if isset($last) && $last == 'true'}last{/if} {if isset($currentCategoryId) && ($node.id == $currentCategoryId)}actived{/if} toto"> <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> Edited November 22, 2012 by mmsh (see edit history) Link to comment Share on other sites More sharing options...
musicmaster Posted November 22, 2012 Share Posted November 22, 2012 If you want to do that you can't handle that in your tpl file. You have a value like "$node.children" only because in the php script there has been a mysql "select" query that retrieved that value and assigned it to smarty. However, such a query hasn't been done for the content of subcategories. So you will need to do those queries yourself. Link to comment Share on other sites More sharing options...
mmsh Posted November 22, 2012 Author Share Posted November 22, 2012 (edited) how you should do it? 1) select count nodes at 3rd level? 2) count products 3) {if $node.curd == 2 && no nodes && no products} display none {/if} ? can you help me please with a concrete example? sure that i can't manage it with $node.curd (that is the current depth) and $node.children|@count ? and then a foreach children count the products and calculate if are zero or not? Edited November 22, 2012 by mmsh (see edit history) Link to comment Share on other sites More sharing options...
musicmaster Posted November 24, 2012 Share Posted November 24, 2012 As I told you before: you cannot solve this in your tpl file. Instead you should go to your php files. You might start in CategoryController.php in the controllers directory but you might also have a look at category.php in the classes directory. You will get something like "$rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT ...........')" in which you query the table ps_category and ps_product_category. This is complicated stuff that can take hours of work to get everything right. Link to comment Share on other sites More sharing options...
mmsh Posted November 25, 2012 Author Share Posted November 25, 2012 true until a certain point... because you forget that I have already edited the query to get the number of products and the current depth...and with smarty you can do a lot of things: explain the code: i'm at level 2, if the children are more than zero, count the products for every child. If the sum of products remains zero -> Hide the current category at level 2 (and do more!...also hide the 3rd which do not contain products) ;-) it wasn't really complicated. the new category-tree-branch.tpl: {if $node.curd == 2 && $node.children|@count > 0} {assign var=sum value=0} {foreach from=$node.children item=child} {$sum=$sum+$child.products} {/foreach} {/if} <li {if ($node.curd == 2 && $sum == 0) || ($node.curd == 3 && $node.products == 0)}style="display:none"{/if} class="{if isset($last) && $last == 'true'}last{/if} {if isset($currentCategoryId) && ($node.id == $currentCategoryId)}actived{/if} toto"> <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'}{if $node.curd == 3}(<font color="#0b8553"><b>{$node.products}</b></font>){/if}</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> now mark as SOLVED. thanks 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 Link to comment Share on other sites More sharing options...
mmsh Posted June 24, 2013 Author Share Posted June 24, 2013 (edited) Check out my module to hide empty categories in the sidebar and footer Non-empty Categories Module v1.0 Rohit, you did a module with my tips? if you don't show the source code and you let people buy...i can even think that you copied my code to make your module...give me a prove that you didn't follow my guide lines...send me a private message and let me download the code for free. thanks Edited June 24, 2013 by mmsh (see edit history) Link to comment Share on other sites More sharing options...
Rohit Singhal Posted June 24, 2013 Share Posted June 24, 2013 Rohit, you did a module with my tips? if you don't show the source code and you let people buy...i can even think that you copied my code to make your module...give me a prove that you didn't follow my guide lines...send me a private message and let me download the code for free. thanks @mmsh, I have not used your code. Link to comment Share on other sites More sharing options...
mmsh Posted June 24, 2013 Author Share Posted June 24, 2013 @mmsh, I have not used your code. you can say that like me saying that Santa Claus exists...! since clearly I don't need your module 'cause i can code my own, please send me a private message and let me download the module for PS 1.4... so I can confirm that you didn't use my code. Otherwise you should better not to sell that code, more honestly... Link to comment Share on other sites More sharing options...
ste123 Posted October 17, 2014 Share Posted October 17, 2014 you can say that like me saying that Santa Claus exists...! since clearly I don't need your module 'cause i can code my own, please send me a private message and let me download the module for PS 1.4... so I can confirm that you didn't use my code. Otherwise you should better not to sell that code, more honestly... rohit has put the code on github http://github.com/rubrodapa/Empty-Categories-Controller Link to comment Share on other sites More sharing options...
Recommended Posts