首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >处理Opencart-3事件: AddCustomer EditCustomer

处理Opencart-3事件: AddCustomer EditCustomer
EN

Stack Overflow用户
提问于 2020-04-28 05:43:11
回答 2查看 186关注 0票数 1

我正在尝试处理Opencart-3中的事件,以便将数据移动到本地ERP系统。我创建了一个包含我需要处理的所有事件的扩展,我的问题是,只有与产品相关的事件被触发,而其他事件没有被触发。

代码语言:javascript
运行
复制
<?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_add', 'admin/model/catalog/product/addProduct/after', 'extension/module/erp_integration/addProduct');
        $this->model_setting_event->addEvent('product_notification_update', 'admin/model/catalog/product/editProduct/after', 'extension/module/erp_integration/editProduct');

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

        $this->model_setting_event->addEvent('order_notification_add', '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_add');
        $this->model_setting_event->deleteEventByCode('product_notification_update');
        $this->model_setting_event->deleteEventByCode('customer_notification_add');
        $this->model_setting_event->deleteEventByCode('customer_notification_update');
        $this->model_setting_event->deleteEventByCode('order_notification_add');
    }

    // 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**********\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 );
    }
}

我是否需要为Catalog部分(客户和产品事件)创建新的扩展,并在不同的扩展中注册它们?或者我错过了什么。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-04-28 17:19:58

对于与您的案例中的目录相关的事件,您应该在此文件夹中创建文件。带有内容的名为erp_integration.phpcatalog/controller/extension/module

代码语言:javascript
运行
复制
<?php

class ControllerExtensionModuleErpIntegration extends Controller {
    private $error = array();
    // 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 );
    }

    // 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 );
    }
}

和您的testing.txt,您可以在OC的安装根目录中找到

票数 1
EN

Stack Overflow用户

发布于 2020-04-28 13:53:05

是的,对于目录事件,您应该在目录文件夹中创建一个新文件。

您的代码中存在另一个错误(与此问题无关):

请使用您的扩展名,而不是为每个事件使用不同的名称:

代码语言:javascript
运行
复制
$this->model_setting_event->addEvent('erp_integration', ...
$this->model_setting_event->addEvent('erp_integration', ...

然后,在uninstall方法中,您需要使用deleteEventByCode一次:

代码语言:javascript
运行
复制
$this->model_setting_event->deleteEventByCode('erp_integration');
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61468964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档