From a35f4a536e8c437f2f43759f4109cec5cf967483 Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer <reinhold@kainhofer.com> Date: Sun, 25 Oct 2015 21:06:12 +0100 Subject: [PATCH] Forward port of V5.7: Add variables MinQuantity and MaxQuantity --- library/rules_shipping_framework.php | 7 ++++++- rules_shipping_framework_joomla.php | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/library/rules_shipping_framework.php b/library/rules_shipping_framework.php index 42ad51c..0107373 100644 --- a/library/rules_shipping_framework.php +++ b/library/rules_shipping_framework.php @@ -210,7 +210,12 @@ class RulesShippingFramework { */ /** Functions to calculate all the different variables for the given cart and given (sub)set of products in the cart */ protected function getOrderCounts ($cart, $products, $method) { - return array('articles' => 0, 'products' => count($products)); + return array( + 'articles' => 0, + 'products' => count($products), + 'minquantity' => 9999999999, + 'maxquantity' => 0, + ); } protected function getOrderDimensions ($cart, $products, $method) { diff --git a/rules_shipping_framework_joomla.php b/rules_shipping_framework_joomla.php index d812dee..0c7f75c 100644 --- a/rules_shipping_framework_joomla.php +++ b/rules_shipping_framework_joomla.php @@ -98,13 +98,21 @@ class RulesShippingFrameworkJoomla extends RulesShippingFramework { * - getOrderDimensions */ /** Functions to calculate all the different variables for the given cart and given (sub)set of products in the cart */ - protected function getOrderCounts ($cart, $products, $method) { - $counts = array('products' => count($products)); - $articles = 0; + protected function getOrderCounts (VirtueMartCart $cart, $products, $method) { + $counts = array( + 'articles' => 0, + 'products' => count($products), + 'minquantity' => 9999999999, + 'maxquantity' => 0, + ); + foreach ($products as $product) { - $articles += $product->quantity; + $counts['articles'] += $product->quantity; + $counts['maxquantity'] = max ($counts['maxquantity'], $product->quantity); + $counts['minquantity'] = min ($counts['minquantity'], $product->quantity); } - $counts['articles'] = $articles; + $counts['quantity'] = $counts['articles']; + return $counts; } -- GitLab