处理Opencart-3事件:AddCustomer EditCustomer
我正在尝试处理Opencart-3中的事件,以便将数据移动到本地ERP系统。我创建了一个扩展,它包含了我需要处理的所有事件,我的问题是,只有与产品相关的事件被触发,而其他事件没有被触发处理Opencart-3事件:AddCustomer EditCustomer,opencart,opencart-3,opencart-events,Opencart,Opencart 3,Opencart Events,我正在尝试处理Opencart-3中的事件,以便将数据移动到本地ERP系统。我创建了一个扩展,它包含了我需要处理的所有事件,我的问题是,只有与产品相关的事件被触发,而其他事件没有被触发 <?php class ControllerExtensionModuleErpIntegration extends Controller { private $error = array(); public function index() {} public functi
<?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 );
}
}
是的,对于目录事件,您应该在目录文件夹中创建一个新文件 您的代码中还有一个错误(与此问题无关): 不要为每个事件使用不同的名称,请使用扩展名:
$this->model_setting_event->addEvent('erp_integration', ...
$this->model_setting_event->addEvent('erp_integration', ...
然后在卸载
方法中,您需要使用deleteEventByCode
一次:
$this->model_setting_event->deleteEventByCode('erp_integration');
是的,对于目录事件,您应该在目录文件夹中创建一个新文件 您的代码中还有一个错误(与此问题无关): 不要为每个事件使用不同的名称,请使用扩展名:
$this->model_setting_event->addEvent('erp_integration', ...
$this->model_setting_event->addEvent('erp_integration', ...
然后在卸载
方法中,您需要使用deleteEventByCode
一次:
$this->model_setting_event->deleteEventByCode('erp_integration');
对于案例中与目录相关的事件,您应该在此文件夹中创建文件
catalog/controller/extension/module
namederp\u integration.php
,内容如下:
<?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 );
}
}
对于与您案例中的目录相关的事件,您应该在此文件夹中创建文件catalog/controller/extension/module
namederp\u integration.php
,内容如下:
<?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 );
}
}
我确实在catalog/controller/extension/module下创建了一个新文件,其中一个文件位于language文件夹中,但我无法在管理页面的Modules下的extension management屏幕中看到它,以便安装它。但我会再试一次,以测试我是否遗漏了什么…您可以使用现有的控制器文件在管理中一次性安装所有事件。您不需要单独安装它。只是在我的回答文件中提到的地方。这就是全部。并尝试编辑用户。testing.txt将在OC安装的根目录中创建。我确实在catalog/controller/extension/module下创建了一个新文件,在language文件夹中创建了一个文件,但为了安装它,我在管理页面的模块下的扩展管理屏幕中看不到它。但我会再试一次,以测试我是否遗漏了什么…您可以使用现有的控制器文件在管理中一次性安装所有事件。您不需要单独安装它。只是在我的回答文件中提到的地方。这就是全部。并尝试编辑用户。testing.txt将在OC安装的根目录中创建。