VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: henry_osn on September 27, 2021, 17:11:01 PM

Title: [SOLVED] Bug in Standard payment methods
Post by: henry_osn on September 27, 2021, 17:11:01 PM
The tax / tributes does not work on current version, VirtueMart 3.8.8 10472. How to fix for "standard payment"? Thanks

Still about https://forum.virtuemart.net/index.php?topic=117823.30
Title: Re: Bug in Standard payment methods
Post by: henry_osn on October 01, 2021, 20:00:42 PM
somebody?
Title: Re: Bug in Standard payment methods
Post by: Milbo on October 04, 2021, 21:01:10 PM
Come on, it works for soo many people. Do you really think we have a glasbowl?

Please describe your error. Tell your configuration and your desired result. Make nice screenshots, cut the important parts and upload it here. This way no one know what you mean.
Title: Re: Bug in Standard payment methods
Post by: henry_osn on October 05, 2021, 02:41:23 AM
Sorry, but it seemed pretty clear to me. I even quoted the post of an old discussion, where the problem had been solved, but in the latest version of Virtuemart, it doesn't work. There are no errors, it just the tax / tributes for "standard payment" does not work in cart. I type a fee in the payment method (-8% for example) and nothing happens in the cart. Thanks again.
Title: Re: Bug in Standard payment methods
Post by: Milbo on October 05, 2021, 14:18:03 PM
If you would post your settings! So you used -8%,.... For which setting?

Fee per transaction ? or

Fee or cashback in percent of the total amount.

Did you read the tooltips?
Title: Re: Bug in Standard payment methods
Post by: henry_osn on October 05, 2021, 17:18:53 PM
Thanks for reply.

Fee per transaction -> -8%

I tried also "tax", but not work.

Nothing happens in the cart.
Title: Re: Bug in Standard payment methods
Post by: jjk on October 05, 2021, 23:16:29 PM
I don't have a version 3.8.8 10472 installed, but in my 3.8.9 10473 any fees I add to a standard payment method does show up in the cart right next to the standard payment method.

Do you use the original VirtueMart checkout or a third party checkout?

Note: In the 'Fee per transaction' form field an extra fee would be a positive fixed amount. A negative number would be a rebate.
Maybe you can supply screenshots of your setting and your cart view with the customer data cut off.

Title: Re: Bug in Standard payment methods
Post by: Milbo on October 11, 2021, 22:13:09 PM
and dont use % just the number!
Title: Re: Bug in Standard payment methods
Post by: henry_osn on October 20, 2021, 18:55:53 PM
Thank you all. I was able to offer the percentage discount using the "Fee or cashback in percent of the total amount" field.

But the calculation doesn't work well. I offer 10% off (I typed -10, no %), but the calculation is always wrong. For example for a $1.00 product the 10% discount is equal to $0.09 and not $0.10.
Title: Re: Bug in Standard payment methods
Post by: henry_osn on October 20, 2021, 21:07:53 PM
I found the solution -> https://forum.virtuemart.net/index.php?topic=128671.0

But they still haven't fixed the bug in the current version.

Please read the indicated post.

Important: the payment method in question is the default.
Title: Re: Bug in Standard payment methods
Post by: Gomad on October 25, 2021, 04:21:14 AM
Hello

I am using

Distro Name: CentOS Linux release 7.9.2009 (Core)
PHP Version 7.4.24
Joomla! 3.10.2
Virtuemart 3.8.8 10472

I also found errors in the Virtuemart default payment method

If I do set a value in the field "Fee or cashback in percent of the total amount." the fee or rebate are calculated, but the result is wrong.

I did input just numbers without  % sign

In order to try to understand what happens I tried with a simple case, 10% commission fee, creating a cart with products for 1000 € net (not taxes, no shipping fees, just 1000€ net) the result of the percentage fee calculator is 111,11 € and outputs a total of 1111,11€

What is causing to transform the 10% I setup into the 11,111% that is effectively calculated?

I read the other old post linked by Henry >>> "I found the solution -> https://forum.virtuemart.net/index.php?topic=128671.0".

Sincerely I did not understand well the logics used as I lack a lot of info on the whole rest, anyhow, I found a way to have it working apparently, but setting it up in this way I ask myself what might happen in other possible cases...

Watching at that old post seems in virtuemart 3.8.8 that in the administrator/components/com_virtuemart/plugins/vmpsplugin.php file at line 1237 the string used in the "simple case" seems to belong to the "progressive case" and vice versa.

I tried to swap the lines, and seems to work.

so the original code is this one:

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


I changed it into this:

                                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));
//$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 );
}



Apparently works now, however I'd like to know if this is correct and why this happens...

In that old post I read this message from Milbo that seems relevant

" 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"


What does mean "progressive"?

What does mean "progressive considers that you have to loan the fee itself"?

Loan the fee? I do not understand this, can anyone please explain it?

I am testing it with the standard Virtuemart payment method, reading that post one might think that there is a way to set a payment method as progressive or not progressive, if it is so, how can I set the standard Virtuemart payment method as "progressive" or "non progressive"?

I did not see an option to do that anywhere (I think at least)...

Can anyone confirm that swapping the position of those two lines is OK and that does not cause other kind of errors in other circumstances?

Is it possible to have more info on all of this?

Does exist some documentation explaining how this work ?

Thank you
Title: Re: Bug in Standard payment methods
Post by: Milbo on October 25, 2021, 16:06:15 PM
Yes, the progressive calculation is wrong for cashback. I added an option now, so you can change the behaviour per config option
Title: Re: Bug in Standard payment methods
Post by: Gomad on October 25, 2021, 17:13:06 PM
Hello Milbo

Thank you,  I  guess that it will available with the next Virtuemart release, so, for the moment being, can I leave the code as I corrected it without observing other errors in different cases?

I am thinking to use also stripe when I will have ended the general setup of the website.

In particular, the code in the file administrator/components/com_virtuemart/plugins/vmpsplugin.php I modified, is it going to be used only by the standard default Virtuemart payment method?

Or maybe that same script is also somehow used by third parties payment method plugins? (thus the modification I did could cause malfunctioning in other scripts relying on it?)

Sorry for the naive questions, I am learning from scratch...

Thank you
Title: Re: Bug in Standard payment methods
Post by: GJC Web Design on October 25, 2021, 19:03:45 PM
the function setCartPrices is used in numerous bundled payment plugins .. just search them for setCartPrices

Title: Re: Bug in Standard payment methods
Post by: Milbo on October 25, 2021, 22:03:12 PM
It works without interfering. Any plugin which calls itself the function and uses the already existing $progressive parameter will work as before.

But all other plugins have now a new core parameter, $progressive, which is automatically added, if they use the lately introduced core parameters (categories, blocking, categories, and so on). If the method provides the parameter $progressive, then it overrides the function parameter, because it was wrong from begin, to add it.

There is only one small problem left. When a plugin must use progressive calculation (actually the normal way!) and uses the core variables. Then users may select the wrong option. Maybe I just introduce a small extra variable, which is set in constructor "forceProgressive", or so.
Title: Re: Bug in Standard payment methods
Post by: Gomad on October 25, 2021, 22:45:38 PM
Hi GJC and Milbo

OK, thank you, so I think to understand that for the moment I can leave the standard payment plugin administrator/components/com_virtuemart/plugins/vmpsplugin.php modified as shown in my previous post and will not get problems with other payment method plugins because there is not interference.

In the meanwhile changes will be done in the next version and the problem will be solved as you wrote adding an option to set "progressive" and maybe an extra one to force it for plugins that are not "perfect".

In practice when the next version will be released I should not see problems nor go back to modify that vmpsplugin.php file

I hope to have understood well.

Thank you.
Title: Re: [SOLVED] Bug in Standard payment methods
Post by: Milbo on October 28, 2021, 00:23:20 AM
Please test https://dev.virtuemart.net/attachments/1291/com_virtuemart.3.8.9.10557_package_or_extract.zip