I need to work with visitor country code in product.tpl. Is there any prestashop global variable with country code, which I can use in smarty template? If not, where I can add it?
Geoip in prestashop smarty template
2.5k Views Asked by stix At
3
There are 3 best solutions below
0

I used @Raza's code to build it as an override to the FrontController with the purpose to not only display it in product.tpl but on all shop pages:
- in override > classes > controller > create file FrontController.php
put following code
class FrontController extends FrontControllerCore { public function initContent() { parent::initContent(); 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()); $this->context->smarty->assign('country_name', $record->country_name); //change country_name to code etc } }
@Raza: using {$country_name} in the .tpl-file displays the country name allways in English. Any idea how to use the PS's core translations to the country in the active shop language?
thanks
To do this first go to
Preferences>>Geolocation
and enable it also download .dat fileafter this add this code in
controllers >> front >> ProductController.php
before line 238add this code in smarty assign around line 260
Use
$country_name
in product.tpl where ever you want :)tested in ps-1.5.6