News:

Support the VirtueMart project and become a member

Main Menu

Currency not showing correctly in the order emails.

Started by yobokkie, January 30, 2013, 11:25:05 AM

Previous topic - Next topic

yobokkie

I'm not sure if this topic has been covered already, I did a search and couldn't find anything exactly like this. I have picked up an error in VM 2.0.18 (Joomla 2.5.8). The currency conversion module is installed on the site and works well to show the prices and in the cart it's the correct converted price but when the order email is sent out the price is shown is the vendors price with no conversion. However the currency symbol still matches that which it was converted to.
So explain it better the cart shows a total of $ 22.50, converted from the vendor equivalent of GBP 14.30. However in the email sent to the client the total shows $14.30 , so it's correct for neither.
There is no override for the order emails. The cart has an override, but the currency is correct and it's only a very minor tweak from the standard.
I will go through the source code to find the problem but just thought I'd ask here first in case this was a known error and there was some fix already...

yobokkie

I've looked at the order structure on the database and all the rates are set to 1.00. I think the error might be coming in on these lines of code on the order.php model.

if (isset($_cart->pricesCurrency)) {
         $_orderData->user_currency_id = $_cart->paymentCurrency ;//$this->getCurrencyIsoCode($_cart->pricesCurrency);
         $currency = CurrencyDisplay::getInstance($_orderData->user_currency_id);
         if($_orderData->user_currency_id != $_orderData->order_currency){
            $_orderData->user_currency_rate =   $currency->convertCurrencyTo($_orderData->user_currency_id ,1.0,false);
         } else {
            $_orderData->user_currency_rate=1.0;
         }
      }

Lines 572- 580.

This seems to be where it gets the user currency rate from that is written into the database. The order email in turn reads that from the database and so I'm guessing that's where the problem comes in.
I'll dig some more and see where these variables are being defined.
I should also add that this store doesn't have a user sign-in, does the order process use anything here to store a user_currency?

yobokkie

#2
OK so further digging shows the currency is being determined by the payment method. Is there any way have a payment method accept multiple currencies? Because this store is basically just running as a quote system as it's big ticket items that will have custom shipping quotes. So they don't want a select payment method option and as such there's only one payment method set up which covers every area. Is there any way this can cover every currency too?

EDIT: Test with a new payment method for dollars and still wrong... so back to square one...

jjk

Just curious - I suppose the only payment method is a credit card payment method. If this is what you actually use, I wonder how the shop owner will charge the foreign currency amount. As far as I know, all credit payment processing services allow the merchant only to charge customer's credit cards in their home country currency.
In other words, if the shop is located in Australia, the shop owner can't charge in British Pounds.
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

yobokkie

#4
Yeah they have to send custom payment requests so no credit card functionality. It's mostly wholesale and so all the shipping has to be quoted on first before the account is settled.

I have however solved the problem for this case by changing a few lines.
In the orders model quoted above I changed those lines to:

if (isset($_cart->pricesCurrency)) {
         $_orderData->user_currency_id = $_cart->pricesCurrency ;//$this->getCurrencyIsoCode($_cart->pricesCurrency);
         $currency = CurrencyDisplay::getInstance($_orderData->user_currency_id);
         if($_orderData->user_currency_id != $_orderData->order_currency){
            $_orderData->user_currency_rate =   $currency->convertCurrencyTo($_orderData->user_currency_id ,1.0,false);
         } else {
            $_orderData->user_currency_rate=1.0;
         }
      }

so basically just took the prices currency as the the user's currency instead of the payment currency, which now causes the order to save in the database with the correct rate and currency id.

Then in the view.html file under components/com_virtuemart/views/invoice/

I added after line 160: (if(!class_exists('CurrencyDisplay')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'currencydisplay.php');)

These lines:
if (!$this->doVendor){
         $emailCurrencyId = $orderDetails['details']['BT']->user_currency_id;
         $currency = CurrencyDisplay::getInstance($emailCurrencyId,$vendorId);
      }
      else {
      $currency = CurrencyDisplay::getInstance(0,$vendorId);      
      }

and removed line 161 : $currency = CurrencyDisplay::getInstance($emailCurrencyId,$vendorId);

so again basically just overriding the payment currency id with the one now saved in the order database table.

However it now sends the email with the new currency to both vendor and shopper. I was trying to change it the vendors currency for that email but can't get it to work.
But at least it shows the correct amounts one way or another. Maybe someone who's more better acquainted with VM can offer a better solution? Especially seeing as the next update will override this.
I'm not sure how it might effect credit card payments being as I've overridden the user currency saved in the database, maybe if there was a way to use that currency ID for the payments still but then override the prices via the "user_currency_rate" stored in the database for the email only, so the end user sees the invoice in their currency but the pay in the payment currency. Again maybe there's a better qualified expert out there who could come up with a nicer solution.

      

amet123

Hi  jjk

if i purchase something from india and after conviersion in Dollar what about invoice genrated in which currency

regards
Amit Vaid

Gap Solution
Web Development

alatak

         Hello yobokkie

I found one error in the email subject. The amount was not converted, and the currency sign was the email sign.

int he file components/com_virtuemart/views/invoice/view.html.php
from line 259
//vmdebug('renderMailLayout invoice '.date('H:i:s'),$this->order);
if (strpos($layout,'mail') !== false) {
    if ($this->doVendor) {
    //Old text key COM_VIRTUEMART_MAIL_SUBJ_VENDOR_C
    $this->subject = JText::sprintf('COM_VIRTUEMART_MAIL_SUBJ_VENDOR_'.$orderDetails['details']['BT']->order_status, $this->shopperName, strip_tags($currency->priceDisplay($orderDetails['details']['BT']->order_total)), $orderDetails['details']['BT']->order_number);
    $recipient = 'vendor';
    } else {
    $this->subject = JText::sprintf('COM_VIRTUEMART_MAIL_SUBJ_SHOPPER_'.$orderDetails['details']['BT']->order_status, $vendor->vendor_store_name, strip_tags($currency->priceDisplay($orderDetails['details']['BT']->order_total)), $orderDetails['details']['BT']->order_number );
    $recipient = 'shopper';
    }
    $this->assignRef('recipient', $recipient);
}


replace by
//vmdebug('renderMailLayout invoice '.date('H:i:s'),$this->order);
if (strpos($layout,'mail') !== false) {
    if ($this->doVendor) {
    //Old text key COM_VIRTUEMART_MAIL_SUBJ_VENDOR_C
    $this->subject = JText::sprintf('COM_VIRTUEMART_MAIL_SUBJ_VENDOR_'.$orderDetails['details']['BT']->order_status, $this->shopperName, strip_tags($currency->priceDisplay($orderDetails['details']['BT']->order_total, $currency)), $orderDetails['details']['BT']->order_number);
    $recipient = 'vendor';
    } else {
    $this->subject = JText::sprintf('COM_VIRTUEMART_MAIL_SUBJ_SHOPPER_'.$orderDetails['details']['BT']->order_status, $vendor->vendor_store_name, strip_tags($currency->priceDisplay($orderDetails['details']['BT']->order_total, $currency)), $orderDetails['details']['BT']->order_number );
    $recipient = 'shopper';
    }
    $this->assignRef('recipient', $recipient);
}


For me the prices displayed in the emails are correctly converted.

QuoteI've looked at the order structure on the database and all the rates are set to 1.00.
This is not normal.

Just to try to reproduce your problem.
What are the settings for Payment Currency, Email Currency ?

amet123

my base currency is INR and in paypal i use Dollar
Amit Vaid

Gap Solution
Web Development

alatak

hello amet123

Quoteif i purchase something from india and after conviersion in Dollar what about invoice genrated in which currency
Quotemy base currency is INR and in paypal i use Dollar
The behaviour by default is this one:
If you base currency price is in INR, and your shop currency is in dollar, then payment, mails, invoices are in dollar.

Then you can also do this: and all that is regardless your base price  currency
Publish the currency module: the user selects another currency for the price display.
but then payment, mails, invoices are still  in dollar.


And then you can also do this
in Paypal,
Parameter  Payment Currency: give another currency. For example Euro
Parameter Email Currency: vendor currency
Then , if the client has selected Euro in the vendor currency module, he will pay in euro , and the payment, mails, invoices are in dollar


or
Parameter  Payment Currency: give another currency. For example Euro
Parameter Email Currency: payment currency
Then , if the client has selected Euro in the vendor currency module, he will pay in euro , and the payment, mails, invoices are in euro



yobokkie

Hi Alatak,
Thanks for the response, sorry for the long delay in responding. The main problem is that the store owner wanted the client emails to be sent in their originally selected currency, so if they selected GBP they'd see the invoice email in Pounds, even if the vendors' currency was USD. As it was before I'd changed anything, the email was been sent to the client with the right currency symbol but the default/ unconverted value. Is there perhaps a way or a setting in VM that allows email to the client to be sent in the currency they selected? Because for me it was only working after I'd done those code changes. Like something similar to what you'd changed on the email subject line but that applies to the whole email's contents as well.

The currency I tested on was vendor currency set to GBP and payment currency set to "default vendor currency". Where do you set the email currency?