cikcak Posted November 8, 2014 Share Posted November 8, 2014 Hello, im editing cart.php class and would like to write additional IF by SUM. if ($id_carrier == 73 && $order_total >= 100 ) { do something } But I have 4 currencies. How I should write to set it in default currency? My default currency EUR , ID 1 Link to comment Share on other sites More sharing options...
PascalVG Posted November 9, 2014 Share Posted November 9, 2014 There is a function in class Tools that translates one currency to another: /** * * Convert amount from a currency to an other currency automatically * @param float $amount * @param Currency $currency_from if null we used the default currency * @param Currency $currency_to if null we used the default currency */ public static function convertPriceFull($amount, Currency $currency_from = null, Currency $currency_to = null) { if ($currency_from === $currency_to) return $amount; if ($currency_from === null) $currency_from = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); if ($currency_to === null) $currency_to = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); if ($currency_from->id == Configuration::get('PS_CURRENCY_DEFAULT')) $amount *= $currency_to->conversion_rate; else { $conversion_rate = ($currency_from->conversion_rate == 0 ? 1 : $currency_from->conversion_rate); // Convert amount to default currency (using the old currency rate) $amount = Tools::ps_round($amount / $conversion_rate, 2); // Convert to new currency $amount *= $currency_to->conversion_rate; } return Tools::ps_round($amount, 2); } (But actually, the translation to other currencies is normally done only just before displaying them on the screen, so there may not be any need to translate anything in the first place... check if the numbers are in the default currency already) pascal. 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