opencart 客户事件,未在管理端调用

opencart customer Events, not being called in admin side

我使用 OC3,并尝试处理 addCustomer 事件以将新创建​​的客户移动到 ERP 系统。我创建了一个扩展 admin/controller/extension/module/erp_integration。php 此扩展具有事件注册功能和产品集成调用。

class ControllerExtensionModuleErpIntegration extends Controller {
    private $error = array();    


    public function index() {}

    public function validate() {}

    public function install() {
        $this->load->model('setting/event');
        $this->model_setting_event->addEvent('product_notification', 'admin/model/catalog/product/addProduct/after', 'extension/module/erp_integration/addProduct');
        $this->model_setting_event->addEvent('product_notification', 'admin/model/catalog/product/editProduct/after', 'extension/module/erp_integration/editProduct');
        $this->model_setting_event->addEvent('customer_notification', 'catalog/model/account/customer/addCustomer/after', 'extension/module/erp_integration/addCustomer');
        $this->model_setting_event->addEvent('customer_notification', 'catalog/model/account/customer/editCustomer/after', 'extension/module/erp_integration/editCustomer');

        $this->model_setting_event->addEvent('order_notification', 'catalog/model/checkout/order/addOrder/after', 'extension/module/erp_integration/addOrder');
    }

    public function uninstall() {
        $this->load->model('setting/event');
        $this->model_setting_event->deleteEventByCode('product_notification');
        $this->model_setting_event->deleteEventByCode('customer_notification');
        $this->model_setting_event->deleteEventByCode('order_notification');

    }

    // admin/model/catalog/product/addProduct/after
    public function addProduct(&$route, &$args, &$output)  {
        file_put_contents ( "testing.txt","\n******ADD PRODUCT**********\n" ,FILE_APPEND );
        file_put_contents ( "testing.txt",print_r($args,true) . print_r($output,true) ,FILE_APPEND );
    }

    // admin/model/catalog/product/editProduct/after
    public function editProduct(&$route, &$args, &$output)  {
        file_put_contents ( "testing.txt","\n******EDIT PRODUCT**********\n" ,FILE_APPEND );
        file_put_contents ( "testing.txt",print_r($args,true) . print_r($output,true) ,FILE_APPEND );
    }

    // catalog/model/account/customer/addCustomer/after
    public function addCustomer(&$route, &$args, &$output)  {
        file_put_contents ( "testing.txt","\n******ADD CUSTOMER from admin**********\n" ,FILE_APPEND );
        file_put_contents ( "testing.txt",print_r($args,true) . print_r($output,true) ,FILE_APPEND );
    }

}

对于客户部分,我在 catalog/controller/extension/module/erp_integration.php 中创建了另一个文件来处理客户事件

<?php

class ControllerExtensionModuleErpIntegration extends Controller {

    // catalog/model/account/customer/addCustomer/after
    public function addCustomer(&$route, &$args, &$output)  {
        file_put_contents ( "testing.txt","\n******ADD CUSTOMER**********\n" ,FILE_APPEND );
        file_put_contents ( "testing.txt",print_r($args,true) . print_r($output,true) ,FILE_APPEND );
    }

    // catalog/model/account/customer/editCustomer/after
    public function editCustomer(&$route, &$args, &$output)  {
        file_put_contents ( "testing.txt","\n******EDIT CUSTOMER**********\n" ,FILE_APPEND );
        file_put_contents ( "testing.txt",print_r($args,true) . print_r($output,true) ,FILE_APPEND );

    }

    // catalog/model/checkout/order/addOrder/after
    public function addOrder(&$route, &$args, &$output)  {
        file_put_contents ( "testing.txt","\n******ADD ORDER**********\n" ,FILE_APPEND );
        file_put_contents ( "testing.txt",print_r($args,true) . print_r($output,true) ,FILE_APPEND );
    }
}

我面临的问题是,当用户从用户界面注册帐户时会调用客户事件。但是当我从管理部分添加新客户时,它没有被触发。

我是不是遗漏了什么?

对于管理部分,您应该将事件添加到 admin/comtroller/extension/module/erp_integration.php 这一行

$this->model_setting_event->addEvent('customer_notification_add', 'admin/model/customer/customer/addCustomer/after', 'extension/module/erp_integration/addCustomer');
 $this->model_setting_event->addEvent('customer_notification_update', 'admin/model/customer/customer/editCustomer/after', 'extension/module/erp_integration/editCustomer');

也不要忘记在这个文件中添加这个功能:

 // catalog/model/account/customer/addCustomer/after
    public function addCustomer(&$route, &$args, &$output)  {
        file_put_contents ( "testing.txt","\n******ADD CUSTOMER**********\n" ,FILE_APPEND );
        file_put_contents ( "testing.txt",print_r($args,true) . print_r($output,true) ,FILE_APPEND );
    }

    // catalog/model/account/customer/editCustomer/after
    public function editCustomer(&$route, &$args, &$output)  {
        //print_r($route); die;
        file_put_contents ( "testing.txt","\n******EDIT CUSTOMER**********\n" ,FILE_APPEND );
        file_put_contents ( "testing.txt",print_r($args,true) . print_r($output,true) ,FILE_APPEND );
    }

请注意管理和目录的事件是分开的。所以如果你需要管理端的事件,你必须为管理端添加事件...