使用Prestashop 1.6在模块中获取产品类别名称

Han*_*nny 1 php module prestashop prestashop-1.6

我为prestashop创建了自己的模块(目前非常基本).

我想为产品添加一些自定义(类似于属性向导专业版)终极目标:我希望我的模块在产品页面上显示一个小表格,具体取决于产品所在的类别(每个类别的形式略有不同) - 购买产品时,将保存该表格的结果.

我想把表单放在RightColumnProduct中 - 我可以通过在这个钩子中访问它并调用我创建的TPL来做到这一点.

public function hookDisplayRightColumnProduct()
{
    /* Place your code here. */
    /*Get the Current Category name to see which TPL to show*/


    return $this->display(__FILE__,'views/hooks/mytpl.tpl');
}
Run Code Online (Sandbox Code Playgroud)

我需要做的是访问当前产品的类别名称,但这很难做到.

我尝试了各种解决方案但没有成功.

小智 5

此代码段将显示默认产品类别的名称.

$product = $this->context->controller->getProduct(); $category = new Category((int)$product->id_category_default, (int)$this->context->language->id); echo $category->name;