Jump to content

Nombre des produits dans une sous catégorie


Recommended Posts

Bonjour,

il n'existe pas de module, c'est un développement spécifique.

Mais je crois qu'en cherchant sur le forum vous pourrez trouver une explication pour ajouter le nombre de produit d'une catégorie dans le menu.

Link to comment
Share on other sites

  • 1 year later...

Si ça peut aider ! Test sous Prestashop 1.4.5.1

 

Dans modules/blockcategories/blockcategories.php

 

Dans : public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0)

 

Trouvez :

 

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

 

 

Remplacez le code par celui-ci :

 


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, 'product_count' => $resultIds[$id_category]['product_count']);

 

 

 

Dans : public function hookLeftColumn($params)

 

Trouvez la boucle :

 

foreach ($result as &$row)

{

$resultParents[$row['id_parent']][] = &$row;

$resultIds[$row['id_category']] = &$row;

}

 

 

Remplacez la par celle-ci :

 


		foreach ($result as &$row)
		{
			if($row['id_category'] != 1)
			{
			$result_product_count = Db::getInstance()->ExecuteS('
			SELECT COUNT(ac.`id_product`) as totalProducts
			FROM `'._DB_PREFIX_.'category_product` ac
			LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = ac.`id_product`
			WHERE ac.`id_category` = '.$row['id_category'].' AND p.`active` = 1');
			$row['product_count'] = $result_product_count[0]['totalProducts'];
			}
			$resultParents[$row['id_parent']][] = &$row;
			$resultIds[$row['id_category']] = &$row;
		}

 

 

 

 

Dans themes/votre_theme/category-tree-branch.tpl

 

Rajouter ceci :

({$node.product_count})

 

après le lien :

<a href="{$node.link|escape:'htmlall':'UTF-8'}" {if isset($currentCategoryId) && $node.id == $currentCategoryId}class="selected"{/if} title="{$node.desc|escape:'htmlall':'UTF-8'}">{$node.name|escape:'htmlall':'UTF-8'}</a>

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