-1

我正在尝试向 Hook 添加代码,每当客户在我们的商店中成功注册时都会调用该代码。在 Prestashop 文档中显示 Hook 应该是“actionCustomerAccountAdd”。

我的模块的代码如下所示:


<?php
if (!defined('_PS_VERSION_'))
  exit;
 
class SendEmail extends Module
{
  public function __construct()
  {
    $this->name = 'SendEmail';
    $this->tab = 'front_office_features';
    $this->version = '1.0';
    $this->author = 'Philip Zadeh';
    $this->need_instance = 0;
    $this->ps_versions_compliancy = array('min' => '1.4', 'max' => '1.7');

 
    parent::__construct();
 
    $this->displayName = $this->l('SendEmail');
    $this->description = $this->l('Activate to enable activation Emails for new Customers.');
 
    $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
 
    if (!Configuration::get('SendEmail_NAME'))      
      $this->warning = $this->l('No name provided');
  }
    
    public function install()
    {
        return parent::install()
            && $this->createRequiredDBTables()
            && $this->registerHook('actionCustomerAccountAdd');
    }
    
    public function hookActionCustomerAccountAdd($params)
    {
        $this->logger->info('Hook action customer account add fired');
        echo 'hook fired';
        die();
    }
}
?>

第一部分只是模块的基本设置。在安装功能中,我正在添加 Hook。

老实说,我不太确定 createRequiredDBTables 的用途(我只是从另一篇文章中尝试了此代码行,但效果不佳)

在钩子函数中,我试图将代码添加到钩子并基本上记录一些文本。

不幸的是,您可以假设在创建新客户帐户时没有任何反应......

如果有人可以帮助我,我会很高兴

最好的问候,利亚姆

*EDIT actionObjectCustomerAddAfter 也尝试了这个钩子,也没有工作

4

1 回答 1

0

从 install 方法中删除 $this->createRequiredDBTables() 行。

据我所知,目前模块中没有这种方法,因此安装可能无法正常运行。

或者您可以将此方法添加到模块中,但我认为您不需要它。

public function createRequiredDBTables(){
   //create DB tables, or whatever
   return true;
}

所以删除该行,并尝试再次重置/安装您的模块。您的安装方法应如下所示: public function install()

  {
        return parent::install()
            && $this->registerHook('actionCustomerAccountAdd');
    }
于 2021-11-23T07:31:24.277 回答