0
我是新来的PHP。任何人都可以指导我如何在产品页面上显示制造商的国家名称。我做了几个实验,如重写ProductController.php和其他技巧,但失败。我也在互联网上尝试过不同的解决方案,但无法成功。提前致谢。显示制造商国家Prestashop 1.6电子商务页面的国家名称
我是新来的PHP。任何人都可以指导我如何在产品页面上显示制造商的国家名称。我做了几个实验,如重写ProductController.php和其他技巧,但失败。我也在互联网上尝试过不同的解决方案,但无法成功。提前致谢。显示制造商国家Prestashop 1.6电子商务页面的国家名称
请注意,制造商可以有多个地址。此代码只能从首地址获取国家/地区。
覆盖控制器ProductController
在override/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
当你重写控制器。