News:

Support the VirtueMart project and become a member

Main Menu

Show number of products in a category.

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

Previous topic - Next topic

kanbosk

Hi bytelord,

Thanks its started to work but its returning (0) products for all the subcats whereby there are products under them Help please. Thanks

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!

kanbosk

Hi Bytelord

Thanks I have just figured it out that it is working but the count is not right. You can see it at http://www.myghanashop.com/index.php/4/cars

See BMW says 8 products but its actually 9. Is it counting the products by vendor? Also the food category has 1 product under Fruits and vegetables but it says 0. This is at http://www.myghanashop.com/index.php/3/food

Thanks


bytelord

hello,

works for me ... you are using a commercial template but should work also, i think is not counted products with 0price ... am i right?

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!

kanbosk

Thanks for figuring that out but am not sure. Will check and get back to you. Thanks

bytelord

may be that products assigned to other subcategory?

The countProducts function works fine .. do you use multivendor?

public function countProducts($cat_id=0) {

      if(!empty($this->_db))$this->_db = JFactory::getDBO();
      $vendorId = 1;
      if ($cat_id > 0) {
         $q = 'SELECT count(#__virtuemart_products.virtuemart_product_id) AS total
         FROM `#__virtuemart_products`, `#__virtuemart_product_categories`
         WHERE `#__virtuemart_products`.`virtuemart_vendor_id` = "'.(int)$vendorId.'"
         AND `#__virtuemart_product_categories`.`virtuemart_category_id` = '.(int)$cat_id.'
         AND `#__virtuemart_products`.`virtuemart_product_id` = `#__virtuemart_product_categories`.`virtuemart_product_id`
         AND `#__virtuemart_products`.`published` = "1" ';
         $this->_db->setQuery($q);
         $count = $this->_db->loadResult();
      } else $count=0 ;

      return $count;
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!

kanbosk

Yes I use multivendor called vm vendor. What should I do with that code and where should I put it? Also am not sure why my product prices aren't showing at all. Any extra help please?

bytelord

#22
hm,

You could change that function query load to select multivendor ... but i am afraid maybe other issues will be caused ... so i am not aware at the moment what issues could that create ...

try to play around with the following function that is located under joomla_folder\administrator\components\com_virtuemart\helpers\shopfunctions.php ... but this is a core hack and i am not suggested to change it because may be have side effects and your shop does not work properly after. I think that solution works only for one vendor at the moment and multivendor is under development.

public function countProducts($cat_id=0) {

      if(!empty($this->_db))$this->_db = JFactory::getDBO();
      $vendorId = 1;
      if ($cat_id > 0) {
         $q = 'SELECT count(#__virtuemart_products.virtuemart_product_id) AS total
         FROM `#__virtuemart_products`, `#__virtuemart_product_categories`
         WHERE `#__virtuemart_products`.`virtuemart_vendor_id` = "'.(int)$vendorId.'"
         AND `#__virtuemart_product_categories`.`virtuemart_category_id` = '.(int)$cat_id.'
         AND `#__virtuemart_products`.`virtuemart_product_id` = `#__virtuemart_product_categories`.`virtuemart_product_id`
         AND `#__virtuemart_products`.`published` = "1" ';
         $this->_db->setQuery($q);
         $count = $this->_db->loadResult();
      } else $count=0 ;

      return $count;
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!

kanbosk

Hi bytelord,
Many thanks for your generous support. I have used an alternative but you have opened my eyes more. Thanks

bytelord

Hello,

Great you find a solution, you could share if you like.

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!

kanbosk

Hi,
Just like you said, your solution works only for a single vendor and that is the super user, which suggests that vm only counts for products added by the super user and not other users. In order for other users products to be counted, I had to make every vendor a super user which will be stupid for me to do so. I have rather used a module which displays the categories in list form and which counts every product individually by category. I am happy with it so far. Saying so, I will be happy to revert back to the original if an update or a hack is available. Many thanks for your efforts.

bytelord

#26
Hello,

You could try to add a new function similar to the countProducts inside category model for all vendors to use it. Inside the file joomla_folder\administrator\components\com_virtuemart\models\category.php around line 375 after the coundProducts function (no matter where but easier to locate it). So please try the add following code inside models\category.php:


/**
* count the products in a category for all Vendors
*
* @author RolandD, Max Milbers, Bytelord
* @return array list of categories product is in for all vendors
*/
public function countAllVendorsProducts($cat_id=0) {

if(!empty($this->_db))$this->_db = JFactory::getDBO();
if ($cat_id > 0) {
$q = 'SELECT count(#__virtuemart_products.virtuemart_product_id) AS total
FROM `#__virtuemart_products`, `#__virtuemart_product_categories`
WHERE `#__virtuemart_product_categories`.`virtuemart_category_id` = '.(int)$cat_id.'
AND `#__virtuemart_products`.`virtuemart_product_id` = `#__virtuemart_product_categories`.`virtuemart_product_id`
AND `#__virtuemart_products`.`published` = "1" ';
$this->_db->setQuery($q);
$count = $this->_db->loadResult();
} else $count=0 ;

return $count;
}


After that inside your category default template you will use the following code:

<?php $categoryModelVmModel::getModel('category');
           echo 
'('.$categoryModel->countAllVendorsProducts($category->virtuemart_category_id ).')'?>


I haven't test it but you could test and please report if is working...

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!

kanbosk

Hi bytelord,
You have solved my biggest problem. Your solution worked very good. You can check on my site. Every product is counted by your hack and it is just how I wanted it. I don't know how to thank you. You are very good and helpful. Wish everyone was like you. I did a template override as well so hopefully no update will mess it up. Thank you very much!!!

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!

kanbosk

Hi bytelord,
Sorry to bother you again but I thought I did a template override, not sure what happened but the new VM update messed the hack up so its not working anymore.  I know am asking too much but if you have some spare time, can you please look into the hack to show all vendor products count in VM update 2.0.14. Thanks