2017-09-15 140 views

回答

0

请注意,制造商可以有多个地址。此代码只能从首地址获取国家/地区。

覆盖控制器ProductControlleroverride/controllers/front

class ProductController extends ProductControllerCore 
{ 
    public function initContent() 
    { 
     parent::initContent(); 

     if (!$this->errors) { 
      $manufacturer = new Manufacturer((int)$this->product->id_manufacturer, $this->context->language->id); 
      $manufacturerAddress = $manufacturer->getAddresses($this->context->language->id); 

      if (isset($manufacturerAddress) && $manufacturerAddress[0]['country']) { 
       $this->context->smarty->assign(array(
        'manufacturer_country' => $manufacturerAddress[0]['country'], 
       )); 
      } 
     } 
    } 
} 

而在你的TPL打印:

{$manufacturer_country|escape:'html':'UTF-8'} 

记得删除cache/class_index.php当你重写控制器。