tdr170 Posted September 8, 2016 Share Posted September 8, 2016 Testing 1.7 and I see the category tree always collapse after selecting a sub category, is there a way to have this remain open so you do not have to re-open menu to get to other sub categories as in 1.6. I have looked but do not see anything, any ideas. 2 Link to comment Share on other sites More sharing options...
Vincent Beudez Posted September 8, 2016 Share Posted September 8, 2016 Hi, On which page please ? Link to comment Share on other sites More sharing options...
tdr170 Posted September 8, 2016 Author Share Posted September 8, 2016 Any page, open the menu and click on any subcategory and the menu collapses back to Women instead of staying on the subcategory. I am testing the site in a 2 column layout so you use the left category tree all the time no top menu. 2 Link to comment Share on other sites More sharing options...
deonderd Posted May 4, 2017 Share Posted May 4, 2017 i have the same problem.. in 1.7 the categery tree does not stay open in the category u are in.. its very confusing for customers if u have like several subcategories.. for example for mercedes -> filters -> Oilfilters i would prefer also that the whole tree stays visible.. for easy navigating 1 Link to comment Share on other sites More sharing options...
tukker Posted July 6, 2017 Share Posted July 6, 2017 I have the same problem. I would aso prefer the whole tree is expanded. Haven you already found a solution ? I have found some themes where the created this. So there must be a way to get this working Link to comment Share on other sites More sharing options...
templatin Posted July 8, 2017 Share Posted July 8, 2017 You can keep the whole tree similar on all pages by configuring the "Category tree links" module in Back-office. Select the following option: Category root => Home category. You can also try other options based on your requirement. 3 2 Link to comment Share on other sites More sharing options...
tiwelle Posted August 24, 2017 Share Posted August 24, 2017 Have you found a way to keep the category tree open on a category page ? @templatin, your solution is answering the question. It does have some options to configure, but what if you want to have the entire category tree (with all categories), open on current category ? That is what tdr170 is asking. Thank you ! Link to comment Share on other sites More sharing options...
tiwelle Posted August 24, 2017 Share Posted August 24, 2017 I have a solution You can add a class to the category tree you're in by {if $node.id == $category.id} displaymytree{/if} Then, with Jquery, you can target all parents from this particular class $(document).ready(function(){ $( '.displaymytree' ).parents( ".collapse" ).addClass('displaymytree'); }); And then, force display block on all elements with that class : .displaymytree.collapse { display: block; } Enjoy ! 1 Link to comment Share on other sites More sharing options...
condorazul Posted October 24, 2017 Share Posted October 24, 2017 On 24/8/2017 at 0:40 PM, tiwelle said: I have a solution You can add a class to the category tree you're in by {if $node.id == $category.id} displaymytree{/if} Then, with Jquery, you can target all parents from this particular class $(document).ready(function(){ $( '.displaymytree' ).parents( ".collapse" ).addClass('displaymytree'); }); And then, force display block on all elements with that class : .displaymytree.collapse { display: block; } Enjoy ! And where should we put that code... Link to comment Share on other sites More sharing options...
Rynraf Posted October 28, 2017 Share Posted October 28, 2017 (edited) I was trying to use this code {if $node.id == $category.id} displaymytree{/if} in this file /themes/classic/modules/ps_categorytree/views/templates/hook/ps_categorytree.tpl but there is an error. I'm also don't know how/where to implement this change. Could you please give some advice? I have a feeling that if I would like to have mark selected category using some CSS class I have to use some code like above... Am I right? What I would like to acheive is to have by default expanded all categories and subcategories. I would like to have shown, expanded all categories all the time as I have now in PS 1.6 (my shop on PS 1.6: https://palmatum.pl ). Any advice? Now with this new PS 1.7 (not so new today...) I'm feel like years ago with OsCommerce - when I would like to have something - I have to code this by myself Edited October 28, 2017 by Rynraf (see edit history) Link to comment Share on other sites More sharing options...
Rynraf Posted October 31, 2017 Share Posted October 31, 2017 Answer to my own question... In my Prestashop I would like to have exapned all categories all the time. I'm starting with "Classic" theme. In file: /themes/classic/modules/ps_categorytree/views/templates/hook/ps_categorytree.tpl it's enugh to make two little changes. In two lines (line numer 39 and 50) which looks like this: <div class="collapse" id="exCollapsingNavbar{$node.id}"> add " in" to class atribute and add attribute "aria-expanded" with value "true". Final this two lines will look like this: <div class="collapse in" id="exCollapsingNavbar{$node.id}" aria-expanded="true"> That's all. Upload changed file. 2 2 1 Link to comment Share on other sites More sharing options...
tantan199 Posted December 19, 2017 Share Posted December 19, 2017 Hi, I created a tutorial several weeks ago about the problem, check it here: how to set the Category tree links module to expand the brunch containing current category in PrestaShop 1.7, 3 1 Link to comment Share on other sites More sharing options...
Kunsthelden Posted January 9, 2018 Share Posted January 9, 2018 Dear tantan199 your code works fine. The only thing that is missing for the classic theme is the collapse in. The arrows and + works fine, also after reloade but the whole navigation remains open. I still can recommend your solution. kind regards, Link to comment Share on other sites More sharing options...
tantan199 Posted January 11, 2018 Share Posted January 11, 2018 @Kunsthelden what did you mean "the whole navigation remains open"? Can you please explain it more, so I can improve that guide. Thanks. Link to comment Share on other sites More sharing options...
heyho Posted May 28, 2018 Share Posted May 28, 2018 Here is a working solution: https://www.sunnytoo.com/8222/how-to-set-the-category-tree-links-module-to-expand-the-brunch-containing-current-category-in-prestashop-1-7 Link to comment Share on other sites More sharing options...
Blessy_Preferred Posted May 28, 2018 Share Posted May 28, 2018 On 12/18/2017 at 7:54 PM, tantan199 said: Hi, I created a tutorial several weeks ago about the problem, check it here: how to set the Category tree links module to expand the brunch containing current category in PrestaShop 1.7, Works great on PS 1.7.2.4!! Thanks so much! Link to comment Share on other sites More sharing options...
satellite73 Posted November 21, 2018 Share Posted November 21, 2018 (edited) Quote Works great on PS 1.7.2.4!! Thanks so much! Unfortunately it works not on PS 1.7.4.4. Is there a solution? Or can someone upload the modified files? Maybe I made something wrong? Kind regards from Switzerland Edited November 21, 2018 by satellite73 (see edit history) Link to comment Share on other sites More sharing options...
satellite73 Posted November 22, 2018 Share Posted November 22, 2018 (edited) Hi I upload the changes files. Is there a pro who can find the mistake? XXXX Thank you very much. Edited November 22, 2018 by satellite73 (see edit history) Link to comment Share on other sites More sharing options...
satellite73 Posted November 22, 2018 Share Posted November 22, 2018 I'm sorry, it was a problem of cache. Link to comment Share on other sites More sharing options...
Enrique Gómez Posted December 18, 2018 Share Posted December 18, 2018 On 12/19/2017 at 4:54 AM, tantan199 said: Hi, I created a tutorial several weeks ago about the problem, check it here: how to set the Category tree links module to expand the brunch containing current category in PrestaShop 1.7, Thanks a lot, it works perfect, the info is really useful for a 1.7.2.4. I still don't understand this lost of features between 1.6 and 1.7 .. Link to comment Share on other sites More sharing options...
ciepolml Posted December 19, 2018 Share Posted December 19, 2018 In case somebody still fights and wants a neat one .tpl file solution without CSS involved. See my answer at the end in this thread. Just adding"in" to one class and then {if !$_collapse} aria-expanded="true"{/if} to reverse aria status from closed to opened for icon to work correctly. Link to comment Share on other sites More sharing options...
remoteONE Posted March 26, 2019 Share Posted March 26, 2019 Has PS fixed this issue in 1.7.4.4? Link to comment Share on other sites More sharing options...
TomasVlcek Posted April 24, 2019 Share Posted April 24, 2019 On 19. 12. 2017 at 4:54, tantan199 said: Ahoj, Vytvořil jsem tutoriál před několika týdny o problému, prohlédněte si ho zde: jak nastavit modul pro propojení kategorií stromů a rozšířit brunch obsahující aktuální kategorii v PrestaShopu 1.7 , Really great work, thank you for the amazing tutorial and great help !!! Link to comment Share on other sites More sharing options...
mustang80 Posted May 19, 2019 Share Posted May 19, 2019 This does not work on 1.7.5.1 . I tried. jak nastavit modul pro propojení kategorií stromů a rozšířit brunch obsahující aktuální kategorii v PrestaShopu 1.7 , My site : https://hopshop.bg/ its my code theme file : ps_categorytree.tpl {function name='categories' nodes=[] depth=0} {strip} {if $nodes|count} <ul class="category-sub-menu list-unstyled list-arrows font-weight-bold"> {foreach from=$nodes item=node} <li data-depth="{$depth}"> {if $depth === 0} <a href="{$node.link}">{$node.name}</a> {if $node.children} <div class="navbar-toggler collapse-icons border-0 float-right" data-toggle="collapse" data-target="#exCollapsingNavbar{$node.id}"> <i class="icon-add-square add" aria-hidden="true"></i> <i class="icon-remove-square remove hidden" aria-hidden="true"></i> </div> <div class="collapse" id="exCollapsingNavbar{$node.id}">{categories nodes=$node.children depth=($depth + 1)}</div> {/if} {else} <a href="{$node.link}" class="category-sub-link">{$node.name}</a> {if $node.children} <span class="arrows" data-toggle="collapse" data-target="#exCollapsingNavbar{$node.id}"> <i class="icon-angle-right arrow-right ml-2 align-top" aria-hidden="true"></i> <i class="icon-angle-down arrow-down ml-2 align-top hidden" aria-hidden="true"></i> </span> <div class="collapse" id="exCollapsingNavbar{$node.id}">{categories nodes=$node.children depth=($depth + 1)}</div> {/if} {/if} </li> {/foreach} </ul> {/if} {/strip} {/function} <div class="block-categories side-block"> <p class="block-title"><a href="{$categories.link nofilter}">{$categories.name}</a></p> <div class="block-content">{categories nodes=$categories.children}</div> </div> 1 Link to comment Share on other sites More sharing options...
mysz Posted May 20, 2019 Share Posted May 20, 2019 (edited) On 12/19/2017 at 4:54 AM, tantan199 said: Hi, I created a tutorial several weeks ago about the problem, check it here: how to set the Category tree links module to expand the brunch containing current category in PrestaShop 1.7, Hello, I have classic rocket theme, and I do it everything like in your tutorial, except one (where is span, in classic rocket there is no span in that place, and I also replace 'in' by 'show'). And now I have a problem when I click on "clothes" category, I would like to all category in clothes to be showed, but this only show category when I go to "Men". Edit. When I change for classic theme, and do everything like in the tutorial I have the same problem Edited May 20, 2019 by mysz (see edit history) 1 Link to comment Share on other sites More sharing options...
tantan199 Posted May 21, 2019 Share Posted May 21, 2019 @mysz I mentioned how to expand the current category’s child categories in that tutorial, you probably didn't see that part. Link to comment Share on other sites More sharing options...
Alex Castillo Posted April 22, 2020 Share Posted April 22, 2020 On 5/19/2019 at 11:54 PM, mustang80 said: This does not work on 1.7.5.1 . I tried. jak nastavit modul pro propojení kategorií stromů a rozšířit brunch obsahující aktuální kategorii v PrestaShopu 1.7 , My site : https://hopshop.bg/ its my code theme file : ps_categorytree.tpl {function name='categories' nodes=[] depth=0} {strip} {if $nodes|count} <ul class="category-sub-menu list-unstyled list-arrows font-weight-bold"> {foreach from=$nodes item=node} <li data-depth="{$depth}"> {if $depth === 0} <a href="{$node.link}">{$node.name}</a> {if $node.children} <div class="navbar-toggler collapse-icons border-0 float-right" data-toggle="collapse" data-target="#exCollapsingNavbar{$node.id}"> <i class="icon-add-square add" aria-hidden="true"></i> <i class="icon-remove-square remove hidden" aria-hidden="true"></i> </div> <div class="collapse" id="exCollapsingNavbar{$node.id}">{categories nodes=$node.children depth=($depth + 1)}</div> {/if} {else} <a href="{$node.link}" class="category-sub-link">{$node.name}</a> {if $node.children} <span class="arrows" data-toggle="collapse" data-target="#exCollapsingNavbar{$node.id}"> <i class="icon-angle-right arrow-right ml-2 align-top" aria-hidden="true"></i> <i class="icon-angle-down arrow-down ml-2 align-top hidden" aria-hidden="true"></i> </span> <div class="collapse" id="exCollapsingNavbar{$node.id}">{categories nodes=$node.children depth=($depth + 1)}</div> {/if} {/if} </li> {/foreach} </ul> {/if} {/strip} {/function} <div class="block-categories side-block"> <p class="block-title"><a href="{$categories.link nofilter}">{$categories.name}</a></p> <div class="block-content">{categories nodes=$categories.children}</div> </div> hi, and you code in ps_categorytree.php? i need show menu in category and subcategory. Link to comment Share on other sites More sharing options...
tantan199 Posted May 5, 2020 Share Posted May 5, 2020 @Alex Castillo It seems you've figured it out, let me know if you need more help. 1 Link to comment Share on other sites More sharing options...
nestorps Posted December 5, 2020 Share Posted December 5, 2020 For everyone with this problem. You dont need to edit the core controller. Just copy the template file modules/ps_categorytree/views/templates/hook/ps_categorytree.tpl in your theme modules themes/yourtheme/modules/ps_categorytree/views/templates/hook/ps_categorytree.tpl edit this line with: {foreach from=$nodes item=node} <li> TO {foreach from=$nodes item=node} <li class="roots" id="node-{$node.id}"> And then with jquery target de selected item and then go up to expand the div: if(jQuery(".category-tree").length>0){ var id=location.href.split("/"); id=id[id.length-1].split("-")[0]; jQuery("#node-"+id).addClass("selected-cat"); /*class to add color to the selected item*/ jQuery("#node-"+id).closest("div").addClass("in"); /*depends on the theme. Expand the div*/ jQuery("#node-"+id).parents("li.roots").find(".navbar-toggler").attr("aria-expanded","true"); /*depends on the theme*/ } 1 Link to comment Share on other sites More sharing options...
mudol Posted July 19, 2021 Share Posted July 19, 2021 (edited) Could someone paste here ALL code from ps_categorytree.tpl after changes? On my site, that code didn't work, prestasho p1.77, template: classic for now i have: public function getWidgetVariables($hookName = null, array $configuration = []) { $category = new Category((int) Configuration::get('PS_HOME_CATEGORY'), $this->context->language->id); if (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') && isset($this->context->cookie->last_visited_category) && $this->context->cookie->last_visited_category) { $category = new Category($this->context->cookie->last_visited_category, $this->context->language->id); if (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') == 2 && !$category->is_root_category && $category->id_parent) { $category = new Category($category->id_parent, $this->context->language->id); } elseif (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') == 3 && !$category->is_root_category && !$category->getSubCategories($category->id, true)) { $category = new Category($category->id_parent, $this->context->language->id); } } return [ 'categories' => $this->getCategories($category), 'c_tree_path' => isset($categories['children']) && count($categories['children']) && method_exists($this->context->controller, 'getCategory') && ($curr_category = $this->context->controller->getCategory()) ? self::getTreePath($categories['children'], $curr_category->id) : false, 'currentCategory' => $category->id, ]; } public static function getTreePath($categories, $id, array $path = []) { foreach ($categories as $cate) { if ($cate['id'] == $id){ if(is_array($cate['children']) && count($cate['children'])) $path[] = $cate['id']; return $path; } $path[] = $cate['id']; if(is_array($cate['children']) && count($cate['children'])) { if ($result = self::getTreePath($cate['children'], $id, $path)) return $result; } array_pop($path); } return false; } from ps_categorytree.php and it from ps_categorytree.tpl: {** * Copyright since 2007 PrestaShop SA and Contributors * PrestaShop is an International Registered Trademark & Property of PrestaShop SA * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License 3.0 (AFL-3.0) * that is bundled with this package in the file LICENSE.md. * It is also available through the world-wide-web at this URL: * https://opensource.org/licenses/AFL-3.0 * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to https://devdocs.prestashop.com/ for more information. * * @author PrestaShop SA and Contributors <contact@prestashop.com> * @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) *} {function name="categories" nodes=[] depth=0} {strip} {if $nodes|count} <ul class="category-sub-menu"> {foreach from=$nodes item=node} <li data-depth="{$depth}"> {if $depth===0} <a href="{$node.link}">{$node.name}</a> {if $node.children} <div class="navbar-toggler collapse-icons{if $c_tree_path && !in_array($node.id, $c_tree_path)} collapsed zmiana{/if} cos1" data-toggle="collapse" data-target="#exCollapsingNavbar{$node.id}"> <i class="material-icons add"></i> <i class="material-icons remove"></i> </div> <div class="collapse{if $c_tree_path && in_array($node.id, $c_tree_path)} in zmiana2{/if} cos2" id="exCollapsingNavbar{$node.id}"> {categories nodes=$node.children depth=$depth+1} </div> {/if} {else} <a class="category-sub-link" href="{$node.link}">{$node.name}</a> {if $node.children} <span class="arrows{if $c_tree_path && !in_array($node.id, $c_tree_path)} collapsed zmiana3{/if} cos3" data-toggle="collapse" data-target="#exCollapsingNavbar{$node.id}"> <i class="material-icons arrow-right"></i> <i class="material-icons arrow-down"></i> </span> <div class="collapse{if $c_tree_path && in_array($node.id, $c_tree_path)} in zmiana4{/if} cos4" id="exCollapsingNavbar{$node.id}"> {categories nodes=$node.children depth=$depth+1} </div> {/if} {/if} </li> {/foreach} </ul> {/if} {/strip} {/function} <div class="block-categories hidden-sm-down"> <ul class="category-top-menu"> <li><a class="text-uppercase h6" href="{$categories.link nofilter}">{$categories.name}</a></li> <li>{categories nodes=$categories.children}</li> </ul> </div> Edited July 19, 2021 by mudol (see edit history) Link to comment Share on other sites More sharing options...
gasparpulgas Posted July 22, 2021 Share Posted July 22, 2021 Hi Somebody Can help me?, the image of category don't show in móvil, I use Classic 1.7.6.7 I moved this part of code for to show the category "hidden-sm-down" and with this I could shown the category but not the image <div class="block-categories /*hidden-sm-down*/"> <ul class="category-top-menu"> <li><a class="text-uppercase h6" href="{$categories.link nofilter}">{$categories.name}</a></li> <li>{categories nodes=$categories.children}</li> </ul> </div> Link to comment Share on other sites More sharing options...
ComGrafPL Posted July 23, 2021 Share Posted July 23, 2021 Can you show a link to your store? Link to comment Share on other sites More sharing options...
Billy Posted September 10, 2021 Share Posted September 10, 2021 On 12/5/2020 at 8:30 AM, nestorps said: For everyone with this problem. You dont need to edit the core controller. Just copy the template file modules/ps_categorytree/views/templates/hook/ps_categorytree.tpl in your theme modules themes/yourtheme/modules/ps_categorytree/views/templates/hook/ps_categorytree.tpl edit this line with: {foreach from=$nodes item=node} <li> TO {foreach from=$nodes item=node} <li class="roots" id="node-{$node.id}"> And then with jquery target de selected item and then go up to expand the div: if(jQuery(".category-tree").length>0){ var id=location.href.split("/"); id=id[id.length-1].split("-")[0]; jQuery("#node-"+id).addClass("selected-cat"); /*class to add color to the selected item*/ jQuery("#node-"+id).closest("div").addClass("in"); /*depends on the theme. Expand the div*/ jQuery("#node-"+id).parents("li.roots").find(".navbar-toggler").attr("aria-expanded","true"); /*depends on the theme*/ } What file does this bottom jQuery example go? Link to comment Share on other sites More sharing options...
Billy Posted September 10, 2021 Share Posted September 10, 2021 I have this example code below from the ( Main Menu in Prestashop 1.7.7.7 ) Which is called the ( ps_categorytree module ) I just want the stock menu to work In this example I have modified the bottom of the file with the code from https://www.sunnytoo.com/8222/how-to-set-the-category-tree-links-module-to-expand-the-brunch-containing-current-category-in-prestashop-1-7 I used his two example in my code all the way at the bottom of this post aka Here is his example #1 $categories = $this->getCategories($category); return [ 'categories' => $categories, 'c_tree_path' => isset($categories['children']) && count($categories['children']) && method_exists($this->context->controller, 'getCategory') && ($curr_category = $this->context->controller->getCategory()) ? self::getTreePath($categories['children'], $curr_category->id) : false, 'currentCategory' => $category->id, ]; Here is the second example from Sonny's website ST Themes aka "If you want to expand the current category's child categories, see @Pepecop's question on the comment section below, then use this getTreePath function to instead the one on the step #2." public static function getTreePath($categories, $id, array $path = []) { foreach ($categories as $cate) { if ($cate['id'] == $id){ if(is_array($cate['children']) && count($cate['children'])) $path[] = $cate['id']; return $path; } $path[] = $cate['id']; if(is_array($cate['children']) && count($cate['children'])) { if ($result = self::getTreePath($cate['children'], $id, $path)) return $result; } array_pop($path); } return false; } I am getting a ( syntax error, unexpected 'public' (T_PUBLIC) on line ( 338, 1 ) Can anyone fix this one issue please please please. Could you fix the complete file and repost the whole file below? I have been going around and around with this menu for two days as I'm not a coder. Thank you in Advance! Billy <?php /** * Copyright since 2007 PrestaShop SA and Contributors * PrestaShop is an International Registered Trademark & Property of PrestaShop SA * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License 3.0 (AFL-3.0) * that is bundled with this package in the file LICENSE.md. * It is also available through the world-wide-web at this URL: * https://opensource.org/licenses/AFL-3.0 * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to https://devdocs.prestashop.com/ for more information. * * @author PrestaShop SA and Contributors <[email protected]> * @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ if (!defined('_PS_VERSION_')) { exit; } use PrestaShop\PrestaShop\Core\Module\WidgetInterface; class Ps_CategoryTree extends Module implements WidgetInterface { /** * @var string Name of the module running on PS 1.6.x. Used for data migration. */ const PS_16_EQUIVALENT_MODULE = 'blockcategories'; public function __construct() { $this->name = 'ps_categorytree'; $this->tab = 'front_office_features'; $this->version = '2.0.2'; $this->author = 'PrestaShop'; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->getTranslator()->trans('Category tree links', [], 'Modules.Categorytree.Admin'); $this->description = $this->getTranslator()->trans('Help navigation on your store, show your visitors current category and subcategories.', [], 'Modules.Categorytree.Admin'); $this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_]; } public function install() { // If the PS 1.6 module wasn't here, set the default values if (!$this->uninstallPrestaShop16Module()) { Configuration::updateValue('BLOCK_CATEG_MAX_DEPTH', 4); Configuration::updateValue('BLOCK_CATEG_ROOT_CATEGORY', 1); } return parent::install() && $this->registerHook('displayLeftColumn') ; } /** * Migrate data from 1.6 equivalent module (if applicable), then uninstall */ public function uninstallPrestaShop16Module() { if (!Module::isInstalled(self::PS_16_EQUIVALENT_MODULE)) { return false; } $oldModule = Module::getInstanceByName(self::PS_16_EQUIVALENT_MODULE); if ($oldModule) { // This closure calls the parent class to prevent data to be erased // It allows the new module to be configured without migration $parentUninstallClosure = function () { return parent::uninstall(); }; $parentUninstallClosure = $parentUninstallClosure->bindTo($oldModule, get_class($oldModule)); $parentUninstallClosure(); } return true; } public function uninstall() { if (!parent::uninstall() || !Configuration::deleteByName('BLOCK_CATEG_MAX_DEPTH') || !Configuration::deleteByName('BLOCK_CATEG_ROOT_CATEGORY')) { return false; } return true; } public function getContent() { $output = ''; if (Tools::isSubmit('submitBlockCategories')) { $maxDepth = (int) (Tools::getValue('BLOCK_CATEG_MAX_DEPTH')); if ($maxDepth < 0) { $output .= $this->displayError($this->getTranslator()->trans('Maximum depth: Invalid number.', [], 'Admin.Notifications.Error')); } else { Configuration::updateValue('BLOCK_CATEG_MAX_DEPTH', (int) $maxDepth); Configuration::updateValue('BLOCK_CATEG_SORT_WAY', Tools::getValue('BLOCK_CATEG_SORT_WAY')); Configuration::updateValue('BLOCK_CATEG_SORT', Tools::getValue('BLOCK_CATEG_SORT')); Configuration::updateValue('BLOCK_CATEG_ROOT_CATEGORY', Tools::getValue('BLOCK_CATEG_ROOT_CATEGORY')); //$this->_clearBlockcategoriesCache(); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&conf=6'); } } return $output . $this->renderForm(); } private function getCategories($category) { $range = ''; $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); if (Validate::isLoadedObject($category)) { if ($maxdepth > 0) { $maxdepth += $category->level_depth; } $range = 'AND nleft >= ' . (int) $category->nleft . ' AND nright <= ' . (int) $category->nright; } $resultIds = []; $resultParents = []; $result = Db::getInstance((bool) _PS_USE_SQL_SLAVE_)->executeS(' SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite FROM `' . _DB_PREFIX_ . 'category` c INNER JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = ' . (int) $this->context->language->id . Shop::addSqlRestrictionOnLang('cl') . ') INNER JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = ' . (int) $this->context->shop->id . ') WHERE (c.`active` = 1 OR c.`id_category` = ' . (int) Configuration::get('PS_HOME_CATEGORY') . ') AND c.`id_category` != ' . (int) Configuration::get('PS_ROOT_CATEGORY') . ' ' . ((int) $maxdepth != 0 ? ' AND `level_depth` <= ' . (int) $maxdepth : '') . ' ' . $range . ' AND c.id_category IN ( SELECT id_category FROM `' . _DB_PREFIX_ . 'category_group` WHERE `id_group` IN (' . pSQL(implode(', ', Customer::getGroupsStatic((int) $this->context->customer->id))) . ') ) ORDER BY `level_depth` ASC, ' . (Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'cs.`position`') . ' ' . (Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC')); foreach ($result as &$row) { $resultParents[$row['id_parent']][] = &$row; $resultIds[$row['id_category']] = &$row; } return $this->getTree($resultParents, $resultIds, $maxdepth, ($category ? $category->id : null)); } public function getTree($resultParents, $resultIds, $maxDepth, $id_category = null, $currentDepth = 0) { if (is_null($id_category)) { $id_category = $this->context->shop->getCategory(); } $children = []; 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 [ 'id' => $id_category, 'link' => $link, 'name' => $name, 'desc' => $desc, 'children' => $children, ]; } public function renderForm() { $fields_form = [ 'form' => [ 'legend' => [ 'title' => $this->getTranslator()->trans('Settings', [], 'Admin.Global'), 'icon' => 'icon-cogs', ], 'input' => [ [ 'type' => 'radio', 'label' => $this->getTranslator()->trans('Category root', [], 'Modules.Categorytree.Admin'), 'name' => 'BLOCK_CATEG_ROOT_CATEGORY', 'hint' => $this->getTranslator()->trans('Select which category is displayed in the block. The current category is the one the visitor is currently browsing.', [], 'Modules.Categorytree.Admin'), 'values' => [ [ 'id' => 'home', 'value' => 0, 'label' => $this->getTranslator()->trans('Home category', [], 'Modules.Categorytree.Admin'), ], [ 'id' => 'current', 'value' => 1, 'label' => $this->getTranslator()->trans('Current category', [], 'Modules.Categorytree.Admin'), ], [ 'id' => 'parent', 'value' => 2, 'label' => $this->getTranslator()->trans('Parent category', [], 'Modules.Categorytree.Admin'), ], [ 'id' => 'current_parent', 'value' => 3, 'label' => $this->getTranslator()->trans('Current category, unless it has no subcategories, in which case the parent category of the current category is used', [], 'Modules.Categorytree.Admin'), ], ], ], [ 'type' => 'text', 'label' => $this->getTranslator()->trans('Maximum depth', [], 'Modules.Categorytree.Admin'), 'name' => 'BLOCK_CATEG_MAX_DEPTH', 'desc' => $this->getTranslator()->trans('Set the maximum depth of category sublevels displayed in this block (0 = infinite).', [], 'Modules.Categorytree.Admin'), ], [ 'type' => 'radio', 'label' => $this->getTranslator()->trans('Sort', [], 'Admin.Actions'), 'name' => 'BLOCK_CATEG_SORT', 'values' => [ [ 'id' => 'name', 'value' => 1, 'label' => $this->getTranslator()->trans('By name', [], 'Admin.Global'), ], [ 'id' => 'position', 'value' => 0, 'label' => $this->getTranslator()->trans('By position', [], 'Admin.Global'), ], ], ], [ 'type' => 'radio', 'label' => $this->getTranslator()->trans('Sort order', [], 'Admin.Actions'), 'name' => 'BLOCK_CATEG_SORT_WAY', 'values' => [ [ 'id' => 'name', 'value' => 1, 'label' => $this->getTranslator()->trans('Descending', [], 'Admin.Global'), ], [ 'id' => 'position', 'value' => 0, 'label' => $this->getTranslator()->trans('Ascending', [], 'Admin.Global'), ], ], ], ], 'submit' => [ 'title' => $this->getTranslator()->trans('Save', [], 'Admin.Actions'), ], ], ]; $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $helper->submit_action = 'submitBlockCategories'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = [ 'fields_value' => $this->getConfigFieldsValues(), ]; return $helper->generateForm([$fields_form]); } public function getConfigFieldsValues() { return [ 'BLOCK_CATEG_MAX_DEPTH' => Tools::getValue('BLOCK_CATEG_MAX_DEPTH', Configuration::get('BLOCK_CATEG_MAX_DEPTH')), 'BLOCK_CATEG_SORT_WAY' => Tools::getValue('BLOCK_CATEG_SORT_WAY', Configuration::get('BLOCK_CATEG_SORT_WAY')), 'BLOCK_CATEG_SORT' => Tools::getValue('BLOCK_CATEG_SORT', Configuration::get('BLOCK_CATEG_SORT')), 'BLOCK_CATEG_ROOT_CATEGORY' => Tools::getValue('BLOCK_CATEG_ROOT_CATEGORY', Configuration::get('BLOCK_CATEG_ROOT_CATEGORY')), ]; } public function setLastVisitedCategory() { if (method_exists($this->context->controller, 'getCategory') && ($category = $this->context->controller->getCategory())) { $this->context->cookie->last_visited_category = $category->id; } elseif (method_exists($this->context->controller, 'getProduct') && ($product = $this->context->controller->getProduct())) { if (!isset($this->context->cookie->last_visited_category) || !Product::idIsOnCategoryId($product->id, [['id_category' => $this->context->cookie->last_visited_category]]) || !Category::inShopStatic($this->context->cookie->last_visited_category, $this->context->shop) ) { $this->context->cookie->last_visited_category = (int) $product->id_category_default; } } } public function renderWidget($hookName = null, array $configuration = []) { $this->setLastVisitedCategory(); $this->smarty->assign($this->getWidgetVariables($hookName, $configuration)); return $this->fetch('module:ps_categorytree/views/templates/hook/ps_categorytree.tpl'); } public function getWidgetVariables($hookName = null, array $configuration = []) { $category = new Category((int) Configuration::get('PS_HOME_CATEGORY'), $this->context->language->id); if (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') && isset($this->context->cookie->last_visited_category) && $this->context->cookie->last_visited_category) { $category = new Category($this->context->cookie->last_visited_category, $this->context->language->id); if (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') == 2 && !$category->is_root_category && $category->id_parent) { $category = new Category($category->id_parent, $this->context->language->id); } elseif (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') == 3 && !$category->is_root_category && !$category->getSubCategories($category->id, true)) { $category = new Category($category->id_parent, $this->context->language->id); } } $categories = $this->getCategories($category); return [ 'categories' => $categories, 'c_tree_path' => isset($categories['children']) && count($categories['children']) && method_exists($this->context->controller, 'getCategory') && ($curr_category = $this->context->controller->getCategory()) ? self::getTreePath($categories['children'], $curr_category->id) : false, 'currentCategory' => $category->id, ] ; public static function getTreePath($categories, $id, array $path = []) { foreach ($categories as $cate) { if ($cate['id'] == $id){ if(is_array($cate['children']) && count($cate['children'])) $path[] = $cate['id']; return $path; } $path[] = $cate['id']; if(is_array($cate['children']) && count($cate['children'])) { if ($result = self::getTreePath($cate['children'], $id, $path)) return $result; } array_pop($path); } return false; } Link to comment Share on other sites More sharing options...
Billy Posted September 10, 2021 Share Posted September 10, 2021 @razaro was kind enough to post this code in another post. It worked for me! <?php /** * Copyright since 2007 PrestaShop SA and Contributors * PrestaShop is an International Registered Trademark & Property of PrestaShop SA * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License 3.0 (AFL-3.0) * that is bundled with this package in the file LICENSE.md. * It is also available through the world-wide-web at this URL: * https://opensource.org/licenses/AFL-3.0 * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to https://devdocs.prestashop.com/ for more information. * * @author PrestaShop SA and Contributors <[email protected]> * @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ if (!defined('_PS_VERSION_')) { exit; } use PrestaShop\PrestaShop\Core\Module\WidgetInterface; class Ps_CategoryTree extends Module implements WidgetInterface { /** * @var string Name of the module running on PS 1.6.x. Used for data migration. */ const PS_16_EQUIVALENT_MODULE = 'blockcategories'; public function __construct() { $this->name = 'ps_categorytree'; $this->tab = 'front_office_features'; $this->version = '2.0.2'; $this->author = 'PrestaShop'; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->getTranslator()->trans('Category tree links', [], 'Modules.Categorytree.Admin'); $this->description = $this->getTranslator()->trans('Help navigation on your store, show your visitors current category and subcategories.', [], 'Modules.Categorytree.Admin'); $this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_]; } public function install() { // If the PS 1.6 module wasn't here, set the default values if (!$this->uninstallPrestaShop16Module()) { Configuration::updateValue('BLOCK_CATEG_MAX_DEPTH', 4); Configuration::updateValue('BLOCK_CATEG_ROOT_CATEGORY', 1); } return parent::install() && $this->registerHook('displayLeftColumn') ; } /** * Migrate data from 1.6 equivalent module (if applicable), then uninstall */ public function uninstallPrestaShop16Module() { if (!Module::isInstalled(self::PS_16_EQUIVALENT_MODULE)) { return false; } $oldModule = Module::getInstanceByName(self::PS_16_EQUIVALENT_MODULE); if ($oldModule) { // This closure calls the parent class to prevent data to be erased // It allows the new module to be configured without migration $parentUninstallClosure = function () { return parent::uninstall(); }; $parentUninstallClosure = $parentUninstallClosure->bindTo($oldModule, get_class($oldModule)); $parentUninstallClosure(); } return true; } public function uninstall() { if (!parent::uninstall() || !Configuration::deleteByName('BLOCK_CATEG_MAX_DEPTH') || !Configuration::deleteByName('BLOCK_CATEG_ROOT_CATEGORY')) { return false; } return true; } public function getContent() { $output = ''; if (Tools::isSubmit('submitBlockCategories')) { $maxDepth = (int) (Tools::getValue('BLOCK_CATEG_MAX_DEPTH')); if ($maxDepth < 0) { $output .= $this->displayError($this->getTranslator()->trans('Maximum depth: Invalid number.', [], 'Admin.Notifications.Error')); } else { Configuration::updateValue('BLOCK_CATEG_MAX_DEPTH', (int) $maxDepth); Configuration::updateValue('BLOCK_CATEG_SORT_WAY', Tools::getValue('BLOCK_CATEG_SORT_WAY')); Configuration::updateValue('BLOCK_CATEG_SORT', Tools::getValue('BLOCK_CATEG_SORT')); Configuration::updateValue('BLOCK_CATEG_ROOT_CATEGORY', Tools::getValue('BLOCK_CATEG_ROOT_CATEGORY')); //$this->_clearBlockcategoriesCache(); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&conf=6'); } } return $output . $this->renderForm(); } private function getCategories($category) { $range = ''; $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); if (Validate::isLoadedObject($category)) { if ($maxdepth > 0) { $maxdepth += $category->level_depth; } $range = 'AND nleft >= ' . (int) $category->nleft . ' AND nright <= ' . (int) $category->nright; } $resultIds = []; $resultParents = []; $result = Db::getInstance((bool) _PS_USE_SQL_SLAVE_)->executeS(' SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite FROM `' . _DB_PREFIX_ . 'category` c INNER JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = ' . (int) $this->context->language->id . Shop::addSqlRestrictionOnLang('cl') . ') INNER JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = ' . (int) $this->context->shop->id . ') WHERE (c.`active` = 1 OR c.`id_category` = ' . (int) Configuration::get('PS_HOME_CATEGORY') . ') AND c.`id_category` != ' . (int) Configuration::get('PS_ROOT_CATEGORY') . ' ' . ((int) $maxdepth != 0 ? ' AND `level_depth` <= ' . (int) $maxdepth : '') . ' ' . $range . ' AND c.id_category IN ( SELECT id_category FROM `' . _DB_PREFIX_ . 'category_group` WHERE `id_group` IN (' . pSQL(implode(', ', Customer::getGroupsStatic((int) $this->context->customer->id))) . ') ) ORDER BY `level_depth` ASC, ' . (Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'cs.`position`') . ' ' . (Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC')); foreach ($result as &$row) { $resultParents[$row['id_parent']][] = &$row; $resultIds[$row['id_category']] = &$row; } return $this->getTree($resultParents, $resultIds, $maxdepth, ($category ? $category->id : null)); } public function getTree($resultParents, $resultIds, $maxDepth, $id_category = null, $currentDepth = 0) { if (is_null($id_category)) { $id_category = $this->context->shop->getCategory(); } $children = []; 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 [ 'id' => $id_category, 'link' => $link, 'name' => $name, 'desc' => $desc, 'children' => $children, ]; } public function renderForm() { $fields_form = [ 'form' => [ 'legend' => [ 'title' => $this->getTranslator()->trans('Settings', [], 'Admin.Global'), 'icon' => 'icon-cogs', ], 'input' => [ [ 'type' => 'radio', 'label' => $this->getTranslator()->trans('Category root', [], 'Modules.Categorytree.Admin'), 'name' => 'BLOCK_CATEG_ROOT_CATEGORY', 'hint' => $this->getTranslator()->trans('Select which category is displayed in the block. The current category is the one the visitor is currently browsing.', [], 'Modules.Categorytree.Admin'), 'values' => [ [ 'id' => 'home', 'value' => 0, 'label' => $this->getTranslator()->trans('Home category', [], 'Modules.Categorytree.Admin'), ], [ 'id' => 'current', 'value' => 1, 'label' => $this->getTranslator()->trans('Current category', [], 'Modules.Categorytree.Admin'), ], [ 'id' => 'parent', 'value' => 2, 'label' => $this->getTranslator()->trans('Parent category', [], 'Modules.Categorytree.Admin'), ], [ 'id' => 'current_parent', 'value' => 3, 'label' => $this->getTranslator()->trans('Current category, unless it has no subcategories, in which case the parent category of the current category is used', [], 'Modules.Categorytree.Admin'), ], ], ], [ 'type' => 'text', 'label' => $this->getTranslator()->trans('Maximum depth', [], 'Modules.Categorytree.Admin'), 'name' => 'BLOCK_CATEG_MAX_DEPTH', 'desc' => $this->getTranslator()->trans('Set the maximum depth of category sublevels displayed in this block (0 = infinite).', [], 'Modules.Categorytree.Admin'), ], [ 'type' => 'radio', 'label' => $this->getTranslator()->trans('Sort', [], 'Admin.Actions'), 'name' => 'BLOCK_CATEG_SORT', 'values' => [ [ 'id' => 'name', 'value' => 1, 'label' => $this->getTranslator()->trans('By name', [], 'Admin.Global'), ], [ 'id' => 'position', 'value' => 0, 'label' => $this->getTranslator()->trans('By position', [], 'Admin.Global'), ], ], ], [ 'type' => 'radio', 'label' => $this->getTranslator()->trans('Sort order', [], 'Admin.Actions'), 'name' => 'BLOCK_CATEG_SORT_WAY', 'values' => [ [ 'id' => 'name', 'value' => 1, 'label' => $this->getTranslator()->trans('Descending', [], 'Admin.Global'), ], [ 'id' => 'position', 'value' => 0, 'label' => $this->getTranslator()->trans('Ascending', [], 'Admin.Global'), ], ], ], ], 'submit' => [ 'title' => $this->getTranslator()->trans('Save', [], 'Admin.Actions'), ], ], ]; $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $helper->submit_action = 'submitBlockCategories'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = [ 'fields_value' => $this->getConfigFieldsValues(), ]; return $helper->generateForm([$fields_form]); } public function getConfigFieldsValues() { return [ 'BLOCK_CATEG_MAX_DEPTH' => Tools::getValue('BLOCK_CATEG_MAX_DEPTH', Configuration::get('BLOCK_CATEG_MAX_DEPTH')), 'BLOCK_CATEG_SORT_WAY' => Tools::getValue('BLOCK_CATEG_SORT_WAY', Configuration::get('BLOCK_CATEG_SORT_WAY')), 'BLOCK_CATEG_SORT' => Tools::getValue('BLOCK_CATEG_SORT', Configuration::get('BLOCK_CATEG_SORT')), 'BLOCK_CATEG_ROOT_CATEGORY' => Tools::getValue('BLOCK_CATEG_ROOT_CATEGORY', Configuration::get('BLOCK_CATEG_ROOT_CATEGORY')), ]; } public function setLastVisitedCategory() { if (method_exists($this->context->controller, 'getCategory') && ($category = $this->context->controller->getCategory())) { $this->context->cookie->last_visited_category = $category->id; } elseif (method_exists($this->context->controller, 'getProduct') && ($product = $this->context->controller->getProduct())) { if (!isset($this->context->cookie->last_visited_category) || !Product::idIsOnCategoryId($product->id, [['id_category' => $this->context->cookie->last_visited_category]]) || !Category::inShopStatic($this->context->cookie->last_visited_category, $this->context->shop) ) { $this->context->cookie->last_visited_category = (int) $product->id_category_default; } } } public function renderWidget($hookName = null, array $configuration = []) { $this->setLastVisitedCategory(); $this->smarty->assign($this->getWidgetVariables($hookName, $configuration)); return $this->fetch('module:ps_categorytree/views/templates/hook/ps_categorytree.tpl'); } public function getWidgetVariables($hookName = null, array $configuration = []) { $category = new Category((int) Configuration::get('PS_HOME_CATEGORY'), $this->context->language->id); if (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') && isset($this->context->cookie->last_visited_category) && $this->context->cookie->last_visited_category) { $category = new Category($this->context->cookie->last_visited_category, $this->context->language->id); if (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') == 2 && !$category->is_root_category && $category->id_parent) { $category = new Category($category->id_parent, $this->context->language->id); } elseif (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') == 3 && !$category->is_root_category && !$category->getSubCategories($category->id, true)) { $category = new Category($category->id_parent, $this->context->language->id); } } $categories = $this->getCategories($category); return [ 'categories' => $categories, 'c_tree_path' => isset($categories['children']) && count($categories['children']) && method_exists($this->context->controller, 'getCategory') && ($curr_category = $this->context->controller->getCategory()) ? self::getTreePath($categories['children'], $curr_category->id) : false, 'currentCategory' => $category->id, ] ; } public static function getTreePath($categories, $id, array $path = []) { foreach ($categories as $cate) { if ($cate['id'] == $id){ if(is_array($cate['children']) && count($cate['children'])) $path[] = $cate['id']; return $path; } $path[] = $cate['id']; if(is_array($cate['children']) && count($cate['children'])) { if ($result = self::getTreePath($cate['children'], $id, $path)) return $result; } array_pop($path); } return false; } } Link to comment Share on other sites More sharing options...
Pragati P Posted April 10, 2023 Share Posted April 10, 2023 (edited) Hi, I tried to make the same changes in code but its not working as I am using themevolty theme can anyone help me for left panel category panel open. My code looks like <ul class="category-sub-menu"> {foreach from=$nodes item=node} <li data-depth="{$depth}"> {if $depth===0} <a href="{$node.link}">{$node.name}</a> {if $node.children} <div class="navbar-toggler collapse-icons" data-toggle="collapse" data-target="#exCollapsingNavbar{$node.id}"> <i class="material-icons add"></i> <i class="material-icons remove"></i> </div> <div class="collapse" id="exCollapsingNavbar{$node.id}"> {categories nodes=$node.children depth=$depth+1} </div> {/if} {else} <a class="category-sub-link" href="{$node.link}">{$node.name}</a> {if $node.children} <span class="navbar-toggler collapse-icons" data-toggle="collapse" data-target="#exCollapsingNavbar{$node.id}"> <i class="material-icons add"></i> <i class="material-icons remove"></i> </span> <div class="collapse" id="exCollapsingNavbar{$node.id}"> {categories nodes=$node.children depth=$depth+1} </div> {/if} {/if} </li> {/foreach} </ul> Edited April 10, 2023 by Pragati P (see edit history) Link to comment Share on other sites More sharing options...
koguja Posted February 5 Share Posted February 5 On 5/28/2018 at 11:14 PM, Blessy_Preferred said: Works great on PS 1.7.2.4!! Thanks so much! Try to use this on 8.1.0 now, also working. Thanks. 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