0

我需要使用 product.tpl 中的访客国家代码。是否有任何带有国家代码的 prestashop 全局变量,我可以在 smarty 模板中使用?如果没有,我可以在哪里添加它?

4

3 回答 3

1

为此,首先转到Preferences>>Geolocation并启用它还下载 .dat 文件

controllers >> front >> ProductController.php在此之后在第 238 行之前添加此代码

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()); 

在第 260 行附近的 smarty assign 中添加此代码

'country_name' => $record->country_name //change country_name to code etc

$country_name在您想要的任何地方使用product.tpl :)

在 ps-1.5.6 中测试

于 2013-12-11T07:44:39.743 回答
0

@nortonOn:您可以尝试使用 cookie 中的 id_lang ,这样,它应该以商店语言显示国家/地区名称。应该看起来像:$country->name[intval($this->context->cookie->id_lang)];

我希望它会帮助你:)

于 2016-05-10T08:57:41.863 回答
0

我使用@Raza 的代码将其构建为对 FrontController 的覆盖,目的不仅是在 product.tpl 中显示它,而且在所有商店页面上显示它:

  1. 在覆盖 > 类 > 控制器 > 创建文件 FrontController.php
  2. 输入以下代码

    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:在 .tpl 文件中使用 {$country_name} 始终以英文显示国家/地区名称。知道如何以活跃的商店语言使用 PS 对国家/地区的核心翻译吗?

谢谢

于 2016-02-22T22:34:27.310 回答