Skip to content
Snippets Groups Projects
Commit 6b752e9c authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Implement MinWeight/MaxWeight

parent 4cd62a13
Branches
Tags
No related merge requests found
<?php <?php
defined('_JEXEC') or die('Restricted access'); defined('_JEXEC') or die('Restricted access');
/**
* Installation script for the plugin
*
* @copyright Copyright (C) 2013 Reinhold Kainhofer, office@open-tools.net
* @license GPL v3+, http://www.gnu.org/copyleft/gpl.html
*/
class plgVmShipmentRules_ShippingInstallerScript class plgVmShipmentRules_ShippingInstallerScript
{ {
......
...@@ -8,7 +8,7 @@ defined ('_JEXEC') or die('Restricted access'); ...@@ -8,7 +8,7 @@ defined ('_JEXEC') or die('Restricted access');
* *
* @package VirtueMart * @package VirtueMart
* @subpackage Plugins - shipment. * @subpackage Plugins - shipment.
* @copyright Copyright (C) 2013 Reinhold Kainhofer, office@open-tools.n.et * @copyright Copyright (C) 2013 Reinhold Kainhofer, office@open-tools.net
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant * VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or * to the GNU General Public License, and as distributed it includes or
......
<?php <?php
defined('_JEXEC') or die('Restricted access'); defined('_JEXEC') or die('Restricted access');
/**
* Installation script for the plugin
*
* @copyright Copyright (C) 2013 Reinhold Kainhofer, office@open-tools.net
* @license GPL v3+, http://www.gnu.org/copyleft/gpl.html
*/
class plgVmShipmentRules_Shipping_AdvancedInstallerScript class plgVmShipmentRules_Shipping_AdvancedInstallerScript
{ {
......
...@@ -24,8 +24,10 @@ defined ('_JEXEC') or die('Restricted access'); ...@@ -24,8 +24,10 @@ defined ('_JEXEC') or die('Restricted access');
if (!class_exists ('vmPSPlugin')) { if (!class_exists ('vmPSPlugin')) {
require(JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'); require(JPATH_VM_PLUGINS . DS . 'vmpsplugin.php');
} }
if (!class_exists ('plgVmShipmentRules_Shipping_Base')) {
// Only declare the class once... // Only declare the class once...
if (class_exists ('plgVmShipmentRules_Shipping_Base')) {
return;
}
/** Shipping costs according to general rules. /** Shipping costs according to general rules.
* Supported Variables: Weight, ZIP, Amount, Products (1 for each product, even if multiple ordered), Articles * Supported Variables: Weight, ZIP, Amount, Products (1 for each product, even if multiple ordered), Articles
...@@ -342,6 +344,15 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { ...@@ -342,6 +344,15 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
return $articles; return $articles;
} }
protected function getOrderProducts (VirtueMartCart $cart) {
/* Cache the value in a static variable and calculate it only once! */
static $products = 0;
if(empty($products) and count($cart->products)>0){
$products = count($cart->products);
}
return $products;
}
protected function getOrderDimensions (VirtueMartCart $cart, $length_dimension) { protected function getOrderDimensions (VirtueMartCart $cart, $length_dimension) {
/* Cache the value in a static variable and calculate it only once! */ /* Cache the value in a static variable and calculate it only once! */
static $calculated = 0; static $calculated = 0;
...@@ -359,7 +370,6 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { ...@@ -359,7 +370,6 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
$l = ShopFunctions::convertDimensionUnit ($product->product_length, $product->product_lwh_uom, $length_dimension); $l = ShopFunctions::convertDimensionUnit ($product->product_length, $product->product_lwh_uom, $length_dimension);
$w = ShopFunctions::convertDimensionUnit ($product->product_width, $product->product_lwh_uom, $length_dimension); $w = ShopFunctions::convertDimensionUnit ($product->product_width, $product->product_lwh_uom, $length_dimension);
$h = ShopFunctions::convertDimensionUnit ($product->product_height, $product->product_lwh_uom, $length_dimension); $h = ShopFunctions::convertDimensionUnit ($product->product_height, $product->product_lwh_uom, $length_dimension);
// JFactory::getApplication()->enqueueMessage("<pre>Product, returned dimensions: $l x $w x $h, from $product->product_lwh_uom to $length_dimension, ".print_r($product,1)."</pre>", 'error');
$volume = $l * $w * $h; $volume = $l * $w * $h;
$dimensions['volume'] += $volume * $product->quantity; $dimensions['volume'] += $volume * $product->quantity;
...@@ -376,18 +386,26 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { ...@@ -376,18 +386,26 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
$dimensions['totalheight'] += $h * $product->quantity; $dimensions['totalheight'] += $h * $product->quantity;
} }
} }
// JFactory::getApplication()->enqueueMessage("<pre>Dimensions: ".print_r($dimensions,1)."</pre>", 'error');
return $dimensions; return $dimensions;
} }
protected function getOrderProducts (VirtueMartCart $cart) { function getOrderWeights (VirtueMartCart $cart, $weight_units) {
/* Cache the value in a static variable and calculate it only once! */ static $calculated = 0;
static $products = 0; static $dimensions=array(
if(empty($products) and count($cart->products)>0){ 'weight' => 0,
$products = count($cart->products); 'maxweight' => 0, 'minweight' => 9999999999,
);
if ($calculated==0 && count($cart->products)>0) {
$calculated = 1;
foreach ($cart->products as $product) {
$w = ShopFunctions::convertWeigthUnit ($product->product_weight, $product->product_weight_uom, $to_weight_unit);
$dimensions['maxweight'] = max ($dimensions['maxweight'], $w);
$dimensions['minweight'] = min ($dimensions['minweight'], $w);
$dimensions['weight'] += $w * $product->quantity;
}
} }
return $products; return $dimensions;
} }
/** Allow child classes to add additional variables for the rules /** Allow child classes to add additional variables for the rules
...@@ -395,26 +413,17 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { ...@@ -395,26 +413,17 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
protected function addCustomCartValues (VirtueMartCart $cart, $cart_prices, &$values) { protected function addCustomCartValues (VirtueMartCart $cart, $cart_prices, &$values) {
} }
protected function getCartValues (VirtueMartCart $cart, $method, $cart_prices) { protected function getCartValues (VirtueMartCart $cart, $method, $cart_prices) {
$orderWeight = $this->getOrderWeight ($cart, $method->weight_unit);
$address = (($cart->ST == 0) ? $cart->BT : $cart->ST); $address = (($cart->ST == 0) ? $cart->BT : $cart->ST);
$products = 0;
$articles = 0;
foreach ($cart->products as $product) {
$products += 1;
$articles += $product->quantity;
}
$zip = trim($address['zip']); $zip = trim($address['zip']);
$cartvals = array('weight'=>$orderWeight, $cartvals = array('zip'=>$zip,
'zip'=>$zip,
'zip1'=>substr($zip,0,1), 'zip1'=>substr($zip,0,1),
'zip2'=>substr($zip,0,2), 'zip2'=>substr($zip,0,2),
'zip3'=>substr($zip,0,3), 'zip3'=>substr($zip,0,3),
'zip4'=>substr($zip,0,4), 'zip4'=>substr($zip,0,4),
'zip5'=>substr($zip,0,5), 'zip5'=>substr($zip,0,5),
'zip6'=>substr($zip,0,6), 'zip6'=>substr($zip,0,6),
'articles'=>$articles, 'articles'=>$this->getOrderArticles($cart),
'products'=>$products, 'products'=>$this->getOrderProducts($cart),
'amount'=>$cart_prices['salesPrice'], 'amount'=>$cart_prices['salesPrice'],
'amountWithTax'=>$cart_prices['salesPrice'], 'amountWithTax'=>$cart_prices['salesPrice'],
'amountWithoutTax'=>$cart_prices['priceWithoutTax'], 'amountWithoutTax'=>$cart_prices['priceWithoutTax'],
...@@ -431,6 +440,8 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { ...@@ -431,6 +440,8 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
'country'=>$address['virtuemart_country_id'], 'country'=>$address['virtuemart_country_id'],
); );
$cartvals = array_merge ($cartvals, $this->getOrderWeights ($cart, $method->weight_unit));
$cartvals = array_merge ($cartvals, $this->getOrderDimensions ($cart, $method->length_unit)); $cartvals = array_merge ($cartvals, $this->getOrderDimensions ($cart, $method->length_unit));
// Let child classes update the $cartvals array, or add new variables // Let child classes update the $cartvals array, or add new variables
$this->addCustomCartValues($cart, $cart_prices, $cartvals); $this->addCustomCartValues($cart, $cart_prices, $cartvals);
...@@ -575,11 +586,11 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { ...@@ -575,11 +586,11 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
return $ret; return $ret;
} }
}
} }
if (!class_exists ('ShippingRule')) { if (class_exists ('ShippingRule')) {
return;
}
class ShippingRule { class ShippingRule {
var $rulestring = ''; var $rulestring = '';
...@@ -788,5 +799,4 @@ class ShippingRule { ...@@ -788,5 +799,4 @@ class ShippingRule {
} }
}
// No closing tag // No closing tag
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment