将Prestashop购物车应用于自定义挂钩
首先让我解释一下。我对Prestashop开发不熟悉,我有使用Wordpress的背景。问题是,我正在尝试将“blockcart.php”挂接到我的定制钩子“hook\u SHOPPINGBAG”。我试了很多,几个小时后我决定在这里问这个问题 首先,我在Prestashop数据库中的ps_Hook中创建了Hook。此挂钩正在运行,Prestashop会读取它。在我将新的钩子添加到FrontController.php之后,代码如下所示:将Prestashop购物车应用于自定义挂钩,prestashop,Prestashop,首先让我解释一下。我对Prestashop开发不熟悉,我有使用Wordpress的背景。问题是,我正在尝试将“blockcart.php”挂接到我的定制钩子“hook\u SHOPPINGBAG”。我试了很多,几个小时后我决定在这里问这个问题 首先,我在Prestashop数据库中的ps_Hook中创建了Hook。此挂钩正在运行,Prestashop会读取它。在我将新的钩子添加到FrontController.php之后,代码如下所示: public function initContent()
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'));
}
我还将钩子添加到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中显示购物车,因此我已将挂钩添加到此文件:
<div class="shoppingbag">
{$HOOK_SHOPPINGBAG}
</div>
我已经尝试了很多东西,但是当我尝试将模块挂接到新的钩子上时,它总是告诉我这些模块不能移植到这个钩子上
也许我刚刚犯了一些愚蠢的错误,但无论如何我希望你们能帮助我。谢谢 我假设您需要一个自定义挂钩,以便将区块车模块放置在某个位置 这是如何通过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>
我不确定你想在这里挂什么,但我认为你可能在你的模块安装方法中缺少$this->registerHook'displayShoppingBag'。这实际上告诉perstashop,当执行钩子时,调用该模块的钩子函数。否则,该函数就只是到处乱放,没有人调用它。
<div class="shoppingbag">
{hook h='presetWishlist'}
</div>