I am trying to handle events in Opencart-3 to move data to a local ERP system. I created an extension that contains all the events that I need to handle, My problem is that, only the events related to products are being triggered, but the others are not triggered.
<?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 );
}
}
DO I need to create a new extension for the Catalog section (customer and product events), and register them in a different extension? Or what am I missing.
For events which related to catalog in your case, you should create file in this folder. catalog/controller/extension/module
named erp_integration.php
with content:
<?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 );
}
}
And your testing.txt you can find in the root of installation of the OC