Commit ff49131e authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

V3.96: Apply bugfixes in the setCartPrices function (from the VM repo), which...

V3.96: Apply bugfixes in the setCartPrices function (from the VM repo), which I had to copy from vmpsplugin.php
parent b8b3151c
......@@ -2,7 +2,7 @@ BASE=rules_shipping
BASE_ADV=rules_shipping_advanced
PLUGINTYPE=vmshipment
ZIPBASE=opentools_vm2
VERSION=3.95
VERSION=3.96
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, Reinhold Kainhofer</copyright>
<license>GPL v3+</license>
<version>3.95</version>
<version>3.96</version>
<description>VMSHIPMENT_RULES_DESC</description>
<files>
<filename plugin="rules_shipping">rules_shipping.php</filename>
......
......@@ -316,7 +316,7 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
}
$_psType = ucfirst ($this->_psType);
$calculator = calculationHelper::getInstance ();
$cart_prices[$this->_psType . 'Value'] = $calculator->roundInternal ($this->getCosts ($cart, $method, $cart_prices), 'salesPrice');
if($this->_psType=='payment'){
......@@ -336,15 +336,26 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
$q = 'SELECT * FROM #__virtuemart_calcs WHERE `virtuemart_calc_id`="' . $method->tax_id . '" ';
$db->setQuery ($q);
$taxrules = $db->loadAssocList ();
} else {
$taxrules = array();
if(!empty($calculator->_cartData['VatTax']) ){
$taxrules = $calculator->_cartData['VatTax'];
if(!empty($taxrules) ){
foreach($taxrules as &$rule){
if(!isset($rule['subTotal'])) $rule['subTotal'] = 0;
if(!isset($rule['taxAmount'])) $rule['taxAmount'] = 0;
$rule['subTotalOld'] = $rule['subTotal'];
$rule['taxAmountOld'] = $rule['taxAmount'];
$rule['taxAmount'] = 0;
$rule['subTotal'] = $cart_prices[$this->_psType . 'Value'];
}
}
} else {
$taxrules = array_merge($calculator->_cartData['VatTax'],$calculator->_cartData['taxRulesBill']);
$denominator = 0;
if(!empty($taxrules) ){
$denominator = 0.0;
foreach($taxrules as &$rule){
//$rule['numerator'] = $rule['calc_value']/100.0 * $rule['subTotal'];
if(!isset($rule['subTotal'])) $rule['subTotal'] = 0;
if(!isset($rule['taxAmount'])) $rule['taxAmount'] = 0;
$denominator += ($rule['subTotal']-$rule['taxAmount']);
$rule['subTotalOld'] = $rule['subTotal'];
$rule['subTotal'] = 0;
......@@ -359,21 +370,15 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
foreach($taxrules as &$rule){
$frac = ($rule['subTotalOld']-$rule['taxAmountOld'])/$denominator;
$rule['subTotal'] = $cart_prices[$this->_psType . 'Value'] * $frac;
vmdebug('Part $denominator '.$denominator.' $frac '.$frac,$rule['subTotal']);
}
} else if(!empty($calculator->_cartData['taxRulesBill']) ){
$taxrules = array_merge($taxrules,$calculator->_cartData['taxRulesBill']);
}
}
if(empty($method->cost_per_transaction)) $method->cost_per_transaction = 0.0;
if(empty($method->cost_percent_total)) $method->cost_percent_total = 0.0;
//If the taxing via unpublished categories is used, then the rules use the subtotal which is now overriden here
/*if (count ($taxrules) == 1 and isset($taxrules[1]['subTotal'] )) {
$taxrules[1]['subTotal'] = $cart_prices[$this->_psType . 'Value'];
}/*/
if (count ($taxrules) > 0 ) {
// BEGIN_RK_CHANGES
......@@ -387,8 +392,9 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
$calculator->setRevert (false);
} else {
// END_RK_CHANGES
$cart_prices['salesPrice' . $_psType] = $calculator->roundInternal ($calculator->executeCalculation ($taxrules, $cart_prices[$this->_psType . 'Value'],true,false), 'salesPrice');
$cart_prices[$this->_psType . 'Tax'] = $calculator->roundInternal (($cart_prices['salesPrice' . $_psType] - $cart_prices[$this->_psType . 'Value']), 'salesPrice');
$cart_prices['salesPrice' . $_psType] = $calculator->roundInternal ($calculator->executeCalculation ($taxrules, $cart_prices[$this->_psType . 'Value'],true,false), 'salesPrice');
//vmdebug('I am in '.get_class($this).' and have this rules now',$taxrules,$cart_prices[$this->_psType . 'Value'],$cart_prices['salesPrice' . $_psType]);
$cart_prices[$this->_psType . 'Tax'] = $calculator->roundInternal (($cart_prices['salesPrice' . $_psType] - $cart_prices[$this->_psType . 'Value']), 'salesPrice');
// BEGIN_RK_CHANGES
}
// END_RK_CHANGES
......@@ -910,7 +916,7 @@ class ShippingRule {
}
if (count($args) == 3) {
switch ($func) {
case "substring": return substr($args[0], $args[1], $args[2]); break;
case "substring": return substr($args[0], $args[1]-1, $args[2]); break;
}
}
// List functions
......
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