首页 > 解决方案 > 如何在 Prestashop 1.7 registerHook('customerAccount') 中使用它?

问题描述

如何使用这个 displayCustomerAccount ?我想在这里显示一些信息 /index.php?controller=my-account

标签: prestashop-1.7

解决方案


我不确定你到底想做什么,但这个钩子是专门用来在 index.php?controller=my-account 的页面上添加链接的,而不是任何类型的文本或信息。

无论如何,要在此页面上添加元素,首先通过在模块类的安装函数中添加 $this->registerHook('customerAccount') 将模块挂钩到 customerAccount,如下所示:

public function install()
{
    if (!parent::install() ||
        !$this->registerHook('customerAccount')
    ) {
        return false;
    }

    return true;
}

然后将以下函数添加到模块的类中

public function hookCustomerAccount()
{
    $this->smarty->assign(array(
        'your_link' => $your_link,
        'any_variable_needed' => $any_variable_needed
    ));

    return $this->display(__FILE__, 'my_account.tpl');
}

最后,创建一个新的 tpl 文件 your_module_folder\views\templates\hook\my_account.tpl 并在其中添加您的信息。正如我之前所说,通常你会找到这样的链接:

<a class="col-lg-4 col-md-6 col-sm-6 col-xs-12" id="your_id" href="{$your_link|escape:'htmlall':'UTF-8'}">
      <span class="link-item">
        <i class="material-icons">&#xE850;</i>
          {l s='Your link' mod='your_module'}
      </span>
</a>

推荐阅读