Jump to content

[solved] PS 1.5 categories displayed depending on the link in the main horizontal


juanmiguelfp

Recommended Posts

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}

it's what i mean, i need an example function with smarty or how to include php here.

 

{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

Here is my solution:

 

This work only if your category only has a principal Category

 


   foreach ($resultParents[2] as $dat)
  {
		  $principalesIds[] = $dat['id_category'];
   }  


function is_id__cat_in_principal($principalesIds,$id_category){

	  $i=0;

	  while (($principalesIds[$i]!=$id_category)&&($i<count($principalesIds))){
		   $i=$i+1;
	  }

	  if($i==count($principalesIds)){
		return  false;
	  }else{
		return true;
	  }

	}

	// this function return de Id from the main cat Id
	// where $id_category is descendant
   function mainCatId($principalesIds,$resultIds,$id_category){

	  //esta  $id_category en el array de principales
	  if(is_id__cat_in_principal($principalesIds,$id_category)){
		 return  $id_category;
	  }else{
		return  mainCatId($principalesIds,$resultIds,$resultIds[$id_category]["id_parent"]);
	  }
   }


if($id_category>2){

       $categoryPrincipal = mainCatId($principalesIds,$resultIds,$id_category);
     }else{
       $categoryPrincipal = $id_category;
     }


  /*here is the change introduce the $categoryPrincipal at the end */
  $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'),$categoryPrincipal);
  unset($resultParents, $resultIds);

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

  • 3 weeks 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...