Jump to content

(SOLVED) Sub Categories Number


Recommended Posts

When you click on a main category that has sub categories it returns in the centre of the page the main cat at the top in my case "candles" and because I have placed 4 products from sub categories in the main category "candles" it has a 4 next to it and then showcases these 4 products under the sub cat list, so I am using the main cat as a kin of a showcase rather like featured products etc (see image) Ok the problem is that they way it is at present it looks as if there are only "4" products in total in the candles section when in fact there are loads in the sub categories. So is there a way of

1) removing the "4" next to the main cat titles
2) including numbers next to each sub cat item

I have removed the default no image pics and replaced with a pixel, this is not ideal as there are massive gaps, but I can't seem to find a work around. Is there a category featured product module anywhere perhaps.

Many thanks
Paul

22910_U8eowg4rTLSvr9sgLzeA_t

Link to comment
Share on other sites

To remove the number of products on the category page, you'll need to edit category.tpl in your theme's directory. In Prestashop v1.2.5, {* comment out *} line 7:

{$nb_products|intval} {if $nb_products>1}{l s='products'}{else}{l s='product'}{/if}



To put the number of products next to each subcategory is more difficult, since only the number of products for the current category is passed in from category.php. To pass in all the number of the products in the subcategories, you'll need to add the following code after line 50 in category.php (in Prestashop v1.2.5):

if (is_array($subCategories))
   for ($i = 0; $i < sizeof($subCategories); $i++)
   {
       $subCategory = new Category($subCategories[$i]['id_category']);
       $subCategories[$i]['nbProducts'] = $subCategory->getProducts(NULL, NULL, NULL, $orderBy, $orderWay, true);
   }



then you can change line 38 of category.tpl (in Prestashop v1.2.5) from:

<a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}">{$subcategory.name|escape:'htmlall':'UTF-8'}



to:

<a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}">{$subcategory.name|escape:'htmlall':'UTF-8'} ({$subcategory.nbProducts})

Link to comment
Share on other sites

I got the first part working but the second part leaves a line of faults (see screenshot) heres what the code looks like when I added to just below line 50

                $category->name = Category::hideCategoryPosition($category->name);
               $category->description = nl2br2($category->description);
               $subCategories = $category->getSubCategories(intval($cookie->id_lang));
                if (is_array($subCategories))
   for ($i = 0; $i < sizeof($subCategories); $i++)
   {
       $subCategory = new Category($subCategories[$i]['id_category']);
       $subCategories[$i]['nbProducts'] = $subCategory->getProducts(NULL, NULL, NULL, $orderBy, $orderWay, true);
   }

               $smarty->assign('category', $category);
               if (Db::getInstance()->numRows())

23006_yFeAz7Exz6AsSQUEet22_t

Link to comment
Share on other sites

The forum deleted part of my code, which is why you are having that problem. I've updated my code above for category.tpl in a way so that the forum won't delete it. Please try copying it again.

Link to comment
Share on other sites

Thanks all sorted and working fine, one last thing on this, how do I get rid of the images altogether so that I haven't got a massive gap between each cat, so that each cat lines up one under the other so to speak

Thanks again Paul

Link to comment
Share on other sites

Add the following to the "body#category #subcategories li" block in the /* category.tpl */ section of global.css:

width: 100px;



This will create 100px columns of categories. You can adjust the number until you are happy with the way it looks.

To remove the subcategory images, {* comment out *} the following code on lines 14-18 of category.tpl:

{else}
   <!-- Category image -->
   {if $category->id_image}
       <img src="{$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category')}" alt="{$category->name|escape:'htmlall':'UTF-8'}" title="{$category->name|escape:'htmlall':'UTF-8'}" id="categoryImage" />
   {/if}

Link to comment
Share on other sites

That didn't seem to make a difference heres what I commented out

        {include file=$tpl_dir./scenes.tpl scenes=$scenes}
       {* {else}
                <!-- Category image -->
               {if $category->id_image}
getCatImageLink($category->link_rewrite, $category->id_image, 'category')}" alt="{$category->name|escape:'htmlall':'UTF-8'}" title="{$category->name|escape:'htmlall':'UTF-8'}" id="categoryImage" />
               {/if}*}



Actually what would perhaps be better would be to make the defualt no cat image (that I replaced with a pixel image) much smaller (at present it still takes up the size of the defualt one) that way if I have a few sub cats elsewhere I can have the option to include images, if you image is present it shows the pixel but much smaller. Is this controlled in the css file

Link to comment
Share on other sites

  • 3 months later...

Hi Rocky,

Your solution worked great but the only problem after I applied it is that when a category for example Chairs has many subcategories in it, the product number next to Chairs will be (0).

Only when you click on chairs you see the subcategories for example metal, wood, plastic with the product numbers inside.

It makes it a bit confusing as people think there is no products in the Chairs category ?

Any fix available for this or I should just remove the products number completely ? Last solution would kind of make me feel sad, as I felt this was a great add-on.

Thanks for any help you can give!

Link to comment
Share on other sites

To count subcategories, sub-subcategories, etc would be much more difficult. I suggest that you put your metal, wood and plastic products in the chairs category too instead of having no products in that category, or remove the products numbers.

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