Author Topic: Solution for Bugs (Shipping fee is converted twice & Paypal wrong currency)  (Read 2407 times)

kcalvis

  • Beginner
  • *
  • Posts: 5
Thanks that "techmatters" posted in Serious bug when using currency converter fixed one of my problems finding in checkout when using currency converter
http://forum.virtuemart.net/index.php?topic=44648.msg142296#msg142296 (2014-06-19: sadly still having bug, see update)

However, in the post, although it provides a way to easily solve the second bug - Shipping fee is converted twice, the method only solves the shipping total and order total in the backend and passing to paypal, but not the displayed value in checkout step 4. It still shows a wrong shipping fee and total to the buyers.

Here is my way to solve the bug of "Shipping fee is converted twice":

First, in "administrator/components/com_virtuemart/classes/shipping/standard_shipping.php" (I am only using standard shipping. So, please handle your shipping method yourself.)

find

Code: [Select]
$total_shipping_handling = $GLOBALS['CURRENCY']->convert( $total_shipping_handling, $shipping_rate_currency_code, $GLOBALS['product_currency'] ) ;
and after this line add

Code: [Select]
$_SESSION['shipping_rate_currency_code'] = $GLOBALS['product_currency'] ;
Second, in "administrator/components/com_virtuemart/classes/ps_checkout.php"

find

Code: [Select]
$d['shipping_tax'] = $GLOBALS['CURRENCY']->convert( $d['shipping_tax'] );
$d['shipping_total'] = $GLOBALS['CURRENCY']->convert( $d['shipping_total'] );

replace to

Code: [Select]
$d['shipping_tax'] = $GLOBALS['CURRENCY']->convert( $d['shipping_tax'], $_SESSION['shipping_rate_currency_code'], $GLOBALS['product_currency'] );
$d['shipping_total'] = $GLOBALS['CURRENCY']->convert( $d['shipping_total'], $_SESSION['shipping_rate_currency_code'], $GLOBALS['product_currency'] );

Finally, in "administrator/components/com_virtuemart/html/ro_basket.php"

find

Code: [Select]
$shipping_total = $GLOBALS['CURRENCY']->convert( $shipping_total );
replace to

Code: [Select]
$shipping_total = $GLOBALS['CURRENCY']->convert( $shipping_total, $_SESSION['shipping_rate_currency_code'], $GLOBALS['product_currency'] );
It will completely fix the bug of using currency converter with multi-currency in the checkout step 2, 3, & 4.

Of course, I know VM1.1 is no longer supported but I still have some clients not willing to upgrade VM2...
That is why I have to fix these serious bug...

Hope it will help who is still using VM1.1

===

Update on 2014-06-19:

Sadly the solution of the bug about wrong currency passing to Paypal posted by "techmatters" is not thoroughly solved the problem...

Example of the bug:
VM sends the converted order total amount to Paypal but sends the shop's base currency code (vendor currency), resulting in a mismatch between the order total amount and the currency.  Say the cost of the item was 10 Euro (in the shop/vendor currency) and when converted that is USD 14.70. VM passes 14.70 to Paypal but says the currency is Euro when it should be USD.

The solution of the bug about wrong currency passing to Paypal posted by "techmatters" is by changing the vendor currency code ($_SESSION['vendor_currency']) to the session's current currency code ($_SESSION['product_currency']). It solved the most of the scenario. However, I find a scenario that if the same client makes another new order with Euro after an USD order, and wants to pay later and cancels the immediate payment after the checkout confirmation (on the page of Paypal interface), and then the client comes back, clicks into the pending order and clicks the button "Click to pay here Paypal", VM will direct the client to the page of Paypal again but sadly that the currency code will be kept as the last change in the session because this currency code comes from the currency converter. It means - if the last change is USD (because of the last order), then even the order currency code is confirmed to use Euro, VM passes the amount to Paypal but still says the currency is USD.

Here is my way to solve the bug of "Paypal wrong currency":

In the "Configuration" tab of the PayPal module ("Store > List Payment Profiles > "PayPal"), "Payment extra info" change the below code:

Find


Code: [Select]
"currency_code" => $_SESSION['vendor_currency'],
replace to

Code: [Select]
"currency_code" => $db->f("order_currency"),
Why do I not to use the data in the session? It is because VM will store all the data of every order including the finally confirmed currency code into the database after the checkout confirmation. And so, why do we still use an uncertain data in the session but not to use the confirmed total amount, shipping fee and currency code inside the database?! (Currency converter cannot change the data in the confirmed order!) In the coding of Paypal configuration, it shows that most of the necessary data is selected from the database. It means it is possible to pass the confirmed order currency code from database to Paypal.

===