News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Wrong calculation percentage in VM 3.0.2

Started by Enrique_Barrajon, March 08, 2015, 22:36:56 PM

Previous topic - Next topic

Enrique_Barrajon

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

Does anyone know how to resolve this error?
What its due this error?

GJC Web Design

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?
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Enrique_Barrajon

Hi, thanks for your reply.
I'll try to look into that file.

Enrique_Barrajon

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;
      }


Enrique_Barrajon

 :) :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 !!!!

GJC Web Design

Please explain better what you did as a help for others

Thanks
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Milbo

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
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

alatak

Hello
Yes, i will add this option in paypal.

Milbo

Yeh the VirtueMart flower is by far not showing all of its possibilities.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Enrique_Barrajon

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:


mosdata

#10
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

Milbo

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
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Robert_ITMan

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 !!
WEBSITES @ OURFINGERTIPS
manage > develop > market > repeat

Save a lot of time and money when focused on building a website that works with marketing efforts to get more leads and sales from visitors.

www.ourfingertips.com

Milbo

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);
}
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/