如何在Prestashop 1.7中的自定义模块模板中获取$product变量
我正在努力与自定义模块。我想在自定义模块模板中使用$product变量 这在每个产品页面中都有效,但在类别和主页中不起作用,这给了我调试错误如何在Prestashop 1.7中的自定义模块模板中获取$product变量,prestashop,prestashop-1.7,Prestashop,Prestashop 1.7,我正在努力与自定义模块。我想在自定义模块模板中使用$product变量 这在每个产品页面中都有效,但在类别和主页中不起作用,这给了我调试错误 Notice: Undefined index: product 像 当我把它包起来的时候 {foreach from=$products item="product"} {$product.name} {/foreach} 然后$product变量起作用,但我只想显示与product匹配的变量 有什么想法吗 我通过ps_special
Notice: Undefined index: product
像
当我把它包起来的时候
{foreach from=$products item="product"}
{$product.name}
{/foreach}
然后$product变量起作用,但我只想显示与product匹配的变量
有什么想法吗
我通过ps_specials实现了产品功能,并提供了所有必要的接口,如
$products = $this->getSpecialProducts();
$this->smarty->assign(
array(
'products' => $products,
));
return false;
告诉我如何在主页和分类页中获取$product变量(在{hook h='displayProductListReviews'product=$product}中的自定义模块的钩住的自定义模板文件中)
编辑 我的函数现在看起来很正常
public function hookDisplayProductListReviews($params){
$templateFile = 'test.tpl';
$products = $this->getSpecialProducts($params['product']);
$this->context->smarty->assign(
array(
'products' => $products,
));
return $this->fetch('module:'.$this->name.'/'.$templateFile);
}
到目前为止还不错,因为
{foreach from=$products item=product} {$product->name} {/foreach}
我可以打印$product->name,但是
如果没有foreach循环打印getSpecialProducts函数(来自ps_specials模块)中收集的所有产品的名称,如何使用它
public function hookDisplayProductListReviews($params){
$products = $this->getSpecialProducts($params['product']);
}
当您使用{hook h='displayProductListReviews'product=$product})
product=$product
将在$params中,您可以使用print\r($params);模具()
查看该变量中的确切内容Hi。你的想法是正确的。我已经编辑了我的问题。也许你能告诉我更多?
public function hookDisplayProductListReviews($params){
$products = $this->getSpecialProducts($params['product']);
}