我正在为Prestashop创建一个新的插件。插件是激活的,工作正常,除了,我不能挂钩到Prestashop产品管理(后台)的特定区域。
我正在使用这个钩子: DisplayAdminProductsMainStepLeftColumnMiddle。我可以看到它被放在prestashop的模板分枝引擎中,我正在使用它,如下所示,但内容根本没有显示出来。
奇怪的是,我可以很容易地连接到例如钩子AdminOrder,没有问题,但不是DisplayAdminProductsMainStepLeftColumnMiddle。
class my_module extends Module
{
public function __construct()
{
$this->name = "my_module";
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'my_author';
$this->need_instance = 1;
$this->ps_versions_compliancy = [
'min' => '1.6',
'max' => _PS_VERSION_,
];
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('my_module');
$this->description = $this->l('my_module');
$this->confirmUninstall = $this->l('You are about to uninstall Product addons. Wish to continue?');
}
public function install()
{
return
parent::install()
&& $this->registerHook('displayAdminProductsMainStepLeftColumnMiddle')
&& $this->registerHook('adminOrder');
}
public function uninstall()
{
return parent::uninstall();
}
public function HookDisplayAdminProductsMainStepLeftColumnMiddle() //No content is being displayed in the productpage backoffice
{
echo 'Content in hook';
}
public function HookAdminOrder() //This hook works perfectly fine
{
echo 'Content in hook';
}
}发布于 2019-07-06 18:56:32
使用return而不是echo,它将会工作
public function hookDisplayAdminProductsMainStepLeftColumnMiddle()
{
return 'Content in hook';
}并且不要忘记首先重置您的模块以注册钩子
发布于 2019-07-08 16:50:56
后来我发现,在install函数中注册钩子(尤其是后端钩子)是显式的。我只是出于测试目的在构造函数中注册了钩子(前端钩子总是以这种方式工作)。
所以我把钩子放在installer函数中,重新激活模块,然后它就能工作了。
希望这能帮助到一些人=)
https://stackoverflow.com/questions/56906687
复制相似问题