Jump to content

Hide categories that all products are out of stock


crbwi

Recommended Posts

Hello:-D, I have a question, need to hide the categories that all products are out of stock ( 0 stock), Is it possible to do that automatically? not want to disable the categories because google can not access, I just want to hide.

 I've found a way to hide products with 0 stock, but not the categories.
 

Thanks :-D

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

in this case it is necessary to hide categories links, the questions is: where you've got these links? blockcategories ? top horizontal menu? it will not be as easy as it seems, unfortunately :(

 

in my case I need to hide in the blockcategories, my version of prestashop is the 1.4

 

I hope someone can help :rolleyes:

Link to comment
Share on other sites

ok, here is the solution:

 

open file: /modules/blockcategories/category-tree-branch.tpl paste there this code: 

{if $node.productsCount > 0}
<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>
{/if}

and then, open: /modules/blockcategories/blockcategories.php

 

instead of this:

	public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0)
	{
		global $link;

		$children = array();
		if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $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;z
		return array('id' => $id_category, 'link' => $link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']),
					 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'],
					 'children' => $children);
	}

use:

	public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0)
	{
		global $link;

		$children = array();
		if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $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;
        $productsCount = (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'category_product WHERE id_category = '. $id_category);
		return array('id' => $id_category, 'link' => $link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']),
					 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'],
					 'children' => $children,  'productsCount'=>$productsCount);
	}
  • Like 1
Link to comment
Share on other sites

Hello, thank you very much for your answer :rolleyes: :rolleyes:

 

 

 

ok, here is the solution:

 

open file: /modules/blockcategories/category-tree-branch.tpl paste there this code: 

{if $node.productsCount > 0}
<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>
{/if}

and then, open: /modules/blockcategories/blockcategories.php

 

instead of this:

	public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0)
	{
		global $link;

		$children = array();
		if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $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;z
		return array('id' => $id_category, 'link' => $link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']),
					 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'],
					 'children' => $children);
	}

use:

	public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0)
	{
		global $link;

		$children = array();
		if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $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;
        $productsCount = (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'category_product WHERE id_category = '. $id_category);
		return array('id' => $id_category, 'link' => $link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']),
					 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'],
					 'children' => $children,  'productsCount'=>$productsCount);
	}

 

In this method duplicates the categories :wacko: . And not hide empty categories, O_O why that may be?, Ahh, the counter does not appear.

 

 

And in this way I get the counter products but not display the subcategories. :huh: :huh:
 

 

Attached are my two unchanged files so you can see them.

Greetings and many thanks for helping
:) :)

blockcategories.zip

Link to comment
Share on other sites

 

 

And in this way I get the counter products but not display the subcategories. :huh: :huh:

 

Solution is easy. You must go to the back office, when you create new product or editing existing one check in category tree all categories and subcategories where this product belong.

 

Like this:

 

Category 1

--Subcategory 1

----Product 1

----Product 2

--Subcategory 2

Category 2

Category 3

 

In this case PRODUCT 1 belongs to Subcategory 1 and Category 1 and you must check both in category tree.

 

pu9t.jpg

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

Solution is easy. You must go to the back office, when you create new product or editing existing one check in category tree all categories and subcategories where this product belong.

 

Like this:

 

Category 1

--Subcategory 1

----Product 1

----Product 2

--Subcategory 2

Category 2

Category 3

 

In this case PRODUCT 1 belongs to Subcategory 1 and Category 1 and you must check both in category tree.

 

pu9t.jpg

What? I do not understand. What this does is show the products in all categories. not?

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