Author Topic: Show number of products in a category.  (Read 25759 times)

bmw2182

  • Jr. Member
  • **
  • Posts: 82
Show number of products in a category.
« on: May 03, 2012, 17:36:30 pm »
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

  • Beginner
  • *
  • Posts: 28
Re: Show number of products in a category.
« Reply #1 on: August 07, 2012, 06:09:27 am »
I have the same question.

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

bytelord

  • Nikos
  • Global Moderator
  • Hero Member
  • *
  • Posts: 2369
Re: Show number of products in a category.
« Reply #2 on: August 07, 2012, 12:31:05 pm »
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

  • Beginner
  • *
  • Posts: 28
Re: Show number of products in a category.
« Reply #3 on: August 07, 2012, 15:51:47 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

  • Nikos
  • Global Moderator
  • Hero Member
  • *
  • Posts: 2369
Re: Show number of products in a category.
« Reply #4 on: August 07, 2012, 16:46:27 pm »
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.

Code: [Select]
$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

  • Beginner
  • *
  • Posts: 28
Re: Show number of products in a category.
« Reply #5 on: August 07, 2012, 20:49:39 pm »
Thank you so much, Bytelord. I'll give it a try and let you know :)

karaoke

  • Beginner
  • *
  • Posts: 28
Re: Show number of products in a category.
« Reply #6 on: August 08, 2012, 08:30:51 am »
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 :

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


Any idea?

bytelord

  • Nikos
  • Global Moderator
  • Hero Member
  • *
  • Posts: 2369
Re: Show number of products in a category.
« Reply #7 on: August 08, 2012, 13:41:44 pm »
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)

Code: [Select]
<?php echo $category->category_name ?>

add the following code:

   
Code: [Select]
<?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

  • Beginner
  • *
  • Posts: 13
    • Usato & Co
Re: Show number of products in a category.
« Reply #8 on: August 08, 2012, 21:03:43 pm »
Hello
I have try your suggestion onto Virtuemart 2.0.8e but it don't work :(
Any idea??

Thank you Miriam

bytelord

  • Nikos
  • Global Moderator
  • Hero Member
  • *
  • Posts: 2369
Re: Show number of products in a category.
« Reply #9 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:

Code: [Select]
<?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

  • Beginner
  • *
  • Posts: 28
Re: Show number of products in a category.
« Reply #10 on: August 09, 2012, 16:57:36 pm »
The code worked just fine. Thank you so much BL:)

bytelord

  • Nikos
  • Global Moderator
  • Hero Member
  • *
  • Posts: 2369
Re: Show number of products in a category.
« Reply #11 on: August 09, 2012, 17:06:41 pm »
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

  • Beginner
  • *
  • Posts: 13
    • Usato & Co
Re: Show number of products in a category.
« Reply #12 on: September 21, 2012, 13:40:44 pm »
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

  • Beginner
  • *
  • Posts: 12
Re: Show number of products in a category.
« Reply #13 on: November 02, 2012, 14:12:45 pm »
Hi bytelord,

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

bytelord

  • Nikos
  • Global Moderator
  • Hero Member
  • *
  • Posts: 2369
Re: Show number of products in a category.
« Reply #14 on: November 02, 2012, 14:35:28 pm »
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:

Code: [Select]
<?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!