Jump to content

Show categories or sub-categories in format list with number of products inside [module]


Recommended Posts

Hi for all,

 

I search a module like this image.

 

 

Show all categories or subcategories in the category page.

 

Any solution?

 

 

Thanks in advance.

You  can modify your category page to achieve this without a module.

I did it for one client.

Share this post


Link to post
Share on other sites

Thanks for reply.

 

The part of numbers? (numbers of products in this subcategory). I try to implement this but dont work =(

 

I have found in google but none work in v1.6.1.5,

 

 

Best regards.

Share this post


Link to post
Share on other sites

Take this code as an example:

<?php

  public function tree($parent=null)
					{
					global $ids;
					if ($parent == 0)
					{
					$results = Db::getInstance()->ExecuteS("SELECT c.id_parent, c.id_category, CONCAT ( REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(level_depth,1,''),2,''),3,''),4,''),5,''),6,''),cl.name) as name, cl.description, cl.link_rewrite,cs.position ,level_depth
					FROM "._DB_PREFIX_."category c
					LEFT JOIN "._DB_PREFIX_."category_lang cl ON (c.id_category = cl.id_category AND id_lang = '1')
					LEFT JOIN "._DB_PREFIX_."category_group cg ON (cg.`id_category` = c.id_category)
					LEFT JOIN `"._DB_PREFIX_."category_shop` cs ON (c.`id_category` = cs.`id_category` )
					WHERE c.id_category <> '1'  
					GROUP BY c.id_category
					ORDER BY c.`id_parent` ASC,level_depth ASC");
						foreach ($results as $row)
						{
							if (!in_array($row['id_category'], $ids))
							{
							echo '<li id="'.$row['id_category'].'">'.$row['name'].'</br></br>';
							array_push($ids, $row['id_category']);
							$this->tree($row['id_category']);
							}
						}
					
					} else {
						
					$results = Db::getInstance()->ExecuteS("SELECT c.id_parent, c.id_category, CONCAT ( REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(level_depth,1,''),2,''),3,''),4,''),5,''),6,''),cl.name) as name, cl.description, cl.link_rewrite,cs.position ,level_depth
					FROM "._DB_PREFIX_."category c
					LEFT JOIN "._DB_PREFIX_."category_lang cl ON (c.id_category = cl.id_category AND id_lang = '1')
					LEFT JOIN "._DB_PREFIX_."category_group cg ON (cg.`id_category` = c.id_category)
					LEFT JOIN `"._DB_PREFIX_."category_shop` cs ON (c.`id_category` = cs.`id_category` )
					WHERE c.id_category <> '1'
					AND c.id_parent = '".$parent."'
					GROUP BY c.id_category
					ORDER BY cs.position ASC,c.`id_parent` ASC,level_depth ASC");
						if (!empty($results) > 0)
						{
						echo '<ul>';
						$i = 0;
						$len = count($results);
						foreach ($results as $row)
						{
							if (!in_array($row['id_category'], $ids))
							{
							echo '<li id="'.$row['id_category'].'">'.$row['name'].'</br></br>';
							array_push($ids, $row['id_category']);
							$this->tree($row['id_category']);
							}
							
							if ($i == $len - 1) {
							echo '</ul></li>';
							}
							$i++;
						}	
						
						} else {
							
						echo '</li>';
							
						}
						
					}
					
					}

Share this post


Link to post
Share on other sites

Good morning,

 

I amb using the theme modules, and tthe option that show the subcategories is enabled, only image, name and description, but not number of products.

 

 

Thanks.

Share this post


Link to post
Share on other sites

Hi,

 
I could solve this issue!
 
1. Editing the 651 line (getSubCategories() function) in /classes/Category.php file, add (SELECT count(*) FROM `'._DB_PREFIX_.'product` WHERE id_category_default=c.id_category) AS count

 

2. Add in 413 line of category.tpl of theme ({$subcategory.count})

 

 

Thanks!

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More