News:

Support the VirtueMart project and become a member

Main Menu

Counter in the categories list

Started by MOdyniuk, November 21, 2012, 19:47:28 PM

Previous topic - Next topic

MOdyniuk

Hi guys.
Today came across a small but very pleasant trifle.
I have developed a module integration 1C: Enterprise + Virtuemart, but faced with the problem of counting items in categories. After analyzing the code came across the following function.

    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;
   }


It seems everything is harmless, but there is a nasty piece $vendorId = 1;

I wanted to ask: why?

If multiple vendors?

I hope no one was offended stupid question.
Thanks for answers.

bytelord

Hello,

I have the same on my mind also before some days ... i create the following function for a user that wan't to count the products. But when using multivendors all products are showed right on the front-end, but the count function is calculate only the vendor_id=1.

Take a look here: http://forum.virtuemart.net/index.php?topic=102174.msg367039#msg367039

You can test it and see if there is any issues.

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!

MOdyniuk

oh I know how to solve this problem, thanks.
I'm more interested in why so already.
What were they thinking ...

bytelord

I think because multivendor introduced in v2.0.11 ... before was experimental, so is still in development but works fine, so when that function was build vendor_id = 1 because was the only vendor...
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!

MOdyniuk

#4
Oh, sorry that the translation from the Russian phrase: "What were they thinking ..." does not convey my true emotions and true its meaning))
but in any case, thanks for the answers

bytelord

 :) np
You could create a new function for that and test it with the multivendor options is everything working ... if is working fine then the dev team will fix it...

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!