Hi, i am new in the forum, but i have a problem that i cant resolve and i would like to get your help.
VirtueMart 3.0.2 produces a miscalculation when a payment method (Plugin standard) with increased rate in percent is selected.
For example, if a product has a final price, including taxes, of € 100 and the payment method selected represents an increase of 3% of the total, virtuemart shows a final price of € 103.09 instead of display € 103.
After some research, I have deduced that the operation does is the following:
€ 100 * 1.03 = 103 €
This should be normal, but then Virtuemart calculates the following operation:
€ 103 * 1.03 = € 106.09
And from this result Virtuemart makes subtraction with the above result, leading to the following:
€ 106.09 € -103 = € 3.09
and then to this value of € 3.09, Virtuemart finally sum € 100 of product price, as showing the panel frontral € 103.09
(http://www.fidelitysound.es/pantallazo%20web.jpg)
http://www.fidelitysound.es/pantallazo%20web.jpg (http://www.fidelitysound.es/pantallazo%20web.jpg)
Does anyone know how to resolve this error?
What its due this error?
So effectively the 3% is calc. twice?
The calc. is done in the function setCartPrices(VirtueMartCart $cart, &$cart_prices, $method, $progressive = true)
in administrator\components\com_virtuemart\plugins\vmpsplugin.php ~ line 933
don't know if u can find anything there?
Hi, thanks for your reply.
I'll try to look into that file.
Hello again, I've been reviewing the file and I find no error.
The code is as follows, the equations are simple and seems fine.
function setCartPrices (VirtueMartCart $cart, &$cart_prices, $method, $progressive = true) {
if (!class_exists ('calculationHelper')) {
require(VMPATH_ADMIN . DS . 'helpers' . DS . 'calculationh.php');
}
$_psType = ucfirst ($this->_psType);
$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;
}
:) :D ;D
I've already solved !!!!!!!!!!!!
I changed the order of calculation, simply by progressive and perfect !!!!
That I'm happy !!!
Thank you so much for the guidance !!! many many thank you very much, my friend !!!!
Please explain better what you did as a help for others
Thanks
The payment plugin can implement an option for that
function setCartPrices (VirtueMartCart $cart, &$cart_prices, $method, $progressive = true) {
progressive considers that you have to loan the fee itself
Hello
Yes, i will add this option in paypal.
Yeh the VirtueMart flower is by far not showing all of its possibilities.
Hello again, not turned to look at the forum but now I had to go back to solve the problem by upgrading to Virtuemart 3.0.9 and i will explain the simple modification to the calculation of percentages is correct.
I canceled one of the processes of calculation on line 959 to simply stay the progressive calculation:
(http://www.fidelitysound.es/images/vmpspluginmod1.jpg)
Hi, I'm using the VM version 3.0.12 and I have the same problem.
If the payment method I put 10% or -10% miscalculate the percentage.
I am not programmed experienced. Could include this fix in the next version or help me fix it?
Regards,
Hernan
Mosdata, please read closely again
Quote from: Milbo on March 10, 2015, 12:34:00 PM
The payment plugin can implement an option for that
function setCartPrices (VirtueMartCart $cart, &$cart_prices, $method, $progressive = true) {
progressive considers that you have to loan the fee itself
Your payment is using the progressive option
I can't find setCartPrices function in my customized payment plugin ... can I add this function ... if so, what is the full function?
function setCartPrices (VirtueMartCart $cart, &$cart_prices, $method, $progressive = true) {
FYI - Plugin developer provided solution on 3.8.9 10473 with hack to core /administrator/components/com_virtuemart/plugins/virtuemart/vmpsplugin.php
... but I'm also need to find immediate solution for 3.2.12 for LIVE site which is now taking orders and over charging payment fees ... this will cost me weeks of manual work to re-calulate and re-imburse everyone !!
You just add the function in your plugin and overwrite the core function. Or as proxy
function setCartPrices (VirtueMartCart $cart, &$cart_prices, $method, $progressive = true) {
parent::setCartPrices (VirtueMartCart $cart, $cart_prices, $method, false);
}