Jump to content

Using $This When Not In Object Context


Recommended Posts

Hello.

I saw this post on the forum.

https://www.prestashop.com/forums/topic/170209-how-can-i-publish-the-price-in-2-different-currencies-at-same-time/?p=1769361

And I tried implement a code with my modification.

Function:

public static function ConvertPrice($value,$currencyFrom,$currencyTo){
        $currency_from = new currency($currencyFrom);
        $currency_to = new Currency($currencyTo);
	include_once(_PS_GEOIP_DIR_.'geoipcity.inc');
	$gi = geoip_open(realpath(_PS_GEOIP_DIR_.'GeoLiteCity.dat'), GEOIP_STANDARD);
	$record = geoip_record_by_addr($gi, Tools::getRemoteAddr());
	$country = $record->country_name;
	$this->context->smarty->assign('countryname', $country);
	return Tools::displayPrice(Tools::convertPriceFull($value,$currency_from,$currency_to),$currency_to);
}

But I've got a fatal error linked with $this->context->smarty->assign('countryname', $country);

Using $this when not in object context in /xxx/xxx/xxx/classes/controller/FrontController.php on line 1695

What is wrong with this code?

Edited by MatiPasio (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...