簡體   English   中英

Prestashop 如何使用模塊將代碼添加到 Hook

[英]Prestashop how to add Code to Hook with Module

我正在嘗試向 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();
    }
}
?>

第一部分只是模塊的基本設置。 在安裝 function 時,我正在添加 Hook。

老實說,我不太確定 createRequiredDBTables 的用途(我只是從另一篇文章中嘗試了此代碼行,但效果不佳)

在鈎子 function 我試圖將代碼添加到鈎子並基本上記錄一些文本。

不幸的是,您可以假設在創建新客戶帳戶時沒有任何反應......

如果有人可以幫助我,我會很高興

最好的問候,利亞姆

*EDIT actionObjectCustomerAddAfter 也嘗試了這個鈎子,也沒有工作

從 install 方法中刪除 $this->createRequiredDBTables() 行。

據我所知,目前模塊中沒有這種方法,因此安裝可能無法正常運行。

或者您可以將此方法添加到模塊中,但我認為您不需要它。

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

所以刪除該行,並嘗試再次重置/安裝您的模塊。 您的安裝方法應如下所示: public function install()

  {
        return parent::install()
            && $this->registerHook('actionCustomerAccountAdd');
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM