Jump to content

How to hide category block depending on active category


Recommended Posts

Hi There,

 

I have got many categories and subcategories on my shop. I have duplicated the Category Block several times to have a different Category module for each category, and to fit in each module its subcategories.

 

What I would like to do is, when we are on a category page, to hide all the other category blocks which are not related to this category, so the result would be that only the category module with subcategories will be visible in that category page.

 

This shop is an example http://www.ferrshop.com/

 

I have found other topics about hiding categories or subcategories, but they work for one category block, for example: this code {if$node.id ! =1} hides a category but within the same category block.

 

What I need is to hide the full category block.

 

I am using version 1.5.4 of Prestashop.

 

Thanks in advance for your help.

Edited by mariafernandez (see edit history)
Link to comment
Share on other sites

  • 2 years later...
  • 3 months later...

Hi,
 
I know the topic was started long time ago but I couldn't find the answer anywhere. Here is what I did to sort out the problem and I hope it helps others. It's a quick fix for those who don't want to edit sql queries etc.
 
Edit blockcategories.php - hookLeftColumn method
Add:

$c = new Category($this->context->cookie->last_visited_category);
$parent_c = $c->getParentsCategories((int)$this->context->language->id);
$this->smarty->assign('currentCategoryParents', $parent_c);

after both occurences of this line:

$this->smarty->assign('currentCategoryId', $this->context->cookie->last_visited_category);

Now edit yout tpl file (category-tree-branch.tpl). It should look more or less like this:

<li class="category_{$node.id}{if isset($last) && $last == 'true'} 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 isset($currentCategoryParents)}
        {foreach from=$currentCategoryParents item=cp_item name=cp_name}
            {if $node.id == $cp_item.id_category && $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}
        {/foreach}
    {/if}
</li>

And it's done :)

Link to comment
Share on other sites

×
×
  • Create New...