如何在标题上获取产品列表?

时间:2014-11-17 23:28:41

标签: prestashop prestashop-1.5 prestashop-1.6

您好,我正试图做我的第一个模块。

当我位于类别页面时,我需要获得副本或相同的$ products数组。

我有这段代码。

public function hookHeader($params)
{

    if ('category' == $this->context->controller->php_self){

    $products = //Here I need the same products array from this category

    $this->smarty->assign('products', $products);
    }

    return $this->display(__FILE__, 'views/templates/hook/header.tpl');
}

谢谢!

2 个答案:

答案 0 :(得分:0)

你应该:

  1. 检查列表是否已在smarty数组中可用:error_log(print_r($this->smarty,1));
  2. 使用已经将产品数组传递给您的cateogry页面特定挂钩(这取决于您需要做什么)。如果你需要在标题中添加一些内容,那么这可能是你唯一的一个钩子。否则,转到Hook.php查找exec(方法,添加error_log($hook_name)并查看打开类别页面时执行的挂钩。可能有一个适合您需求的钩子。
  3. 使用静态Product::Category::功能自行获取所有产品。

答案 1 :(得分:0)

试试这个

$category = new Category (Tools::getValue('id_category'):
$products = $category->getProducts($this->context->lang->id, 0 99);

这将抓住99类产品。

为什么不能'复制'该类别的产品?因为当你调用hookHeader时它们尚未被分配,因为CategoryController在那之后

另外,请注意,将在部分中显示内容,如果要显示任何内容,则必须使用hookDisplayTop

此外,在1.6中你应该使用$ this-> context-> smarty:)

相关问题