News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Show number of products in a category.

Started by bmw2182, May 03, 2012, 17:36:30 PM

Previous topic - Next topic

Scargo

Quote from: bytelord on August 08, 2012, 21:29:09 PM
Hello miriame,

Is working. I test it again on VM default template com_virtuemart\views\category\tmpl\default.php.
Be sure that you have place these two lines of code after line 106 (<?php echo $category->category_name ?>) and before </br>. The two lines:

<?php $categoryModelkaraokeVmModel::getModel('category');
echo 
$categoryModelkaraoke->countProducts($category->virtuemart_category_id ); ?>


All the children categories shows correctly the number of products beside name e.g. Children Category1 20 Children Category2 10, etc.

This code above is for category view!

Also you can place that two lines of code in default_categories.php under VM frontpage template (com_virtuemart\views\virtuemart\tmpl\default_categories.php) after line 57 and also works great if you want your master categories shows that number of products (not for children categories product number).

If you want it for category module (mod_virtuemart_category) just let me know!

Thanks. Hope it helps you out.

Regards,

BL
Quote from: bytelord on August 08, 2012, 21:29:09 PM
Hello miriame,

Is working. I test it again on VM default template com_virtuemart\views\category\tmpl\default.php.
Be sure that you have place these two lines of code after line 106 (<?php echo $category->category_name ?>) and before </br>. The two lines:

<?php $categoryModelkaraokeVmModel::getModel('category');
echo 
$categoryModelkaraoke->countProducts($category->virtuemart_category_id ); ?>


All the children categories shows correctly the number of products beside name e.g. Children Category1 20 Children Category2 10, etc.

This code above is for category view!

Also you can place that two lines of code in default_categories.php under VM frontpage template (com_virtuemart\views\virtuemart\tmpl\default_categories.php) after line 57 and also works great if you want your master categories shows that number of products (not for children categories product number).

If you want it for category module (mod_virtuemart_category) just let me know!

Thanks. Hope it helps you out.

Regards,

BL

Hy All!
I reading and reading... :D But my english ... not good :D
So. If i understand this topic, Bytelord make a code. This code can count product in categories and show on categori page. It's ok, but a can't understand, how can i use it on category module ( this link: http://gsmmuzeum.hu/gsmnew/index.php?option=com_virtuemart&view=categories&virtuemart_category_id=0&Itemid=104 left side Telefonok: Alcatel, Benefon, etc ) How can i show the product number here? If the ansver is here, sorry, i can't understand evrythig :D just learning english :D

Best regards from Hungary. Scargo
Joomla 2.5; Virtuemart  2.0.18a
The old: gsmmuzeum.hu
The under construction: gsmmuzeum.hu/gsmnew/

Scargo

Up...

So, does anyone know how I can display the products number in category module?

Thx.

Scargo
Joomla 2.5; Virtuemart  2.0.18a
The old: gsmmuzeum.hu
The under construction: gsmmuzeum.hu/gsmnew/

balai


Scargo

Thx Balai!
It'a  good idea. But i can't use the sub categories with this... :(  Seeking further....
Joomla 2.5; Virtuemart  2.0.18a
The old: gsmmuzeum.hu
The under construction: gsmmuzeum.hu/gsmnew/

balai

Quote from: Scargo on February 05, 2013, 16:26:49 PM
Thx Balai!
It'a  good idea. But i can't use the sub categories with this... :(  Seeking further....

What you mean? It offers a foldable category tree in unlimited depth.
If you want to have the parent categories as links, its in the PRO version

Scargo

Quote from: balai on February 05, 2013, 16:38:35 PM
Quote from: Scargo on February 05, 2013, 16:26:49 PM
Thx Balai!
It'a  good idea. But i can't use the sub categories with this... :(  Seeking further....

What you mean? It offers a foldable category tree in unlimited depth.
If you want to have the parent categories as links, its in the PRO version

It's ok, but my financial situation allows just the free versions now. It's not problem. This site the just for fun category. I think it's will be great with simple solutins.
Thanks for your help, i saved it for the future use.

(sorry for my english - google translate :) )
Joomla 2.5; Virtuemart  2.0.18a
The old: gsmmuzeum.hu
The under construction: gsmmuzeum.hu/gsmnew/

turkish74

Hi all

Will this solution also work for the category module? I looked in the files for the module but couldnt find any place where i could place the code.

Cheers

lostmail

Quote from: bytelord on August 08, 2012, 21:29:09 PM
Hello miriame,

Is working. I test it again on VM default template com_virtuemart\views\category\tmpl\default.php.
Be sure that you have place these two lines of code after line 106 (<?php echo $category->category_name ?>) and before </br>. The two lines:

<?php $categoryModelkaraokeVmModel::getModel('category');
echo 
$categoryModelkaraoke->countProducts($category->virtuemart_category_id ); ?>


All the children categories shows correctly the number of products beside name e.g. Children Category1 20 Children Category2 10, etc.

This code above is for category view!

Also you can place that two lines of code in default_categories.php under VM frontpage template (com_virtuemart\views\virtuemart\tmpl\default_categories.php) after line 57 and also works great if you want your master categories shows that number of products (not for children categories product number).

If you want it for category module (mod_virtuemart_category) just let me know!

Thanks. Hope it helps you out.

Regards,

BL


YESSS - Please:
"If you want it for category module (mod_virtuemart_category) just let me know!"

We need the code for category module ;-)
Joomla 3.x | VirtueMart 4.0.12 107771 | HORME3 PRO 1.9.6 / 2.0
VirtueMart 4.2.4 | Joomla 4.4.1 | PHP 8.1 | Vp_neoteric 1.3

lostmail

Quote from: encreplus on December 17, 2012, 21:10:54 PM
Ok will try to be more precise ...

I have caterogies build that way : 

Main  -- Inkjet (0)
Sub Main -- Brother (0)
Sub Brother -- MFC series (0)
Sub MFC series -- MFC 240 (4)

For the product count i have a number only on MFC-240 category ... all the other 3 up level i have 0 ...

Is it clear that way ??
Same Problem here....
using the override from webnuts...http://www.web-nut.de/webnut-blog/geschreibsel/16-virtuemart-2-category-module-modifizieren.html#.UaxnEpzdXRY

Any suggestion hot to modify the code so that ALL products in Main Category is visible (including products from Sub-Categories) ?
Joomla 3.x | VirtueMart 4.0.12 107771 | HORME3 PRO 1.9.6 / 2.0
VirtueMart 4.2.4 | Joomla 4.4.1 | PHP 8.1 | Vp_neoteric 1.3

Siberex


dirk66

Here is what i did to change the mod_virtuemart_category to show the number of products in the category. It is not perfect because it doesn't count the total number of products in the child categories yet
Maybe someone can help me out with that. Anyway, this should be a standard feature in VM, in my opinion.

First of all copy the file in /modules/mod_virtuemart_category/tmpl/default.php to /templates/*your template name*/mod_virtuemart_category/default.php to make an override, if it is not allready there.

Then edit the file and search for "$cattext = $category->category_name;" and replace it with "$cattext = $category->category_name. ' ('.$categoryModel->countProducts($category->virtuemart_category_id ).')';"

then search for "$cattext = $child->category_name;" and replace it with "$cattext = $child->category_name. ' ('.$categoryModel->countProducts($child->virtuemart_category_id ).')';"

Save the file and that's it, the number of products will show up next to the category name between brackets.

dirk66

ok, this is how i solved the problem showing the total number of product in a category with child categories (use the same file as explained in my previous post):

<?php foreach ($categories as $category) {
       $active_menu = 'class="VmClose"';
      $caturl = JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$category->virtuemart_category_id);
            $cattotal = 0;
      foreach ($category->childs as $child) {

      $cattotal = $cattotal + $categoryModel->countProducts($child->virtuemart_category_id );}
      //$cattext = $category->category_name. ' ('.$categoryModel->countProducts($category->virtuemart_category_id ).')';
      $cattext = $category->category_name. ' ('.$cattotal.')';
      //if ($active_category_id == $category->virtuemart_category_id) $active_menu = 'class="active"';
      if (in_array( $category->virtuemart_category_id, $parentCategories)) $active_menu = 'class="VmOpen"';

      ?>

i hope this helps.

encreplus

How can i do this in com_virtuemart/category/default.php ???

Stefan

encreplus

Im using this code but it counts only products in the category not all subcategories ...

<h2 class="cat-product-title">
                     <a href="<?php echo $caturl ?>" title="<?php echo $category->category_name ?>">
                     <?php echo $category->category_name.' ('.$categoryModel->countProducts($category->virtuemart_category_id).')'; ?>
                     </a>
                     
                </h2>

How can i count products in subcategories also ...

encreplus

any news on this ?

Im using this code but it counts only products in the category not all subcategories ...

<h2 class="cat-product-title">
                     <a href="<?php echo $caturl ?>" title="<?php echo $category->category_name ?>">
                     <?php echo $category->category_name.' ('.$categoryModel->countProducts($category->virtuemart_category_id).')'; ?>
                     </a>
                     
                </h2>

How can i count products in subcategories also ...