Prestashop 如何在页眉上获取产品列表?

Prestashop 如何在页眉上获取产品列表?,prestashop,prestashop-1.5,prestashop-1.6,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

嗨,我正在试着做我的第一个模块

当我位于分类页面上时,我需要获得副本或相同的$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');
}
谢谢

你应该:

  • 检查列表是否已在smarty阵列中可用:
    error\u log(print\r($this->smarty,1))
  • 使用已经将产品数组传递给您的特定于Category页面的钩子(这取决于您需要做什么)。如果您需要在标题中添加一些内容,那么这可能是唯一适合您的钩子。否则,请转到
    Hook.php
    find
    exec(
    method,添加
    error\u log($Hook\u name)
    并查看在打开类别页面时执行了哪些钩子。可能有一个钩子适合您的需要
  • 使用静态
    产品::
    类别::
    函数自己获取所有产品
  • 试试这个

    $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:)

    谢谢尼莫的回答!!