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

bmw2182

I have recently installed Virtuemart 2.0.4 on Joomla 2.5.  There used to be an option to show the number of products in a category, but I'm not finding that anywhere.  Is that still an option and if so where will I find it?

Thanks so much in advance.

Dee

karaoke

I have the same question.

How can I display the number of products in a category in categories view?

bytelord

Hello,

For affecting all categories in category view please go to BE-> Configuration -> Shopfront and change the "Max products per view in frontend" with the number you want.
To change the number of products or categories per row go to BE-> Configuration -> Templates and change the "Default number of categories in a row", "default number of products in a row".
If you want to change it only for a specific category then go to the category you want and you can find there the option " Default Number of Products per Row" and other options for the number of products.

If you mean to show the actual number of products as a number this is done by vmPagination inside template category which displays the number of products in the page of total in the category.

Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

karaoke

Quote from: bytelord on August 07, 2012, 12:31:05 PM

If you mean to show the actual number of products as a number this is done by vmPagination inside template category which displays the number of products in the page of total in the category.



Hi,

Yes, that's what I exactly mean. Let's say I have 3 categories : Bags , Shoes and Shirts . In the categories view I would like to have the total number of products in each category beside the name of the category . For example :

Bags(28) - Shoes(34) - Shirts(118)

The numbers in parentheses indicates how many products exists in each category . In the example above there are 28 products in Bags category.

How can I achieve this?


Thank you

bytelord

#4
Hello,

Because i use my own custom template i work around a little bit and find a solution for you.

In the category template (default.php) around line 106 (vm default template) in your custom template you can place the following code that uses the category model of VM models. I suggest you that solution so there is no need to override core files.

$categoryModelkaraoke= VmModel::getModel('category');
  echo $categoryModelkaraoke->countProducts($this->category->virtuemart_category_id );


The first line assign the model and the second one echo the products number for the category. You can work around and place that code where you need it, you can use some html/css to style it as you wish, like place "(", color, size, etc.
$categoryModelkaraoke --> use a variable  as you wish, like $CatModc

This code snippet is for category-view.

Hope helps you out and may helps some other users that need it.

If that solution works for you please mark the thread as solved. Also this thread should be under Templating & Layouts. Please correct it.

Best Regards,

BL
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

karaoke

Thank you so much, Bytelord. I'll give it a try and let you know :)

karaoke

Hi,

I added the code to line 106 of category/tmpl/default.php but it's not working properly and doesn't count the products. After adding the code a Zero(0) is displayed beside the category names :

Shoes 0 - Bags 0 - Shirts 0


Lines 106-108 of default.php are like this :

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



Any idea?

bytelord

#7
Hello,

My apologies, i had test the code for the current category and no children categories! :)

Please inside category/default.php in your template after the following line (where the subcategories are print-out)

<?php echo $category->category_name ?>


add the following code:

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


i test it and works great for all subcategories.

Thank you

Regards,

Bytelord
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

miriame

Hello
I have try your suggestion onto Virtuemart 2.0.8e but it don't work :(
Any idea??

Thank you Miriam

bytelord

#9
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
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

karaoke

The code worked just fine. Thank you so much BL:)

bytelord

Hello karaoke,


That's nice.  i'm glad it helps! :)


don't forget to mark your thread as solved.


Regards,
BL
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

miriame

Hello bytelord Thank you very much for your hrlp.
I have made the changes onto Virtuemart 2.0.10 and it's work fine.

Thank you very much  :D

kanbosk

Hi bytelord,

Thanks but the code didn't work for me. Any help will be appreciated.

bytelord

Hello,

Is working vm2012f also. You should placed that code after line 111, after the <?php echo $category->category_name ?>

But please make a template override for that and do not edit the vm default theme because after a vm upgrade you will the changes.
to make a template override just copy the file joomla_folder\com_virtuemart\views\category\tmpl\default.php to joomla_folder/template/your_joomla_template/html/com_virtuemart/category/default.php
but, did you use already template overrides so you should edit the file joomla_folder/template/your_joomla_template/html/com_virtuemart/category/default.php that already exists???

The actual code for Children categories:

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


The above will return Chrilder_category name (x_number_of_products)

Some more information regarding templates:

template overrides: http://forum.virtuemart.net/index.php?topic=98505.0
Using the template system: http://dev.virtuemart.net/projects/virtuemart/wiki/Hints_for_the_use_of_the_template_system.

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!