884483048 Posted August 8, 2018 Share Posted August 8, 2018 (edited) Who can advise to how to assign a currency exchange rate to a varible in a module using PHP? I tried to use function Currency::getConversionRate() but wasn't unable to get the value. Edited August 8, 2018 by 884483048 (see edit history) Link to comment Share on other sites More sharing options...
NemoPS Posted August 9, 2018 Share Posted August 9, 2018 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 More sharing options...
Knowband Plugins Posted August 9, 2018 Share Posted August 9, 2018 (edited) 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 August 9, 2018 by Knowband Plugins (see edit history) 1 Link to comment Share on other sites More sharing options...
884483048 Posted August 10, 2018 Author Share Posted August 10, 2018 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 More sharing options...
Knowband Plugins Posted August 11, 2018 Share Posted August 11, 2018 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 More sharing options...
884483048 Posted August 11, 2018 Author Share Posted August 11, 2018 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now