sactonet Posted October 1, 2013 Share Posted October 1, 2013 Hi, I have a multistore setup and in one of the stores, the leftside category block just displays the root category and has to be clicked on to display the subcategories. Is there a way to hide the root category and just display the subcategories? Or even if you can't hide the root, can you show or list the subcategories without having to click on the root to expand that tree? Thanks much! Link to comment Share on other sites More sharing options...
tdc666 Posted December 10, 2013 Share Posted December 10, 2013 I know this thread is old, but I'm looking for the same answer and I can't find it anywhere. I want to hide my "root" categories as listing them on the left is redundant, anyone have any ideas? Link to comment Share on other sites More sharing options...
vekia Posted December 11, 2013 Share Posted December 11, 2013 how the category block module looks like now ? can you show it please? Link to comment Share on other sites More sharing options...
tdc666 Posted December 11, 2013 Share Posted December 11, 2013 sure, i'll attach a couple screen shots. the first one shows it as-is, the second one shows what i want to get rid of. pretty much, i want to hide all the root categories and only show the sub categories from the "products" category. everything we sell will be in there. i want to use the other root categories ("Lights" and "Bracket kits") for sorting items that we do not sell on their own, but in packs. for example, we have four models of lights, but we don't sell the lights on their own. each "kit" that we sell comes with a bracket for your specific motorcycle, the light type you choose and the hardware needed to install on your bike. so i'm building "packs" that will automatically assemble all the different parts into one product that you can buy. each "pack" component has to have a category, even though we don't sell the components individually. does this make sense? i know it's kind of complicated. Link to comment Share on other sites More sharing options...
vekia Posted December 11, 2013 Share Posted December 11, 2013 well, it's possible to hide these categories with modification of template file. you have to define there simple if condition like: {if $node.id!=5 || $node.id!=12 || $node.id!=9} HERE FULL CODE OF TPL FILE {/if} it's a category-tree-branch.tpl file of course you have to change $node.id values (you have to use there id of root categories that you've got) other solution: (it's not free unfortunately) Link to comment Share on other sites More sharing options...
tdc666 Posted December 12, 2013 Share Posted December 12, 2013 (edited) so it would look something like this? or do i put the if condition somewhere in the code? i have changed your example id numbers with the correct id numbers of the categories i'm trying to hide. {if $node.id!=769 || $node.id!=476 || $node.id!=477} <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|strip_tags|trim|escape:'htmlall':'UTF-8'}">{$node.name|escape:'htmlall':'UTF-8'}</a> {if $node.children|@count > 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} i tried it out and it doesn't work. if i only have one $node.id called out in my if condition, it will work for that one category, but if i add the other two, or even one more, like so - {if $node.id!=769 || $node.id!=476}, it won't work for any of them. Edited December 12, 2013 by tdc666 (see edit history) Link to comment Share on other sites More sharing options...
tdc666 Posted December 12, 2013 Share Posted December 12, 2013 ok, i replaced the || with && and it seems to be working fine. except i can't hide my products root, or else it hides all the children categories too. Link to comment Share on other sites More sharing options...
tdc666 Posted December 12, 2013 Share Posted December 12, 2013 it seems to me that the module is pulling the categories from the "HOME" root, shouldn't i be able to change something in the code somewhere to tell it what category to pull from? this is relatively over my head, but the module is getting it's information from somewhere, i just want to tell it to pull the info from my "PRODUCTS" category and not the "HOME" category. Link to comment Share on other sites More sharing options...
tdc666 Posted December 12, 2013 Share Posted December 12, 2013 maybe i'm not explaining myself very well. i've done more research and i've found where other people were looking for similar results and people were able to show them where to edit the code to get the required results. all of those threads were for older versions of prestashop, though, and it would appear the code has changed. pretty much, i just want to display one category and it's sub categories in my category block, like the attached picture. this thread (http://www.prestashop.com/forums/topic/70800-solved-categories-displayed-depending-on-the-link-in-the-main-horizontal/page-2) had some useful info that was similar to what i'm wanting, but it's all info for an older version and i can't make sense of the code to try and patch it up to make it work. thanks for the help. Link to comment Share on other sites More sharing options...
tdc666 Posted December 12, 2013 Share Posted December 12, 2013 (edited) ok, after poking at things for a while, i figured it out. i'll put this here for anyone who's searching for a way to run their blockcategories module with a sub-tree rather than the root-tree. the unfortunate part is that you have to modify the blockcategories.php file, which means it could be overwritten next time prestashop updates. i tried sticking the php file in my template/modules/blockcategories folder, but prestashop would not read from it, so you have to modify the file in prestashop's module folder. anyway, the job of this piece of code from the blockcategories.php file is to "get" the category tree (hence "getTree"). 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; } the only part you care about is the first line; you'll notice the "null" where it calls for the category id ($id_category = null), change "null" to the category id number of the subcategory you want to be your root and it should work. my sub-category's id is 769, so i replace "null" with "769" and prestashop is starting my category tree from 769 rather than the root category. public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 769, $currentDepth = 0) if i'm not mistaking, you could probably remove this next piece of code, as i believe it is telling prestashop to default to whatever your home category is if the category id is set at "null". if (is_null($id_category)) $id_category = $this->context->shop->getCategory(); honestly though, i don't really know what i'm doing, so maybe i'll just leave it there. even though i got it functioning as i wanted, please let me know if there's any issues with the way i edited things to make it work. i don't know php very well and i'm kinda just making it up as i go along. Edited December 12, 2013 by tdc666 (see edit history) Link to comment Share on other sites More sharing options...
CLance Posted February 4, 2014 Share Posted February 4, 2014 (edited) at first I make Vekia's suggestion (tpl files in themes), it does not work.To make Vekia's suggestion work,alter Modules -> blockcategories -> category-tree-branch.tplalter Themes -> default -> modules -> blockcategories -> category-tree-branch.tpl Edited February 4, 2014 by Lance Chan (see edit history) Link to comment Share on other sites More sharing options...
sweszler Posted June 25, 2015 Share Posted June 25, 2015 tdc666 your code is working when you use $id_category as string, like: public function getTree($resultParents, $resultIds, $maxDepth, $id_category = "769", $currentDepth = 0) Link to comment Share on other sites More sharing options...
nosnevetzy Posted July 2, 2015 Share Posted July 2, 2015 (edited) tdc666 code is not working on me. Please any help with this problem? I'm using Prestashop 1.6 Edited July 2, 2015 by nosnevetzy (see edit history) Link to comment Share on other sites More sharing options...
koc Posted November 10, 2015 Share Posted November 10, 2015 Bump. Link to comment Share on other sites More sharing options...
ciepolml Posted December 19, 2018 Share Posted December 19, 2018 (edited) In case somebody is trying to open all categories in Presta 1.7.X - here's the fix I posted in other thread. -- Check answer from me at the end --- Edited December 19, 2018 by ciepolml (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