Post by php0 » Tue Feb 18, 2025 8:13 pm

opencart 4.1.0
it is trigger work

Code: Select all

$this->model_setting_event->addEvent([
            'code'			=> $this->module,
            'description'	=> $this->description,
            'trigger'       => 'admin/view/catalog/product_form/after',
            'action'		=> $this->event.'.init',
            'status'		=> true,
            'sort_order'	=> 0
        ]);
it is trigger not work

Code: Select all

$this->model_setting_event->addEvent([
            'code'			=> $this->module,
            'description'	=> $this->description,
            'trigger'       => 'admin/model/catalog/product/addProduct/after',
            'action'		=> $this->event.'.xxx',
            'status'		=> true,
            'sort_order'	=> 0
        ]);

Newbie

Posts

Joined
Sat Nov 30, 2024 10:41 pm

Post by knowband.plugins » Tue Feb 25, 2025 10:01 pm

Hi,

The trigger admin/view/catalog/product_form/after is a view-based event that is fired after rendering the product form in the admin panel. OpenCart automatically supports admin/view/ events because it hooks into the rendering system.

The trigger admin/model/catalog/product/addProduct/after is a model-based event, meaning it should trigger after the addProduct() method is called. However, OpenCart does not automatically trigger model events unless they are explicitly registered and executed inside the model.

To make admin/model/catalog/product/addProduct/after work, follow these steps:

Step 1: Ensure the Event is Registered in the Database. If it's missing, try "$this->model_setting_event->deleteEventByCode" before the addEvent function call. This will ensure that the event is registered in the Database properly.

Step 2: Modify the method "addProduct()" (in the file, admin/model/catalog/product.php) to manually fire the event, by adding this line at the end:

Code: Select all

$this->event->trigger('admin/model/catalog/product/addProduct/after', array(&$data));
Alternatively, If the event still does not trigger, try logging the event execution, for the same use the below code as follows:

Code: Select all

public function index(&$route, &$args, &$output) {
    file_put_contents(DIR_LOGS . 'event_log.txt', "Triggered: $route\n", FILE_APPEND);
}
This will create a log file in "/storage/logs/event_log.txt" where you can check if the event is being triggered.

Please review the above information and let us know in case of any queries.

Regards,
Knowband team

User avatar
Active Member

Posts

Joined
Thu Aug 04, 2016 2:56 pm
Who is online

Users browsing this forum: No registered users and 4 guests