Jump to content

how to assign a currency exchange rate to a variable in the module using PHP


884483048

Recommended Posts

Try 

$currency = new Currency($id_currency);
$currency->conversion_rate

Although you obviously can't get it unless it's a non-default currency. The method you mentioned is still supposed to work even in 1.7 anyway

Link to comment
Share on other sites

Hi,
 
Use the following code to get the currency conversion.
 

For Prestashop 1.6:

For default currency conversion:

$conversion_rate = Context::getContext()->currency->getConversationRate();

OR 

$currency = new Currency($id_currency);
$conversion_rate = $currency->getConversationRate();
 

For Prestashop 1.7:

For default currency conversion

$conversion_rate = Context::getContext()->currency->getConversionRate();

OR 

$currency = new Currency($id_currency);
$conversion_rate = $currency->getConversionRate();
 
Edited by Knowband Plugins (see edit history)
  • Like 1
Link to comment
Share on other sites

Thank you for the answers. I have a default currency usd and an additional currency with id = 4. Where to insert into your code id number to get rate for desired currency? Should do like this:

$currency = new Currency(4);
$conversion_rate = $currency->getConversionRate();

Link to comment
Share on other sites

21 hours ago, 884483048 said:

Thank you for the answers. I have a default currency usd and an additional currency with id = 4. Where to insert into your code id number to get rate for desired currency? Should do like this:

$currency = new Currency(4);
$conversion_rate = $currency->getConversionRate();

 

Yes, You will get the conversion rate of the additional currency in respect of default currency (Basically the rate which have defined in the admin).

Are you looking for the same OR something else?

 

 

Link to comment
Share on other sites

1 hour ago, Knowband Plugins said:

 

Yes, You will get the conversion rate of the additional currency in respect of default currency (Basically the rate which have defined in the admin).

Are you looking for the same OR something else?

 

 

Yes it's that I was looking for.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...