Display currency rate on the invoice.

  • Posts: 50
  • Thank you received: 1
11 years 8 months ago #90094

Hi.

Can you please help me.

How do I put the currency rate on the invoice? I have looked in the view for backend currency listing to maybe get a hint. Getting stuck. Argh...

I have three currencies EUR, USD and SEK. EUR=primary. I want to display the rate of USD or SEK (depending on chosen currency) on the frontend printable invoice. That goes for the backend invoice as well.



/Mathias

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 8 months ago #90144

Hi,

Is the price the good one ? If it is, you can use the function "format($number,$currency_id=0,$format_override='')" of the class "currency".
Else, you can use the function "convertUniquePrice($price,$srcCurrency_id, $dstCurrency_id)" then "format(..)" of the same class.

To call the class, you can do:

$currencyClass = hikashop_get('class.currency');
$price = $currencyClass->format($number,$currency_id=0,$format_override='');

Please Log in or Create an account to join the conversation.

  • Posts: 50
  • Thank you received: 1
11 years 8 months ago #90303

Thanks Xavier.

Whith your suggestions I was able to do the following:

<?php
$currencyClass = hikashop_get('class.currency');
$converted_price = $currencyClass->convertUniquePrice($this->order->order_full_price,$this->order->order_currency_id,1);
echo 'Total: '.$currencyClass->format($converted_price).'<br>';
echo 'Rate: '.$this->order->order_full_price/$converted_price;
?>

Sale in SEK, Primary currency=EUR
This gives the output:

Total: 40,66 €
Rate: 8.4557


So far so good. BUT IT IS WRONG! Stay with me and I will explain. The output is dynamic. It shows the rate on todays rates. So it only will be valid on the day for the sale. When looking at an order/invoice e g one week later it shows a different rate. WRONG!

Solution:
I have to make a database entry and put the rate for the sale and store it the same day the sale takes place. Then when looking/printing at the invoice the rate is fetched from database.

Could you please give me a hint on how to do this.

/Mathias

Last edit: 11 years 8 months ago by Jerome. Reason: adding code tags

Please Log in or Create an account to join the conversation.

  • Posts: 26152
  • Thank you received: 4027
  • MODERATOR
11 years 8 months ago #90407

Hi,

If you want to store the rate directly in the order, you can.
You can create an order custom field and with a little plugin which trigger the event "onBeforeOrderCreate" you can modify the object given in parameter by setting the "rate" custom field.

After that, displaying the rate would be quite easy.
If you custom field is called "order_rate", you would just have to write:

echo $this->order->order_rate;

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 50
  • Thank you received: 1
11 years 8 months ago #90438

Thanks Jerome.

Never made a plugin before. I will give it a try :) . I post my result here.


Regards

Please Log in or Create an account to join the conversation.

Time to create page: 0.073 seconds
Powered by Kunena Forum