Jump to content

Hide root category in Left "Categories Block"


sactonet

Recommended Posts

Hi, I have a multistore setup and in one of the stores, the leftside category block just displays the root category and has to be clicked on to display the subcategories. 

 

Is there a way to hide the root category and just display the subcategories? 

 

Or even if you can't hide the root, can you show or list the subcategories without having to click on the root to expand that tree?

 

Thanks much!

Link to comment
Share on other sites

  • 2 months later...

sure, i'll attach a couple screen shots. the first one shows it as-is, the second one shows what i want to get rid of. pretty much, i want to hide all the root categories and only show the sub categories from the "products" category. everything we sell will be in there. i want to use the other root categories ("Lights" and "Bracket kits") for sorting items that we do not sell on their own, but in packs.

 

for example, we have four models of lights, but we don't sell the lights on their own. each "kit" that we sell comes with a bracket for your specific motorcycle, the light type you choose and the hardware needed to install on your bike. 
so i'm building "packs" that will automatically assemble all the different parts into one product that you can buy. 

each "pack" component has to have a category, even though we don't sell the components individually.

does this make sense? i know it's kind of complicated.

post-711233-0-22555800-1386788958_thumb.png

post-711233-0-40251000-1386789031_thumb.png

Link to comment
Share on other sites

well, it's possible to hide these categories with modification of template file.

you have to define there simple if condition like:

{if $node.id!=5 || $node.id!=12 || $node.id!=9}
HERE FULL CODE OF TPL FILE
{/if}

it's a category-tree-branch.tpl file

 

of course you have to change $node.id values (you have to use there id of root categories that you've got)

 

 

other solution: (it's not free unfortunately)

Link to comment
Share on other sites

so it would look something like this? or do i put the if condition somewhere in the code? i have changed your example id numbers with the correct id numbers of the categories i'm trying to hide.

{if $node.id!=769 || $node.id!=476 || $node.id!=477}

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

{/if}

i tried it out and it doesn't work. if i only have one $node.id called out in my if condition, it will work for that one category, but if i add the other two, or even one more, like so -  {if $node.id!=769 || $node.id!=476}, it won't work for any of them. 
 

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

it seems to me that the module is pulling the categories from the "HOME" root, shouldn't i be able to change something in the code somewhere to tell it what category to pull from? this is relatively over my head, but the module is getting it's information from somewhere, i just want to tell it to pull the info from my "PRODUCTS" category and not the "HOME" category.

Link to comment
Share on other sites

maybe i'm not explaining myself very well. i've done more research and i've found where other people were looking for similar results and people were able to show them where to edit the code to get the required results. all of those threads were for older versions of prestashop, though, and it would appear the code has changed.

 

pretty much, i just want to display one category and it's sub categories in my category block, like the attached picture.

 

post-711233-0-54019800-1386873648_thumb.png

 

this thread (http://www.prestashop.com/forums/topic/70800-solved-categories-displayed-depending-on-the-link-in-the-main-horizontal/page-2) had some useful info that was similar to what i'm wanting, but it's all info for an older version and i can't make sense of the code to try and patch it up to make it work.

 

thanks for the help.

Link to comment
Share on other sites

ok, after poking at things for a while, i figured it out. 

i'll put this here for anyone who's searching for a way to run their blockcategories module with a sub-tree rather than the root-tree.

 

the unfortunate part is that you have to modify the blockcategories.php file, which means it could be overwritten next time prestashop updates. i tried sticking the php file in my template/modules/blockcategories folder, but prestashop would not read from it, so you have to modify the file in prestashop's module folder.

 

anyway, the job of this piece of code from the blockcategories.php file is to "get" the category tree (hence "getTree"). 

	public function getTree($resultParents, $resultIds, $maxDepth, $id_category = null, $currentDepth = 0)
	{
		if (is_null($id_category))
			$id_category = $this->context->shop->getCategory();

		$children = array();
		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]))
			return false;
		$return = array('id' => $id_category, 'link' => $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']),
					 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'],
					 'children' => $children);
		return $return;
	}

the only part you care about is the first line; you'll notice the "null" where it calls for the category id ($id_category = null), change "null" to the category id number of the subcategory you want to be your root and it should work. 

 

my sub-category's id is 769, so i replace "null" with "769" and prestashop is starting my category tree from 769 rather than the root category.

public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 769, $currentDepth = 0)

if i'm not mistaking, you could probably remove this next piece of code, as i believe it is telling prestashop to default to whatever your home category is if the category id is set at "null".

if (is_null($id_category))
			$id_category = $this->context->shop->getCategory();

honestly though, i don't really know what i'm doing, so maybe i'll just leave it there.  
even though i got it functioning as i wanted, please let me know if there's any issues with the way i edited things to make it work. i don't know php very well and i'm kinda just making it up as i go along.

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

  • 1 month later...
  • 1 year later...
  • 4 months later...
  • 3 years 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...