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

administrator/components/com_virtuemart/models/product.php getProducts() absMaxP

Started by GJC Web Design, November 25, 2013, 12:41:48 PM

Previous topic - Next topic

GJC Web Design

2.0.24c and probably before

in file administrator/components/com_virtuemart/models/product.php it fires the getProducts() function line 1348

Code: [Select]
public function getProducts ($productIds, $front = TRUE, $withCalc = TRUE, $onlyPublished = TRUE, $single = FALSE) {

      if (empty($productIds)) {
         //          vmdebug('getProducts has no $productIds','No ids given to get products');
         //          vmTrace('getProducts has no $productIds');
         return array();
      }

      $maxNumber = VmConfig::get ('absMaxProducts', 700);
      $products = array();
      if ($single) {

         foreach ($productIds as $id) {
            $i = 0;
            if ($product = $this->getProductSingle ((int)$id, $front)) {
               $products[] = $product;
               $i++;
            }
            if ($i > $maxNumber) {
               vmdebug ('Better not to display more than ' . $maxNumber . ' products');
               return $products;
            }
         }
      }
      else {
         $i = 0;
         foreach ($productIds as $id) {
            if ($product = $this->getProduct ((int)$id, $front, $withCalc, $onlyPublished)) {
               $products[] = $product;
               $i++;
            }
            if ($i > $maxNumber) {
               vmdebug ('Better not to display more than ' . $maxNumber . ' products');
               return $products;
            }
         }
      }

      return $products;
   }

you can see a line

$maxNumber = VmConfig::get ('absMaxProducts', 700);

this can be set in config - (don't see it) but any way as a test set to 2

$maxNumber = VmConfig::get ('absMaxProducts', 2);

no effect - all products returned

this part of the code is wrong

Code: [Select]
if ($single) {

         foreach ($productIds as $id) {
            $i = 0;
            if ($product = $this->getProductSingle ((int)$id, $front)) {
               $products[] = $product;
               $i++;
            }
            if ($i > $maxNumber) {
               vmdebug ('Better not to display more than ' . $maxNumber . ' products');
               return $products;
            }
         }
      }

the $i=0; is inside the loop so is reset to 0 every loop

if I change the code to

Code: [Select]
if ($single) {
         $i = 0;
         foreach ($productIds as $id) {
            
            if ($product = $this->getProductSingle ((int)$id, $front)) {
               $products[] = $product;
               $i++;
            }

            print 'Debug Line '.__LINE__.' $i <pre>'; print_r ($i); print "</pre><br />\n";
            if ($i > $maxNumber) {
               vmdebug ('Better not to display more than ' . $maxNumber . ' products');
               return $products;
            }
         }
      }

then the code works as intended.. now it only returns 2 products (or what ever I set $maxNumber = VmConfig::get ('absMaxProducts', 700); to
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Milbo

Ehrm, thank you very much. little typo in the other if the $i is correct.

You can set values like this  VmConfig::get ('absMaxProducts', 2); via the config fiel and the command "get values by file" in tools & migration
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

GJC Web Design

GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation