Commit 237f155d authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

V5.7: Add variables MinQuantity and MaxQuantity

parent f2c4bb07
......@@ -2,7 +2,7 @@ BASE=rules_shipping
BASE_ADV=rules_shipping_advanced
PLUGINTYPE=vmshipment
ZIPBASE=opentools_vm
VERSION=5.6
VERSION=5.7
PLUGINFILES=$(BASE).php $(BASE)_base.php $(BASE).script.php $(BASE).xml index.html
PLUGINFILES_ADV=$(BASE_ADV).php $(BASE)_base.php $(BASE_ADV).script.php $(BASE_ADV).xml index.html
......
......@@ -6,7 +6,7 @@
<authorUrl>http://www.open-tools.net</authorUrl>
<copyright>Copyright (C) 2013-2014, Reinhold Kainhofer</copyright>
<license>GPL v3+</license>
<version>5.6</version>
<version>5.7</version>
<description>VMSHIPMENT_RULES_DESC</description>
<files>
<filename plugin="rules_shipping">rules_shipping.php</filename>
......
......@@ -167,7 +167,7 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
}
// We need to call getCosts, because in J3 $method->rule_name and $method->cost as set in getCosts is no longer preserved.
// Instead, we simply call getCosts again, which as a side-effect sets all those members of $method.
$costs = $this->getCosts($cart,$method,$cart->cartPrices);
$costs = $this->getCosts($cart,$method,isset($cart->cartPrices)?($cart->cartPrices):array());
$values['virtuemart_order_id'] = $order['details']['BT']->virtuemart_order_id;
$values['order_number'] = $order['details']['BT']->order_number;
$values['virtuemart_shipmentmethod_id'] = $order['details']['BT']->virtuemart_shipmentmethod_id;
......@@ -175,8 +175,9 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
$values['rule_name'] = $method->rule_name;
$weights = $this->getOrderWeights ($cart, $cart->products, $method->weight_unit);
$values['order_weight'] = $weights['weight'];
$values['order_articles'] = $this->getOrderArticles ($cart, $cart->products);
$values['order_products'] = $this->getOrderProducts ($cart, $cart->products);
$counts = $this->getOrderCounts ($cart, $cart->products);
$values['order_articles'] = $counts['articles'];
$values['order_products'] = $counts['products'];
$values['shipment_weight_unit'] = $method->weight_unit;
$values['shipment_cost'] = $method->cost;
$values['tax_id'] = $method->tax_id;
......@@ -593,16 +594,22 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
}
/** Functions to calculate all the different variables for the given cart and given (sub)set of products in the cart */
protected function getOrderArticles (VirtueMartCart $cart, $products) {
$articles = 0;
protected function getOrderCounts (VirtueMartCart $cart, $products) {
$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);
}
return $articles;
}
protected function getOrderProducts (VirtueMartCart $cart, $products) {
return count($products);
$counts['quantity'] = $counts['articles'];
return $counts;
}
protected function getOrderDimensions (VirtueMartCart $cart, $products, $length_dimension) {
......@@ -808,10 +815,7 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
public function getCartValues (VirtueMartCart $cart, $products, $method, $cart_prices) {
$address = (($cart->ST == 0 || $cart->STsameAsBT == 1) ? $cart->BT : $cart->ST);
$cartvals = array_merge (
array(
'articles'=>$this->getOrderArticles($cart, $products),
'products'=>$this->getOrderProducts($cart, $products),
),
$this->getOrderCounts ($cart, $products),
// Add the prices, optionally calculated from the products subset of the cart
$this->getOrderPrices ($cart, $products, $cart_prices),
// Add 'skus', 'categories', 'vendors' variables:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment