To disable any internal caches in VM's calculation, you may want to update this function in VM:
\administrator\components\com_virtuemart\plugins\vmpsplugin.php
- Code: Select all
function setCartPrices (VirtueMartCart $cart, &$cart_prices, $method, $progressive = true) {
static $c = array();
$idN = 'virtuemart_'.$this->_psType.'method_id';
$_psType = ucfirst ($this->_psType);
/* stAn disabled caching:
if(isset($c[$this->_psType][$method->$idN])){
$cart_prices = array_merge($cart_prices,$c[$this->_psType][$method->$idN]);
return $cart_prices['salesPrice' . $_psType];
}
*/
if (!class_exists ('calculationHelper')) {
require(VMPATH_ADMIN . DS . 'helpers' . DS . 'calculationh.php');
}
$calculator = calculationHelper::getInstance ();
$cart_prices[$this->_psType . 'Value'] = $calculator->roundInternal ($this->getCosts ($cart, $method, $cart_prices), 'salesPrice');
if(!isset($cart_prices[$this->_psType . 'Value'])) $cart_prices[$this->_psType . 'Value'] = 0.0;
if(!isset($cart_prices[$this->_psType . 'Tax'])) $cart_prices[$this->_psType . 'Tax'] = 0.0;
if($this->_psType=='payment'){
$cartTotalAmountOrig=$this->getCartAmount($cart_prices);
if(!$progressive){
//Simple
$cartTotalAmount=($cartTotalAmountOrig + $method->cost_per_transaction) * (1 +($method->cost_percent_total * 0.01));
//vmdebug('Simple $cartTotalAmount = ('.$cartTotalAmountOrig.' + '.$method->cost_per_transaction.') * (1 + ('.$method->cost_percent_total.' * 0.01)) = '.$cartTotalAmount );
//vmdebug('Simple $cartTotalAmount = '.($cartTotalAmountOrig + $method->cost_per_transaction).' * '. (1 + $method->cost_percent_total * 0.01) .' = '.$cartTotalAmount );
} else {
//progressive
$cartTotalAmount = ($cartTotalAmountOrig + $method->cost_per_transaction) / (1 -($method->cost_percent_total * 0.01));
//vmdebug('Progressive $cartTotalAmount = ('.$cartTotalAmountOrig.' + '.$method->cost_per_transaction.') / (1 - ('.$method->cost_percent_total.' * 0.01)) = '.$cartTotalAmount );
//vmdebug('Progressive $cartTotalAmount = '.($cartTotalAmountOrig + $method->cost_per_transaction) .' / '. (1 - $method->cost_percent_total * 0.01) .' = '.$cartTotalAmount );
}
$cart_prices[$this->_psType . 'Value'] = $cartTotalAmount - $cartTotalAmountOrig;
}
/* stAn original:
if(!isset($cart_prices['salesPrice' . $_psType])) $cart_prices['salesPrice' . $_psType] = $cart_prices[$this->_psType . 'Value'];
new: */
$cart_prices['salesPrice' . $_psType] = $cart_prices[$this->_psType . 'Value'];
$taxrules = array();
if(isset($method->tax_id) and (int)$method->tax_id === -1){
} else if (!empty($method->tax_id)) {
$cart_prices[$this->_psType . '_calc_id'] = $method->tax_id;
$db = JFactory::getDBO ();
$q = 'SELECT * FROM #__virtuemart_calcs WHERE `virtuemart_calc_id`="' . $method->tax_id . '" ';
$db->setQuery ($q);
$taxrules = $db->loadAssocList ();
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'];
$cart_prices[$this->_psType . 'TaxPerID'][$rule['virtuemart_calc_id']] = $calculator->roundInternal($calculator->roundInternal($calculator->interpreteMathOp($rule, $rule['subTotal'])) - $rule['subTotal'], 'salesPrice');
$cart_prices[$this->_psType . 'Tax'] += $cart_prices[$this->_psType . 'TaxPerID'][$rule['virtuemart_calc_id']];
}
}
} else {
$taxrules = array_merge($cart->cartData['VatTax'],$cart->cartData['taxRulesBill']);
if(!empty($taxrules) ){
$denominator = 0.0;
foreach($taxrules as &$rule){
//Quickn dirty
if(!isset($rule['calc_kind'])) $rule = (array)VmModel::getModel('calc')->getCalc($rule['virtuemart_calc_id']);
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;
$rule['taxAmountOld'] = $rule['taxAmount'];
$rule['taxAmount'] = 0;
}
if(empty($denominator)){
$denominator = 1;
}
foreach($taxrules as &$rule){
$frac = ($rule['subTotalOld']-$rule['taxAmountOld'])/$denominator;
$rule['subTotal'] = $cart_prices[$this->_psType . 'Value'] * $frac;
if(!isset($cart_prices[$this->_psType . 'Tax'])) $cart_prices[$this->_psType . 'Tax'] = 0.0;
$cart_prices[$this->_psType . 'TaxPerID'][$rule['virtuemart_calc_id']] = $calculator->roundInternal($calculator->roundInternal($calculator->interpreteMathOp($rule, $rule['subTotal'])) - $rule['subTotal'], 'salesPrice');
$cart_prices[$this->_psType . 'Tax'] += $cart_prices[$this->_psType . 'TaxPerID'][$rule['virtuemart_calc_id']];
}
}
}
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 (count ($taxrules) > 0 ) {
$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');
reset($taxrules);
foreach($taxrules as &$rule){
if(!isset($cart_prices[$this->_psType . '_calc_id']) or !is_array($cart_prices[$this->_psType . '_calc_id'])) $cart_prices[$this->_psType . '_calc_id'] = array();
$cart_prices[$this->_psType . '_calc_id'][] = $rule['virtuemart_calc_id'];
if(isset($rule['subTotalOld'])) $rule['subTotal'] += $rule['subTotalOld'];
if(isset($rule['taxAmountOld'])) $rule['taxAmount'] += $rule['taxAmountOld'];
}
} else {
$cart_prices['salesPrice' . $_psType] = $cart_prices[$this->_psType . 'Value'];
$cart_prices[$this->_psType . 'Tax'] = 0;
$cart_prices[$this->_psType . '_calc_id'] = 0;
}
/* stAn, disable cache:
$c[$this->_psType][$method->$idN] = $cart_prices;
*/
//if($_psType='Shipment')vmTrace('setCartPrices '.$cart_prices['salesPrice' . $_psType]);
return $cart_prices['salesPrice' . $_psType];
}
the code was suggested towards vm3.0.10 of 21.7.2015 and OPC2.0.293
we are trying to find a solution to the calculation problems without this core VM modification needed.
best regards, stan, rupostel.com