Jump to content

How to show Product count in Category section.


Recommended Posts

I find at times I may have a visible category that currently has NO products. I don't want a customer to click on a category that is empty...(it makes them get bored and leave the site). But, I don't want to always have to go into the backend and uncheck that category to make it invisible.

Soooooo....is there a easy way to either show next to the Category Name a product count?

Example:

CATEGORIES
Shirts (0)
Pants (3)
Shoes (6)

Atleast this way a person would know not to bother clicking on a Category if its EMPTY??

It doesn't need to show inventory amounts..just if products exhist in that category and if so how many.....

Link to comment
Share on other sites

Good idea. I've added this to my categories block module as an optional feature. I've been busy lately, but I hope to finish it soon. I had to add a new SQL query to the block to get the number of products in each category, then I modified the getTree() function to display the number of products in brackets after each category.

Link to comment
Share on other sites

Hello,

Here's what you can do, this will require a little bit of modding :)

* store - the folder that is housing your prestashop installation.
* please backup your files before making any changes, just in case.

1. Open the file

store/modules/blockcategories/blockcategories.php



2. go to line 118-119 and find

$$row['name'] = Category::hideCategoryPosition($row['name']);
$resultParents[$row['id_parent']][] = $row;
$resultIds[$row['id_category']] = $row;



3. copy the below code and paste above the code found on step 2.

// exclude home category
if($row['id_category'] != 1)
{
   $result_product_count = Db::getInstance()->ExecuteS('
   SELECT COUNT(`id_product`) as totalProducts
   FROM `'._DB_PREFIX_.'category_product`
   WHERE `id_category` = '.$row['id_category']);
   $row['product_count'] = $result_product_count[0]['totalProducts'];
}



4. Now, go back up in the script to line 85-86 and find the code

return array('id' => $id_category, 'link' => $link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']),
'name' => Category::hideCategoryPosition($resultIds[$id_category]['name']), 'desc'=> $resultIds[$id_category]['description'],
'children' => $children);



5. copy the below code and replace the code found in step 4. (notice the new product_count at the end of the array)

return array('id' => $id_category, 'link' => $link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']), 'name' => Category::hideCategoryPosition($resultIds[$id_category]['name']), 'desc'=> $resultIds[$id_category]['description'], 'children' => $children, 'product_count' => $resultIds[$id_category]['product_count']);



6. Save the file and upload it to your server.

7. Open the file

store/modules/blockcategories/category-tree-branch.tpl



8. Find the code below (it should be the second line down)

{$node.name|escape:htmlall:'UTF-8'}



9. Add the below code to the end of step 8.

({$node.product_count})



It should look like this:

{$node.name|escape:htmlall:'UTF-8'} ({$node.product_count})



That should do it, if I missed a step or something doesn't work right, just post back here :)

You can see it in action on my store (I should say up and coming store haha)
http://cytech-services.com/store/

I hope this helps!

  • Like 1
Link to comment
Share on other sites

That's exactly what I am talking about! However, I just switched over to a new Block Categories Module (blockcategoriesaccordian v1.6 ) I like the the mouse over effect to open for subcategories, but still want that extra info to display. Not sure how close the code is.....to try the mode. But since its ROCKY from the post two up...maybe its my lucky day !!!!! :-)

Plus...I try not to modify to much..its a pain when upgrading to newer level of prestashop.. I always find I forget stuff :-)

Appreciate the input the storefront I am working on is http://www.ozarkclassiccraftsmall.com

Link to comment
Share on other sites

Hey Halalan,

You should still be able to do the changes in blockcategories.php - I'm assuming the accordion update was mainly for the template and not the actual source files. Make sure you back up all files that you are going to edit and try it out. If it doesn't work, simply post back here and we will figure something out :)

Just to note - when adding the actual count to the .tpl file, the important part is ({$node.product_count}), use that to place the count where you want, it should still work with the new module.

Link to comment
Share on other sites

I appreciate the info... It's something that I feel is a must for any website with lots of categories..you don't want a person to get bored on your site with empty product categories.

I still need to figure out why the new block category is still showing a little of the --- category1 those --- are hiding behind the first letters of each category(IT's BROWSER RELATED) damn Explorer8 .. Like you said its probably in the template file - but just switched to the new block last night !!

Link to comment
Share on other sites

The link to my current project site is http://www.ozarkclassiccraftsmall.com the issue is only showing up using Explorer8 if I run it in compatibility mode the dashes showing up..go away. I usually work in IE8 because most folks use it...I know techies use Firefox..but I try to use what is normal for the average John Doe !! :-)

UPDATE NOTE: That weird issue I just figured out is a THEME only issue...it doesn't show the - - under the first letters in the category block when I switch over to the standard prestashop theme in either browswer setting, So...I got my homework cut out for me..

Link to comment
Share on other sites

Hello,

Double check to make sure you didn't miss a step or remove something that wasn't supposed to be removed, also could you give me a link to your website so I can see it?

To all those who want to use this modification you can download it here:
http://www.cytech-services.com/store/product.php?id_product=14

I also updated the script so it takes into effect active products.

Please keep in mind I'm still working on the store aspect so don't be afraid if you see some weird things haha

Link to comment
Share on other sites

Nice article.Its drastically breathtaking expound owing to me.Hope this cede limn deserved appurtenant to every one.Thanks whereas sharing this overpowering one.Keep posting.All the elite whereas your budgeted posts.

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Nice addon ;)

But i have a question,
Is it possible to make it work with blockslidingcategories ?? I use that one i have looked at the code but it completely different.
Would love to have this working on this module, wel no one dead for asking so i thought i give it a shot ;)


Greats, ysco..

Link to comment
Share on other sites

Hi ysco,

I've already added this option to v2.0 of my sliding categories module, but I'm reluctant to release it since there are a few obvious bugs in it. I want to get the module perfect before I release it. Unfortunately, I've been busy working on websites for various clients, which I've found to be much easier to make a living on than writing Prestashop modules. When I get a break between websites, I'll work on finishing this module.

Rocky

Link to comment
Share on other sites

Hello rockey,

Thats great news mate, i understand dat works goes before the hobby.
So we proberly must wait a bit longer but thats no problem, is it not possible to add the code myself to my catogerieslider that i use now from you?

Thanks in advance,


Greats, Ysco..

Link to comment
Share on other sites

  • 3 months later...
  • 2 years later...
  • 9 months later...
  • 2 months later...
×
×
  • Create New...