Jump to content

[SOLVED] categories displayed depending on the link in the main horizontal


mr tom

Recommended Posts

Hello
I am new to prestashop i have found most of it easy to edit, I am having one big issue ...

I have a horizontal navigation for the main departments of the shop Kitchen, bathroom etc. I need to make the shop change the left column catogories depending on the department so kitchen woul display links to sink, cupboards etc..

Any help would be great please as i have tried with no joy..

I tried modifing a few posts i have seen on here to add unique code depending on the categorie ID but it didnt work..

Link to comment
Share on other sites

Try changing lines 123-141 of modules/blockcategories/blockcategories.php (in PrestaShop v1.3.1) from:

$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));
$isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);

if (isset($_GET['id_category']))
{
   $cookie->last_visited_category = intval($_GET['id_category']);
   $smarty->assign('currentCategoryId', intval($_GET['id_category']));    
}
if (isset($_GET['id_product']))
{            
   if (!isset($cookie->last_visited_category) OR !Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => $cookie->last_visited_category))))
   {
       $product = new Product(intval($_GET['id_product']));
       if (isset($product) AND Validate::isLoadedObject($product))
           $cookie->last_visited_category = intval($product->id_category_default);
   }
   $smarty->assign('currentCategoryId', intval($cookie->last_visited_category));
}    
$smarty->assign('blockCategTree', $blockCategTree);



to:

$isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);
$currentCategoryId = 1;
if (isset($_GET['id_category']))
{
   $currentCategoryId = intval($_GET['id_category']);
   $cookie->last_visited_category = $currentCategoryId;
   $smarty->assign('currentCategoryId', $currentCategoryId);    
}
if (isset($_GET['id_product']))
{            
   if (!isset($cookie->last_visited_category) OR !Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => $cookie->last_visited_category))))
   {
       $product = new Product(intval($_GET['id_product']));
       if (isset($product) AND Validate::isLoadedObject($product))
           $cookie->last_visited_category = intval($product->id_category_default);
   }
   $currentCategoryId = intval($cookie->last_visited_category);
   $smarty->assign('currentCategoryId', $currentCategoryId);
}    
$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'), $currentCategoryId);
$smarty->assign('blockCategTree', $blockCategTree);

Link to comment
Share on other sites

Try changing lines 123-141 of modules/blockcategories/blockcategories.php (in PrestaShop v1.3.1) from:

$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));
$isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);

if (isset($_GET['id_category']))
{
   $cookie->last_visited_category = intval($_GET['id_category']);
   $smarty->assign('currentCategoryId', intval($_GET['id_category']));    
}
if (isset($_GET['id_product']))
{            
   if (!isset($cookie->last_visited_category) OR !Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => $cookie->last_visited_category))))
   {
       $product = new Product(intval($_GET['id_product']));
       if (isset($product) AND Validate::isLoadedObject($product))
           $cookie->last_visited_category = intval($product->id_category_default);
   }
   $smarty->assign('currentCategoryId', intval($cookie->last_visited_category));
}    
$smarty->assign('blockCategTree', $blockCategTree);



to:

$isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);
$currentCategoryId = 1;
if (isset($_GET['id_category']))
{
   $currentCategoryId = intval($_GET['id_category']);
   $cookie->last_visited_category = $currentCategoryId;
   $smarty->assign('currentCategoryId', $currentCategoryId));    
}
if (isset($_GET['id_product']))
{            
   if (!isset($cookie->last_visited_category) OR !Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => $cookie->last_visited_category))))
   {
       $product = new Product(intval($_GET['id_product']));
       if (isset($product) AND Validate::isLoadedObject($product))
           $cookie->last_visited_category = intval($product->id_category_default);
   }
   $currentCategoryId = intval($cookie->last_visited_category);
   $smarty->assign('currentCategoryId', $currentCategoryId);
}    
$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'), $currentCategoryId);
$smarty->assign('blockCategTree', $blockCategTree);



Thank you for the reply but this makes the website not show up at all, i made sure to place it correctly but nothing but white scene show up..
Link to comment
Share on other sites

  • 7 months later...

Hi,

Let say I have 5 category levels

0,1, 2, 3, etc

I would like to display in "block categories" only 2 current levels.

If I click on level 2 - only categories from lev 2 and lev 3 will be displaing.
If I click on category level 3 - only level 3 and 4 will be displaing.

I hope that makes sense.

HOW TO DO THAT IN PS 1.4??
Please, help me

Link to comment
Share on other sites

My AJAX Sliding Categories module has the option to hide parent categories and sub-subcategories like you want. Unfortunately, the code is too complex for me to simply paste the part of my code that does it here.

Link to comment
Share on other sites

I had a quick look and it looks like you change the query on lines 150-158 of modules/blockcategories/blockcategories.php (in PrestaShop v1.4.1):

if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
   SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
   FROM `'._DB_PREFIX_.'category` c
   LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.$id_lang.')
   LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
   WHERE (c.`active` = 1 OR c.`id_category` = 1)
   '.((int)($maxdepth) != 0 ? ' AND `level_depth` <= '.(int)($maxdepth) : '').'
   AND cg.`id_group` = '.$id_group.'
   ORDER BY `level_depth` ASC, c.`position` ASC')



Change 1 to the current category (or leave it at 1 for other pages), then add a subquery to get the child categories of the current category and another subquery to get the children of those categories.

Link to comment
Share on other sites

You could modify the Smarty templates instead of the SQL query, but then every category will be loaded and just the ones you want displayed, which will slow down your website. Change the query from:

if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
   SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
   FROM `'._DB_PREFIX_.'category` c
   LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.$id_lang.')
   LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
   WHERE (c.`active` = 1 OR c.`id_category` = '.$id_category.' OR c.`id_category` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$id_category.') OR (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$id_category.'))
   AND cg.`id_group` = '.$id_group.'
   ORDER BY `level_depth` ASC, c.`position` ASC')



to:

if (isset($_GET['id_category']))
   $category = (int)$_GET['id_category'];
elseif (isset($_GET['id_product']) AND isset($cookie->last_visited_category))
   $category = (int)$cookie->last_visited_category;
elseif (isset($_GET['id_product']))
{
   $product = new Product((int)$_GET['id_product']);

   if (Validate::isLoadedObject($product))
       $category = $product->id_category_default;    
}
else
   $category = 1;

if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
   SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
   FROM `'._DB_PREFIX_.'category` c
   LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.$id_lang.')
   LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
   WHERE (c.`active` = 1 OR c.`id_category` = '.$category.') AND (c.`id_category` = '.$category.' OR c.`id_parent` = '.$category.' OR c.`id_parent` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$category.'))
   AND cg.`id_group` = '.$id_group.'
   ORDER BY `level_depth` ASC, c.`position` ASC')
           )
               return;



and line 183 from:

$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));



to:

$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'), $category);

Link to comment
Share on other sites

Strange. It's working fine on my PrestaShop v1.4.1 test site. Check to see whether $id_lang is being defined above the code you replaced. If not, you will need to change $id_lang to (int)$cookie->id_lang

Link to comment
Share on other sites

if i replace

$id_lang = (int)($params['cookie']->id_lang);

to

(int)$cookie->id_lang = (int)($params['cookie']->id_lang);

category box displays nothing....


It must be an issue with cashing or something, i'm sure it was working properly for just few minutes of tests at the begining.

Now, im getting all subcategories doubled


I have my PS14 switched to 'developing mode' (cashing off, etc)

Link to comment
Share on other sites

uuups, there is a small bug. Now, subcategories in the category box are displaing twice.

like this:

mens:
-red tshirt
-red tshirt
-blue shorts
-blue shorts
womens:
green skirt
green skirt

etc


There is a bug in PS1.4, thats why Im getting duplicated category.
http://forge.prestashop.com/browse/PSCFI-1616?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel#issue-tabs

Rocky's modification WORKS PERFECT!!!

Thanks for your time Rocky!!

regards
SonnyBoyII
Link to comment
Share on other sites

  • 3 weeks later...

Sorry for my english, but, how can I do with the block categories to display only the
parent category (level depth 2) and children ?

I would like the same behaviour that the original blockcategories (without javascript) but without other categories than the current one with children.

To resume, I would like to hide the other level 2 categories and just show the current one with children.

Maybe better with an example Here

Again, sorry for my english... I hope you will understand. Thank you

Link to comment
Share on other sites

The code above gets the subcategories and sub-subcategories of the current category. To get the subcategories only, use:

if (isset($_GET['id_category']))
   $category = (int)$_GET['id_category'];
elseif (isset($_GET['id_product']) AND isset($cookie->last_visited_category))
   $category = (int)$cookie->last_visited_category;
elseif (isset($_GET['id_product']))
{
   $product = new Product((int)$_GET['id_product']);

   if (Validate::isLoadedObject($product))
       $category = $product->id_category_default;    
}
else
   $category = 1;

if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
   SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
   FROM `'._DB_PREFIX_.'category` c
   LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.$id_lang.')
   LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
   WHERE (c.`active` = 1 OR c.`id_category` = '.$category.') AND (c.`id_category` = '.$category.' OR c.`id_parent` = '.$category.'))
   AND cg.`id_group` = '.$id_group.'
   ORDER BY `level_depth` ASC, c.`position` ASC')
           )
               return;

Link to comment
Share on other sites

The code above gets the subcategories and sub-subcategories of the current category. To get the subcategories only, use:

if (isset($_GET['id_category']))
   $category = (int)$_GET['id_category'];
elseif (isset($_GET['id_product']) AND isset($cookie->last_visited_category))
   $category = (int)$cookie->last_visited_category;
elseif (isset($_GET['id_product']))
{
   $product = new Product((int)$_GET['id_product']);

   if (Validate::isLoadedObject($product))
       $category = $product->id_category_default;    
}
else
   $category = 1;

if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
   SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
   FROM `'._DB_PREFIX_.'category` c
   LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.$id_lang.')
   LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
   WHERE (c.`active` = 1 OR c.`id_category` = '.$category.') AND (c.`id_category` = '.$category.' OR c.`id_parent` = '.$category.'))
   AND cg.`id_group` = '.$id_group.'
   ORDER BY `level_depth` ASC, c.`position` ASC')
           )
               return;



Thanks for your response but that code doesn't return anything. I would like to have the same behaviour that this website for my bloc categories module..

I attached a quick mock up of what I would like. (Fruits & Legumes is a child of "Accueil" category)

Thank you for your time

46124_z789wEWgG0VwG3t7Pzg3_t

Link to comment
Share on other sites

You could modify the Smarty templates instead of the SQL query, but then every category will be loaded and just the ones you want displayed, which will slow down your website. Change the query from:

if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
   SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
   FROM `'._DB_PREFIX_.'category` c
   LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.$id_lang.')
   LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
   WHERE (c.`active` = 1 OR c.`id_category` = '.$id_category.' OR c.`id_category` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$id_category.') OR (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$id_category.'))
   AND cg.`id_group` = '.$id_group.'
   ORDER BY `level_depth` ASC, c.`position` ASC')



to:

if (isset($_GET['id_category']))
   $category = (int)$_GET['id_category'];
elseif (isset($_GET['id_product']) AND isset($cookie->last_visited_category))
   $category = (int)$cookie->last_visited_category;
elseif (isset($_GET['id_product']))
{
   $product = new Product((int)$_GET['id_product']);

   if (Validate::isLoadedObject($product))
       $category = $product->id_category_default;    
}
else
   $category = 1;

if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
   SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
   FROM `'._DB_PREFIX_.'category` c
   LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.$id_lang.')
   LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
   WHERE (c.`active` = 1 OR c.`id_category` = '.$category.') AND (c.`id_category` = '.$category.' OR c.`id_parent` = '.$category.' OR c.`id_parent` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$category.'))
   AND cg.`id_group` = '.$id_group.'
   ORDER BY `level_depth` ASC, c.`position` ASC')
           )
               return;



and line 183 from:

$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));



to:

$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'), $category);




Rocky,could you help me please? how to modify this code to display only level 2 and 3?
If you go to level 4 for example nothing will change. Module will still display 2 and 3 level.
Link to comment
Share on other sites

I don't really understand what you are trying to do, but if I wanted to ignore the first-level categories, I'd change lines 33-37 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}



and modules/blockcategories/category-tree-branch.tpl from:

>

   <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.children|@count > 0}
</pre>
<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>
<br>   {/if}<br



to:

>
{if $depth > 1}
   <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}
   {if $node.children|@count > 0}
       {if $depth > 1}</pre>
<ul>{/if}
       {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}
       {if $depth > 1}</ul>{/if}<br>   {/if}<br>{if $depth > 1}{/if

Link to comment
Share on other sites

Thanks rocky!
I generally will have first level hardcoded on the top menu. On the side standard categories module will be displaing allays only second and third level. If you go deeper nothing happens. Side category still will be displaing 3, 4 level

Link to comment
Share on other sites

Try changing:

if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
   SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
   FROM `'._DB_PREFIX_.'category` c
   LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.$id_lang.')
   LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
   WHERE (c.`active` = 1 OR c.`id_category` = '.$id_category.' OR c.`id_category` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$id_category.') OR (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$id_category.'))
   AND cg.`id_group` = '.$id_group.'
   ORDER BY `level_depth` ASC, c.`position` ASC')



to:

if (isset($_GET['id_category']))
   $category = (int)$_GET['id_category'];
elseif (isset($_GET['id_product']) AND isset($cookie->last_visited_category))
   $category = (int)$cookie->last_visited_category;
elseif (isset($_GET['id_product']))
{
   $product = new Product((int)$_GET['id_product']);

   if (Validate::isLoadedObject($product))
       $category = $product->id_category_default;
}
else
   $category = 1;

$categoryObject = new Category($category);

while (Validate::isLoadedObject($categoryObject) AND $categoryObject->id_parent > 1)
   $categoryObject = new Category($categoryObject->id_parent);

$category = $categoryObject->id_category;

if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
   SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
   FROM `'._DB_PREFIX_.'category` c
   LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.$id_lang.')
   LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
   WHERE (c.`active` = 1 OR c.`id_category` = '.$category.') AND (c.`id_category` = '.$category.' OR c.`id_parent` = '.$category.' OR c.`id_parent` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.$category.'))
   AND cg.`id_group` = '.$id_group.'
   ORDER BY `level_depth` ASC, c.`position` ASC')
  )
   return;



This should find the top-level parent category of the current category, then get the first two levels.

Link to comment
Share on other sites

Thanks rocky!
I generally will have first level hardcoded on the top menu. On the side standard categories module will be displaing allays only second and third level. If you go deeper nothing happens. Side category still will be displaing 3, 4 level


Sorry, i ment allways second and third , if you go by clicking categorie thumbnails to for example 7th level, side category module still shows 2,3 .
Link to comment
Share on other sites

It works if I add this line

$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'), $category); 



but not exactly like I want.

I would like to display only level 2, 3 but counting always from the level 1 (home).
If we go to level 8 module should display level 2,3 of this branch.
Deeper levels will be available from category thumbnails.

Link to comment
Share on other sites

It seems what you want is too complicated. Unfortunately, I can't understand what you want.


I would like to display in category box only level 2,3 from current branch. only this

mens >> tshirt >> funny_tshirt >> >> red>>tshirts >> tshirt_with_stripes >>we_are_here

or

womens >> skirts>> short_skirts>> >> dark_skirts>>we_are_here >> .....


sorry for confusion

regards,
Matt
Link to comment
Share on other sites

I just tested the code I last posted and the code you last posted and it seems to be doing what you want. I had to go to Preferences > Performance and disable the Smarty cache for the category tree to be regenerated though.

Link to comment
Share on other sites

  • 4 weeks later...

hello mr. rocky
i have a question please.
is it possible to make the blockcategories to start from a selected category down the last subcategory?
wat i was able to do with the help of your posts was to make the blockcategories display JUST TWO subcategories and when i click into the subcategory the tree is gone because there is no subcategory

Is it possible sir?

Link to comment
Share on other sites

  • 2 months later...

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 year later...

Hi People,

 

I'm trying to do this for prestashop 1.5 i show you my code.

 

this is my ../blockcategories.tpl

{if  $page_name!="index"}
<!-- Block categories module -->
<div id="categories_block_left" class="block">
<!-- <h4>{l s='Categories' mod='blockcategories'}</h4>  -->
<div class="block_content">
 <ul class="tree">
   <!-- <ul class="tree {if $isDhtml}dhtml{/if}"> -->
 {foreach from=$blockCategTree.children item=child name=blockCategTree}   
  {* here i need to put the correct principal child from a root category and show it *}
  {* now it only works for the first child of the tree and if i click on this in the horizontal menu*} 
	  {if $currentCategoryId == $child.id}
	   {if $smarty.foreach.blockCategTree.last}
		 {include file="$branche_tpl_path" node=$child  last='true' }
	   {else}
	    {include file="$branche_tpl_path" node=$child  }
	   {/if}
	   {/if}
 {/foreach}
 </ul> 
 {* Javascript moved here to fix bug #PSCFI-151 *}
 <!-- <script type="text/javascript">
 // <![CDATA[
  // we hide the tree only if JavaScript is activated
  $('div#categories_block_left ul.dhtml').hide();
 // ]]>
 </script>  -->
</div>
</div>
<!-- /Block categories module -->
{/if}  

 

I only need to pass the principal child that content the currentcategory.

 

i´m thinking in 3 options:

 

 

A - Create with smarty a recurrent function (i had been looking for information in http://www.smarty.net but is a little confused and i suppose is slow)

 

B - With Javascript DOM. To Hidden the unnecesary nodes. (but i will have to change the actual code i had here)

 

C - Generate the blockCategoryTree correct in each time. I think it's the most efficient choice but i need some help.

 

It would be more easy if the code in prestashop was commented. (it's is a suggestion for developers)

Link to comment
Share on other sites

This is more or less what i mean

 

 {foreach from=$blockCategTree.children item=child name=blockCategTree}  
{* is $currentCategoryId descendant  of  $child.id *}
		   {if  is_descendant_of($currentCategoryId , $child.id)}
			   {if $smarty.foreach.blockCategTree.last}
					 {include file="$branche_tpl_path" node=$child  last='true' }
			   {else}
				{include file="$branche_tpl_path" node=$child  }
			   {/if}
		   {/if}
 {/foreach}

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

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