Jump to content

[SOLVED] Categories


Papaya

Recommended Posts

Try changing lines 9-13 of modules/blockcategories/blockcategories.tpl from:

{if $smarty.foreach.blockCategTree.last}
   {include file=$branche_tpl_path node=$child last='true'}
{else}
   {include file=$branche_tpl_path node=$child}
{/if}



to:

{if $smarty.foreach.blockCategTree.last}
   {include file=$branche_tpl_path node=$child depth=1 last='true'}
{else}
   {include file=$branche_tpl_path node=$child depth=1}
{/if}



then change modules/blockcategories/category-tree-branch.tpl to:

>
{assign var='childSelected' value='0'}
{foreach from=$node.children item=child}{if $child.id == $smarty.get.id_category}{assign var='childSelected' value='1'}{/if}{/foreach}
{if $page_name != 'category' OR $depth != 1 OR $node.id == $smarty.get.id_category OR $childSelected}

{$node.name|escape:html:'UTF-8'}
   {if $node.children|@count > 0}
</pre>
<ul>
       {foreach from=$node.children item=child name=categoryTreeBranch}
           {if $smarty.foreach.categoryTreeBranch.last}
                       {include file=$tpl_dir./category-tree-branch.tpl node=$child depth=$depth+1 last='true'}
           {else}
                       {include file=$tpl_dir./category-tree-branch.tpl node=$child depth=$depth+1 last='false'}
           {/if}
       {/foreach}
</ul>
<br>   {/if}<br><br>{/if



This should do what you want as long as the category depth is no more than 2.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 3 months later...
  • 2 weeks later...
  • 1 month later...
  • 3 weeks later...

Dear Rocky, sorry for head up this issue again. Because I have been try the solution as you provide, then I still found that it still have some problem.

1. When I click the main categories mobile phone (picture cate01.jpg), then left column categories place will show Mobile Phone > BlackBerry & HTC. (picture cate01.jpg)

2. When I click the sub categorie which Mobile Phone > BlackBerry (picture cate02.jpg), then left column categories will only show Categories Mobile Phone, no more show as Mobile Phone > BlackBerry & HTC (picture cate03.jpg).

Hope you can provide help again, thanks a lot Rocky.

Regards,
John

30621_cTbfvGUzgPJiymMMaLuN_t

30622_Mtx9sUupxXh8fZEbReYc_t

30623_hyywZpqI6f3CJjQyqiGK_t

Link to comment
Share on other sites

  • 2 months later...

hi rocky,

your solution works fine for me, but i have just one question.

Is it possible to have the option to hide all categories when they are not selected (for example when you are on the homepage no categories are selected and so no categories have to be visible.

thanks a lot


pldtm

Link to comment
Share on other sites

  • 2 months later...

Hi,
I asked my question in a different post, but I think you guys know what to do... PLEASE HELP!

When I take the steps as written on page 1, I have this, for example;


(Categoryblock1):boxershorts

boxershorts A
boxershorts B
boxershorts C
(+)t-shirts: t-shirt A, t-shirt B, t-shirt C (<-- subcategory with ID as used in step 4 of page1, permanently visable. And unfolding when clicking in Category2. I want this not showing up here, only in category2block).
boxershort D
boxershort E


(Categoryblock2):t-shirts

t-shirt A
t-shirt B
t-shirt C


As you can see my second categoriesblock appears also as a subcategory in between other products in category1.
I tried a lot of ways, but this is the only way I can get it done.
How can I just make 2 categories; cat.1 for only product A, and cat.2 for only product B. (not showing B at A)?

Can anyone help me please? I tried everything I know, maybe its in the php files?

Thanks in advance!
Grtz, Don C.

Link to comment
Share on other sites

  • 6 months later...

@rocky

thanks for help! Your post http://www.prestashop.com/forums/topic/48033-solved-categories/page__view__findpost__p__321549 is great and it helped me much. But there is one little issue related more to this forum than to your code. Code snippet in this forum is stripping your code from ul's and li's html tags so sometimes is hard to understand it for the first time.

 

One more thing: when I go to product page all categories are visible like in standard blockcategories. It is possible to get same effect in product page like in category and product-list pages?

 

edit:

 

I've figured it out myself.

 

I've changed:

 

{foreach from=$node.children item=child}{if $child.id == $smarty.get.id_category}{assign var='childSelected' value='1'}{/if}{/foreach}
{if $page_name != 'category' OR $depth != 1 OR $node.id == $smarty.get.id_category OR $childSelected}

 

to

 

{foreach from=$node.children item=child}{if $child.id == $currentCategoryId}{assign var='childSelected' value='1'}{/if}{/foreach}
{if $depth != 1 OR $node.id == $currentCategoryId OR $childSelected}

 

and now itis working both in categories and in product pages.

 

btw I'm using v 1.3.1

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

  • 5 weeks later...

Sorry, but I don't know how to proceed to change the category-tree-branc.tpl. Actually I am using the version 1.4 and the code inside is:

 

 

 

 

<li {if isset($last) && $last == 'true'}class="last"{/if}>

 

<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>

 

 

I replace this code by the one you write, and it doesn't work...I am doing something wrong?

 

Thanks in advance

Link to comment
Share on other sites

Hi Rocky,

 

thanks for u r continuous support for the new users in Prestashop, Iam very new to prestashop and am using version 1.4.1 now i have an issue regarding displaying the categories, the thing is that i want to display only active Category (the one i have selected) and its Subcategories in my page and other categories should not be displayed is that possible and please brief me all the steps in respective files to do the needed changes that will help me a lot.

 

Anil

Bangalore

Link to comment
Share on other sites

  • 1 month later...

I have a problem with a 3th level category: a > b > c > product list . When I click on "c" category, simply disappear all categories, nothing are loaded. Can someone help for that ? Otherwise great mod.

 

Thanks,

Robert

Link to comment
Share on other sites

  • 4 weeks later...

Hi,

 

I have managed to get this working in 1.5 by replacing file=$tpl_dir./category-tree-branch.tpl with file="$branche_tpl_path", but am having issues where if you are on the product page it displays all subcategories it belongs to eg:

 

cat 1

- sub cat 1

- sub cat 2

 

cat 2

-sub cat1

 

Does anyone know how to resolve this? Also having an issue where the menu is not showing at all if you are on one of the sub category pages. Thanks for your help

Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...
I have a problem with a 3th level category: a > b > c > product list . When I click on "c" category, simply disappear all categories, nothing are loaded. Can someone help for that ? Otherwise great mod. Thanks, Robert

Hi, have you find a solution??

I have the same problem!

 

I try to set max depth, but it doesn't work!

Help!

Link to comment
Share on other sites

The problem is here:

 

{assign var='childSelected' value='0'}

{foreach from=$node.children item=child}{if $child.id == $currentCategoryId}{assign var='childSelected' value='1'}{/if}{/foreach}

{if $depth != 1 OR $node.id == $currentCategoryId OR $childSelected}

 

It check only if in sucategories there is a category with the current category id, but if the current category is is the sub-subcategory it doesn't work!!

 

I try this

 

{foreach from=$node.children item=child}{if $child.id == $currentCategoryId}{assign var='childSelected' value='1'}

{else}{foreach from=$node.children item=child}{if $child.id == $currentCategoryId}{assign var='childSelected' value='1'}bb{/if}{/foreach}

{/if}{/foreach}

{if $depth != 1 OR $node.id == $currentCategoryId OR $childSelected==1}

 

but it doesn't work!

Have you idea??

Link to comment
Share on other sites

Today I'm working on a shop that has a top menu (blocktopmenu) with the categories. The menu on the left (blockcategories) should show only the subcategories (or only the main categories on the homepage and information pages.)

 

Example, these are the categories:

-Shoes:
  Running
  Boots
  Heels

-T-shirt
  Blue
  Red
  Yellow

 

What I wanted for this shop:

 

On the home page it would show: Shoes, T-shirt

And when you go to Shoes it would show: Running, Boots, Heels

And when you go to Boots it would still show: Running, Boots, Heels

 

So I changed my category-tree-branch.tpl, here is my code:

 

/themes/theme-name/modules/blockcategories/category-tree-branch.tpl

{assign var="show_child" value="false"}

{if !isset($currentCategoryId)}
<li {if isset($last) && $last == 'true'}class="last"{/if}>
	<a href="{$node.link}" title="{$node.desc|escape:html:'UTF-8'}">{$node.name|escape:html:'UTF-8'}</a>
</li>
{/if}

{if isset($currentCategoryId) && ($node.id == $currentCategoryId)}
{assign var="show_child" value="true"}
{/if}

{if $node.children|@count > 0}
{foreach from=$node.children item=child name=categoryTreeBranch}
	{if isset($currentCategoryId) && ($child.id == $currentCategoryId)}
		{assign var="show_child" value="true"}
	{/if}
{/foreach}
{/if}

{if $show_child == 'true'}
{if $node.children|@count > 0}
	{foreach from=$node.children item=child name=categoryTreeBranch}
		{if isset($smarty.foreach.categoryTreeBranch) && $smarty.foreach.categoryTreeBranch.last}
			{include file="$branche_tpl_path" node=$child show='true' last='true'}
		{else}
			{include file="$branche_tpl_path" node=$child show='true' last='false'}
		{/if}
	{/foreach}
   {if $child.children|@count > 0}
           {foreach from=$child.children item=child2 name=categoryTreeBranch2}
               {if isset($currentCategoryId) && ($child2.id == $currentCategoryId)}
                   {assign var="show_child" value="true"}
               {/if}
           {/foreach}
       {/if}
{/if}
{/if}


{if isset($show)}
<li {if isset($last) && $last == 'true'}class="last"{/if}>
<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 show='true' last='true'}
		{else}
			{include file="$branche_tpl_path" node=$child show='true' last='false'}
		{/if}
	{/foreach}
	</ul>
{/if}
</li>
{/if}

 

Not sure if this example is what you guys want, but I though I will just share it. Also perhaps this code is not optiomal, but at least it works for me :)

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

  • 7 months later...

If you want more depth:

edit category-tree-branch.tpl

 

{foreach from=$node.children item=child}
{if $child.id == $smarty.get.id_category}
 {assign var='childSelected' value='1'}
   {/if}
   {foreach from=$child.children item=child2}
 {if $child2.id == $smarty.get.id_category}
  {assign var='childSelected' value='1'}
 {/if}
    {foreach from=$child2.children item=child3}
  {if $child3.id == $smarty.get.id_category}
   {assign var='childSelected' value='1'}
  {/if}
 {/foreach}
   {/foreach}
{/foreach}

Link to comment
Share on other sites

  • 5 weeks later...

Any body knows how to make changes of html tags in first node of category lists in top menu?

top menu Module / blocktopmenu.php

 

line:645

 

// filter the categories that the user is allowed to see and browse

if (!empty($is_intersected))

{

if(count($children)){

$this->_menu .= '<dd id="4" '.$selected.'>';

$this->_menu .= '<a href="'.$category_link.'">'.$category->name.'</a>';}

 

else{$this->_menu .= '<li class="medb" id="9" '.$selected.'>';

$this->_menu .= '<a class="norm five area-christmas" href="'.$category_link.'">'.$category->name.'</a>';}

 

if (count($children))

{

if($node.children){

$this->_menu .= '<li id="10">';

foreach ($children as $child)

$this->getCategory((int)$child['id_category'], (int)$id_lang, (int)$child['id_shop']);

$this->_menu .= '</li>';}

else if($show_child == 'true'){$this->_menu .= '<dl>';

foreach ($children as $child)

$this->getCategory((int)$child['id_category'], (int)$id_lang, (int)$child['id_shop']);

$this->_menu .= '</dl>';}

}

if($node.children){$this->_menu .= '</dd>';}

 

else{$this->_menu .= '</li>';}

 

}

line:684

if (count($categories) || count($pages))

{

$this->_menu .= '<dl class="1">';

 

foreach ($categories as $category)

{

$this->_menu .= '<dd id="1" >';

$this->_menu .= '<a id="1" href="#">'.$category['name'].'</a>';

$this->getCMSMenuItems($category['id_cms_category'], (int)$depth + 1);

$this->_menu .= '</dd>';

}

 

foreach ($pages as $page)

{

$cms = new CMS($page['id_cms'], (int)$id_lang);

$links = $cms->getLinks((int)$id_lang, array((int)$cms->id));

 

$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';

$this->_menu .= '<dd id="2" '.$selected.'>';

$this->_menu .= '<a id="2" href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';

$this->_menu .= '</dd>';

}

 

$this->_menu .= '</ul>';

};

line:

Link to comment
Share on other sites

if (!empty($is_intersected))

{

if (false){

 

}

else{

$this->_menu .= '<li class="medb" id="3" '.$selected.'>';

$this->_menu .= '<a class="norm five area-christmas" href="'.$category_link.'">'.$category->name.'</a>';

}

 

if (count($children))

{

$this->_menu .= '<dl>';

 

foreach ($children as $child)

$this->getCategory((int)$child['id_category'], (int)$id_lang, (int)$child['id_shop']);

 

$this->_menu .= '</dl>';

}

if(false){

 

}

else{

$this->_menu .= '</li>';

}

}

Link to comment
Share on other sites

Any body knows how to add proper condition for if that contains false condition in this code to apply changes only for first node of categories?

(!empty($is_intersected))

{

if (false){

$this->_menu .= '<dd id="3" '.$selected.'>';

$this->_menu .= '<a href="'.$category_link.'">'.$category->name.'</a>';

}

else{

$this->_menu .= '<li class="medb" id="3" '.$selected.'>';

$this->_menu .= '<a class="norm five area-christmas" href="'.$category_link.'">'.$category->name.'</a>';

}

 

if (count($children))

{

 

$this->_menu .= '<dl>';

 

foreach ($children as $child)

$this->getCategory((int)$child['id_category'], (int)$id_lang, (int)$child['id_shop']);

 

$this->_menu .= '</dl>';

 

}

if(false){

$this->_menu .= '</dd>';

}

else{

$this->_menu .= '</li>';

}

}

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

  • 5 weeks later...

Today I'm working on a shop that has a top menu (blocktopmenu) with the categories. The menu on the left (blockcategories) should show only the subcategories (or only the main categories on the homepage and information pages.)

 

Example, these are the categories:

-Shoes:
  Running
  Boots
  Heels

-T-shirt
  Blue
  Red
  Yellow

 

What I wanted for this shop:

 

On the home page it would show: Shoes, T-shirt

And when you go to Shoes it would show: Running, Boots, Heels

And when you go to Boots it would still show: Running, Boots, Heels

 

So I changed my category-tree-branch.tpl, here is my code:

 

/themes/theme-name/modules/blockcategories/category-tree-branch.tpl

{assign var="show_child" value="false"}

{if !isset($currentCategoryId)}
<li {if isset($last) && $last == 'true'}class="last"{/if}>
	<a href="{$node.link}" title="{$node.desc|escape:html:'UTF-8'}">{$node.name|escape:html:'UTF-8'}</a>
</li>
{/if}

{if isset($currentCategoryId) && ($node.id == $currentCategoryId)}
{assign var="show_child" value="true"}
{/if}

{if $node.children|@count > 0}
{foreach from=$node.children item=child name=categoryTreeBranch}
	{if isset($currentCategoryId) && ($child.id == $currentCategoryId)}
		{assign var="show_child" value="true"}
	{/if}
{/foreach}
{/if}

{if $show_child == 'true'}
{if $node.children|@count > 0}
	{foreach from=$node.children item=child name=categoryTreeBranch}
		{if isset($smarty.foreach.categoryTreeBranch) && $smarty.foreach.categoryTreeBranch.last}
			{include file="$branche_tpl_path" node=$child show='true' last='true'}
		{else}
			{include file="$branche_tpl_path" node=$child show='true' last='false'}
		{/if}
	{/foreach}
   {if $child.children|@count > 0}
		{foreach from=$child.children item=child2 name=categoryTreeBranch2}
			{if isset($currentCategoryId) && ($child2.id == $currentCategoryId)}
				{assign var="show_child" value="true"}
			{/if}
		{/foreach}
	{/if}
{/if}
{/if}


{if isset($show)}
<li {if isset($last) && $last == 'true'}class="last"{/if}>
<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 show='true' last='true'}
		{else}
			{include file="$branche_tpl_path" node=$child show='true' last='false'}
		{/if}
	{/foreach}
	</ul>
{/if}
</li>
{/if}

 

Not sure if this example is what you guys want, but I though I will just share it. Also perhaps this code is not optiomal, but at least it works for me :)

 

 

 

That Worked BUT only with first level categories !!!

When i navigate at subcategory i would like to show ONLY the Sub-subcategories at the left and instead i get again the whole tree.

 

 

Can you help me on that ??

 

Thanks

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

I tried following what is written in this post to have hints on how to accomplish this:

 

on 1.5.3.1 block categories i'm trying to show only level 1 category and related subcategories

example:

 

home

--shoes

-----runners

-----boots

--clothes

-----shirts

-----pants

 

when i'm inside shoes i want only to see shoes and related subcategories and not clothes or other categories at the same level as shoes. When i'm in a subcategory (lvl2) i want to see only the parent category (lvl1 parent cat (shoes)) and the others subcategory at the same level (lvl2(runner,boots)). Can anyone help me on how to do it?

 

Thanks

Edited by Supermanzo (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Today I'm working on a shop that has a top menu (blocktopmenu) with the categories. The menu on the left (blockcategories) should show only the subcategories (or only the main categories on the homepage and information pages.)

 

Example, these are the categories:

-Shoes:
  Running
  Boots
  Heels

-T-shirt
  Blue
  Red
  Yellow

 

What I wanted for this shop:

 

On the home page it would show: Shoes, T-shirt

And when you go to Shoes it would show: Running, Boots, Heels

And when you go to Boots it would still show: Running, Boots, Heels

 

So I changed my category-tree-branch.tpl, here is my code:

 

/themes/theme-name/modules/blockcategories/category-tree-branch.tpl

{assign var="show_child" value="false"}

{if !isset($currentCategoryId)}
<li {if isset($last) && $last == 'true'}class="last"{/if}>
	<a href="{$node.link}" title="{$node.desc|escape:html:'UTF-8'}">{$node.name|escape:html:'UTF-8'}</a>
</li>
{/if}

{if isset($currentCategoryId) && ($node.id == $currentCategoryId)}
{assign var="show_child" value="true"}
{/if}

{if $node.children|@count > 0}
{foreach from=$node.children item=child name=categoryTreeBranch}
	{if isset($currentCategoryId) && ($child.id == $currentCategoryId)}
		{assign var="show_child" value="true"}
	{/if}
{/foreach}
{/if}

{if $show_child == 'true'}
{if $node.children|@count > 0}
	{foreach from=$node.children item=child name=categoryTreeBranch}
		{if isset($smarty.foreach.categoryTreeBranch) && $smarty.foreach.categoryTreeBranch.last}
			{include file="$branche_tpl_path" node=$child show='true' last='true'}
		{else}
			{include file="$branche_tpl_path" node=$child show='true' last='false'}
		{/if}
	{/foreach}
   {if $child.children|@count > 0}
		{foreach from=$child.children item=child2 name=categoryTreeBranch2}
			{if isset($currentCategoryId) && ($child2.id == $currentCategoryId)}
				{assign var="show_child" value="true"}
			{/if}
		{/foreach}
	{/if}
{/if}
{/if}


{if isset($show)}
<li {if isset($last) && $last == 'true'}class="last"{/if}>
<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 show='true' last='true'}
		{else}
			{include file="$branche_tpl_path" node=$child show='true' last='false'}
		{/if}
	{/foreach}
	</ul>
{/if}
</li>
{/if}

 

Not sure if this example is what you guys want, but I though I will just share it. Also perhaps this code is not optiomal, but at least it works for me :)

 

Another version of this code... PLEASE HELP US...

http://pastebin.com/0ZPJsMaz

Link to comment
Share on other sites

  • 4 months later...

Is there any way of getting the blockcategories to display when you are deeper than 3 categories?

I have added this slightly modded code from above;


   {assign var="show_child" value="false"}

   {if !isset($currentCategoryId)}
	    <li {if isset($last) && $last == 'true'}class="last"{/if}>
			    <a href="{$node.link}" title="{$node.desc|escape:html:'UTF-8'}">{$node.name|escape:html:'UTF-8'}</a>
	    </li>
   {/if}

   {if isset($currentCategoryId) && ($node.id == $currentCategoryId)}
	    {assign var="show_child" value="true"}
   {/if}

   {if $node.children|@count > 0}
	    {foreach from=$node.children item=child name=categoryTreeBranch}
			    {if isset($currentCategoryId) && ($child.id == $currentCategoryId)}
					    {assign var="show_child" value="true"}
			    {/if}
	    {/foreach}
   {/if}

   {if $show_child == 'true'}
	    {if $node.children|@count > 0}
			    {foreach from=$node.children item=child name=categoryTreeBranch}
					    {if isset($smarty.foreach.categoryTreeBranch) && $smarty.foreach.categoryTreeBranch.last}

					    {else}
							    {include file="$branche_tpl_path" node=$child show='true' last='false'}
					    {/if}
			    {/foreach}
		   {if $child.children|@count > 0}
		    {foreach from=$child.children item=child2 name=categoryTreeBranch2}
			    {if isset($currentCategoryId) && ($child2.id == $currentCategoryId)}
				    {assign var="show_child" value="true"}
			    {/if}
		    {/foreach}
	    {/if}
	    {/if}
   {/if}


   {if isset($show)}
   <li {if isset($last) && $last == 'true'}class="last"{/if}>
	    <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 show='true' last='true'}
					    {else}

					    {/if}
			    {/foreach}
			    </ul>
	    {/if}
   </li>
   {/if}

 

But when I am navigating to a 3rd level category, the block is empty.

I need it to return the sub categories from where ever the user is.

 

I have set the configuration to a maximum depth of 0 (infinate), 3,4,5,6 etc. but nothing was displaying.

on level 1 and 2, this works fine.

 

Any pointers to what might be missing?

Link to comment
Share on other sites

  • 4 months later...
  • 3 months later...

Today I'm working on a shop that has a top menu (blocktopmenu) with the categories. The menu on the left (blockcategories) should show only the subcategories (or only the main categories on the homepage and information pages.)

 

Example, these are the categories:

-Shoes:
   Running
   Boots
   Heels

-T-shirt
   Blue
   Red
   Yellow
What I wanted for this shop:

 

On the home page it would show: Shoes, T-shirt

And when you go to Shoes it would show: Running, Boots, Heels

And when you go to Boots it would still show: Running, Boots, Heels

 

So I changed my category-tree-branch.tpl, here is my code:

 

/themes/theme-name/modules/blockcategories/category-tree-branch.tpl

{assign var="show_child" value="false"}

{if !isset($currentCategoryId)}
	<li {if isset($last) && $last == 'true'}class="last"{/if}>
		<a href="{$node.link}" title="{$node.desc|escape:html:'UTF-8'}">{$node.name|escape:html:'UTF-8'}</a>
	</li>
{/if}

{if isset($currentCategoryId) && ($node.id == $currentCategoryId)}
	{assign var="show_child" value="true"}
{/if}

{if $node.children|@count > 0}
	{foreach from=$node.children item=child name=categoryTreeBranch}
		{if isset($currentCategoryId) && ($child.id == $currentCategoryId)}
			{assign var="show_child" value="true"}
		{/if}
	{/foreach}
{/if}

{if $show_child == 'true'}
	{if $node.children|@count > 0}
		{foreach from=$node.children item=child name=categoryTreeBranch}
			{if isset($smarty.foreach.categoryTreeBranch) && $smarty.foreach.categoryTreeBranch.last}
				{include file="$branche_tpl_path" node=$child show='true' last='true'}
			{else}
				{include file="$branche_tpl_path" node=$child show='true' last='false'}
			{/if}
		{/foreach}
	   {if $child.children|@count > 0}
            {foreach from=$child.children item=child2 name=categoryTreeBranch2}
                {if isset($currentCategoryId) && ($child2.id == $currentCategoryId)}
                    {assign var="show_child" value="true"}
                {/if}
            {/foreach}
        {/if}
	{/if}
{/if}


{if isset($show)}
<li {if isset($last) && $last == 'true'}class="last"{/if}>
	<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 show='true' last='true'}
			{else}
				{include file="$branche_tpl_path" node=$child show='true' last='false'}
			{/if}
		{/foreach}
		</ul>
	{/if}
</li>
{/if}
Not sure if this example is what you guys want, but I though I will just share it. Also perhaps this code is not optiomal, but at least it works for me :)

 

Thank you, your code works correctly, a greeting! 
 
Tested on prestashop 1.6.0.5! :)
Link to comment
Share on other sites

  • 1 month later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...