ConvertPriceToCurrency(): fromCurrency value unused

For articles specific to version 6.x
Post Reply
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

ConvertPriceToCurrency(): fromCurrency value unused

Post by Martin »

Looking at this function:

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;
}
... it seems the $fromCurrency value is completely pointless as nothing is actually done with the value other than a little data retrieval. It's not part of a class so it's not setting up an instance value so in essence there is absolutely no point in using the value as it won't do anything.

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.
Post Reply