首先让我解释一下自己。我是Prestashop Development的新手,我是使用Wordpress的背景。问题是,我试图勾选“blockcart.php”。到我的自定义钩子' HOOK_SHOPPINGBAG'。我已经尝试了很多,几个小时后我决定在这里问这个问题。
首先,我在Prestashop数据库中的ps_hook中创建了Hook。这个钩子正在运行,Prestashop读取它。之后我将我的新钩子添加到FrontController.php,代码如下所示:
public function initContent()
{
$this->process();
if (!isset($this->context->cart))
$this->context->cart = new Cart();
if (!$this->useMobileTheme())
{
// These hooks aren't used for the mobile theme.
// Needed hooks are called in the tpl files.
$this->context->smarty->assign(array(
'HOOK_HEADER' => Hook::exec('displayHeader'),
'HOOK_TOP' => Hook::exec('displayTop'),
'HOOK_SHOPPINGBAG' => Hook::exec('displayShoppingBag'),
'HOOK_LEFT_COLUMN' => ($this->display_column_left ? Hook::exec('displayLeftColumn') : ''),
'HOOK_RIGHT_COLUMN' => ($this->display_column_right ? Hook::exec('displayRightColumn', array('cart' => $this->context->cart)) : ''),
));
}
else
$this->context->smarty->assign('HOOK_MOBILE_HEADER', Hook::exec('displayMobileHeader'));
}
我还将Hook添加到FrontController.php中的第二行:
// Call hook before assign of css_files and js_files in order to include correctly all css and javascript files
$this->context->smarty->assign(array(
'HOOK_HEADER' => $hook_header,
'HOOK_TOP' => Hook::exec('displayTop'),
'HOOK_SHOPPINGBAG' => Hook::exec('displayShoppingBag'),
'HOOK_LEFT_COLUMN' => ($this->display_column_left ? Hook::exec('displayLeftColumn') : ''),
'HOOK_RIGHT_COLUMN' => ($this->display_column_right ? Hook::exec('displayRightColumn', array('cart' => $this->context->cart)) : ''),
'HOOK_FOOTER' => Hook::exec('displayFooter')
));
我想在header.tpl中显示Cart,所以我已将Hook添加到此文件中:
<div class="shoppingbag">
{$HOOK_SHOPPINGBAG}
</div>
为了确保Blockcart.php可以挂钩到我的新钩子,我已将以下行添加到blockcart.php:
public function hookShoppingBag($params) {
return $this->hookheader($params, 'displayShoppingBag');
}
我已经尝试了很多东西,但当我尝试将模块挂钩到新的Hook时,它一直告诉我&#34;这个模块无法移植到这个钩子!&#34;
也许我刚刚犯了一些愚蠢的错误,但无论如何我希望你们能帮助我。谢谢!
答案 0 :(得分:0)
我假设您需要将blockcart模块的自定义挂钩放置在某处。
这是通过Presta的自定义挂钩方式实现的。
|| $this->registerHook('shoppingBag') == false
将此添加到模块的安装方法。
public function install()
{
if (
parent::install() == false
|| $this->registerHook('top') == false
|| $this->registerHook('header') == false
|| $this->registerHook('actionCartListOverride') == false
|| Configuration::updateValue('PS_BLOCK_CART_AJAX', 1) == false
|| Configuration::updateValue('PS_BLOCK_CART_XSELL_LIMIT', 12) == false)
|| $this->registerHook('shoppingBag') == false
return false;
return true;
}
像这样创建一个公共方法hookShoppingBag。
public function hookShoppingBag($params)
{
return $this->hookProductActions($params);
}
要将它挂钩到任何tpl使用它。
<div class="shoppingbag">
{hook h='presetWishlist'}
</div>