Page 3 of 3

Re: Display Prices inclusive/exclusive based on currency vie

Posted: Wed Aug 15, 2012 1:03 am
by busi6292
Thanks for your help Martin. Can't get it to work but I'll live with it for the moment.

We will be moving over to BC in 9 months... :shock: - unfortunatey we have to as I don't like any other cart.

ISC is getting behind and I'm getting BC to iron out the remaining bugs WELL in advance!

Re: Display Prices inclusive/exclusive based on currency vie

Posted: Wed Aug 15, 2012 11:14 am
by Martin
Mod Note: Post removed as not relevant to topic...

Re: Display Prices inclusive/exclusive based on currency vie

Posted: Wed Aug 15, 2012 11:15 am
by Martin
busi6292 wrote:Thanks for your help Martin. Can't get it to work but I'll live with it for the moment.
Daft question, what version of ISC are you running?

... and any new log information that might help spot the issue?

Re: Display Prices inclusive/exclusive based on currency vie

Posted: Wed Aug 15, 2012 11:29 am
by busi6292
I'm running 6.1.1 but it's still the error from my message a few months ago appearing in the log. Is this file correct? The error points to something on line 17. Thank you

Re: Display Prices inclusive/exclusive based on currency vie

Posted: Wed Aug 15, 2012 1:52 pm
by Martin
busi6292 wrote:I'm running 6.1.1 but it's still the error from my message a few months ago appearing in the log. Is this file correct? The error points to something on line 17. Thank you
Most likely that you haven't updated the code in pricing.php properly.

That should have been handled by the new code, specifically this line:

Code: Select all

	if(!key_exists('CurrentCurrency', $GLOBALS) && !$currencyId) {
		return $options;
	}
I'd try replacing your existing function formatPriceDependentOnCurrency() (roughly lines 9 - 49) with this:

Code: Select all

/*
 * MOD set flag for Price format based on the currency being displayed
 * eg: If VAT set for EU/UK countries it will show inclusive for GBP/EURO
 * and exclusive for any non-VAT currencies
 */

function formatPriceDependentOnCurrency($options=array(), $currencyId=false) {

	if(!key_exists('CurrentCurrency', $GLOBALS) && !$currencyId) {
		return $options;
	}
	
	$toCurrencyId = $currencyId ? $currencyId : $GLOBALS['CurrentCurrency'];
	
	$toCurrency = GetCurrencyById($toCurrencyId);
	
	if(!in_array($toCurrency['currencycode'], array('GBP', 'EUR'))) {
		$options['displayFormat'] = TAX_PRICES_DISPLAY_EXCLUSIVE;
		$options['dropLabel'] = true;
		
		$currency2Country = array(
			'USD'	=> 'US',
			'CAD'	=> 'CA',
			'AUD'	=> 'AU'
		);
		
		if(key_exists($toCurrency['currencycode'], $currency2Country)) {
			$options['countryID'] = GetCountryIdByISO2($currency2Country[$toCurrency['currencycode']]);
/*			$GLOBALS['ISC_CLASS_LOG']->LogSystemDebug('php', "CountryISO {$currency2Country[$toCurrency['currencycode']]} CountryID : {$options['countryID']}" , 
					"New Country set based on currency : {$toCurrency['currencycode']}");
*/
		}
	}
	else {
		$options['displayFormat'] = TAX_PRICES_DISPLAY_INCLUSIVE;
		// Default back to UK to ensure pricing updates back to tax inclusive
		$options['countryID'] = GetCountryIdByISO2('GB');
	}
	return $options;
}
// MOD END
... which is the same code as I've recently updated..

Re: Display Prices inclusive/exclusive based on currency vie

Posted: Wed Aug 15, 2012 6:35 pm
by busi6292
Sorry didn't spot that code being updated. Thank you very much. That's sorted the problem.

Re: Display Prices inclusive/exclusive based on currency vie

Posted: Tue May 07, 2013 9:58 pm
by Martin
Another adjustment made to the formatPriceDependentOnCurrency() function that stops the code reverting European quotes to GB if they switch between Euro (EUR) and Sterling (GBP) currencies.

Replace the existing function with this one:

Code: Select all

/*
 * MOD set flag for Price format based on the currency being displayed
 * eg: If VAT set for EU/UK countries it will show inclusive for GBP/EURO
 * and exclusive for any non-VAT currencies
 */

function formatPriceDependentOnCurrency($options=array(), $currencyId=false) {

	if(!key_exists('CurrentCurrency', $GLOBALS) && !$currencyId) {
		return $options;
	}
	
	$toCurrencyId = $currencyId ? $currencyId : $GLOBALS['CurrentCurrency'];
	
	$toCurrency = GetCurrencyById($toCurrencyId);
	
	if(!in_array($toCurrency['currencycode'], array('GBP', 'EUR'))) {
		$options['displayFormat'] = TAX_PRICES_DISPLAY_EXCLUSIVE;
		$options['dropLabel'] = true;
		
		$currency2Country = array(
			'USD'	=> 'US',
			'CAD'	=> 'CA',
			'AUD'	=> 'AU'
		);
		
		if(key_exists($toCurrency['currencycode'], $currency2Country)) {
			$options['countryID'] = GetCountryIdByISO2($currency2Country[$toCurrency['currencycode']]);
/*
			$GLOBALS['ISC_CLASS_LOG']->LogSystemDebug('php', "CountryISO {$currency2Country[$toCurrency['currencycode']]} CountryID : {$options['countryID']}" , 
					"New Country set based on currency : {$toCurrency['currencycode']}");
*/
		}
	}
	else {
		/*
		 * Determine current country used for quote (if any)
		 * If in EU, use that as country we need.
		 * Defaults to GB otherwise
		 */
		$countryISO2 = 'GB';
		
		if(isset($_SESSION['QUOTE'])) {
			$iso2 = $_SESSION['QUOTE']->getBillingAddress()->getCountryIso2();
			$query = "SELECT countrycouregid FROM [|PREFIX|]countries WHERE countryiso2 = '{$iso2}'";
			$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
			if(!$result) {
				$GLOBALS['ISC_CLASS_LOG']->LogSystemDebug('php', "CountryISO Revert to GB or other EU country DB query failed", "SQL: ".$query);
			}
			else {
				$row = $GLOBALS['ISC_CLASS_DB']->FetchOne($result);
				if(count($row)>=1 && $row['countrycouregid'] == 1) {
					$countryISO2 = $iso2;
				}
			}
		}
		
		$options['displayFormat'] = TAX_PRICES_DISPLAY_INCLUSIVE;
		// Default back to UK to ensure pricing updates back to tax inclusive
		$options['countryID'] = GetCountryIdByISO2($countryISO2);
	}
	return $options;
}
// MOD END
The modified function, when called by a change to GBP or EUR currencies looks for any pre-existing quote information and checks to see if it's based on a country in the EU.. If it is, it will use that country information to base the price quote information on.

It will not restore a country used if the preceding currency is anything other than EUR or GBP because it would have had to set the country to Australia for AUD, U.S.A for USD, etc... in order for the quote system to work properly.