Code: Select all
/**
* Convert a price to a specific currency, optionally using a forced exchange rate instead of the
* current one for this currency, and optionally from a specific currency.
*
* @param float The price to convert.
* @param mixed The currency to convert to. If not passed, the current currency is used, if an integer, the currency will be looked up.
* @param mixed If null, the exchange rate for the convert to currency will be used, if a float/decimal, this exchange rate will be used in preference.
* @param mixed If null, it will be assumed that the price is in the default/base currency and doesn't need normalising first. If an integer, the currency will be loaded up.
* @return float The currency converted price.
*/
function ConvertPriceToCurrency($price, $toCurrency=null, $forcedExchangeRate=null, $fromCurrency=null)
{
if($fromCurrency != null) {
if(!is_array($fromCurrency)) {
$fromCurrency = GetCurrencyById($fromCurrency);
}
}
if($toCurrency == null) {
if(!isset($GLOBALS['CurrentCurrency'])) {
$toCurrency = GetDefaultCurrency();
}
else {
$toCurrency = GetCurrencyById($GLOBALS['CurrentCurrency']);
}
}
else if(!is_array($toCurrency)) {
$toCurrency = GetCurrencyById($toCurrency);
}
if(!isset($toCurrency['currencyid'])) {
return $price;
}
if(!is_null($forcedExchangeRate)) {
$toCorrency['currencyexchangerate'] = $forcedExchangeRate;
}
$price *= $toCurrency['currencyexchangerate'];
return $price;
}
I suspect this is because nobody in the dev team expects the function to be used to translate anything other than a default currency value to something foreign.