B
B
BuBux2021-02-01 23:30:20
opencart
BuBux, 2021-02-01 23:30:20

How to add an event in opencart 3.x?

You need to add an event that adds the word "Test" to the product name on the product page.
admin/controller/extension/my_module.php:

class ControllerExtensionModuleMyModule extends Controller {
    public function install() {
        $this->load->model('setting/event'); 
        $this->model_setting_event->addEvent('my_module', 'catalog/view/theme/default/product/product/before', 'extension/module/my_module/index');
    }

    public function uninstall() {
        $this->load->model('setting/event');
        $this->model_setting_event->deleteEventByCode('my_module');
    }
}

catalog/controller/extension/module/my_module.php:
class ControllerExtensionModuleMyModule extends Controller {
    public function index(&$route, &$data){
        if ($data && isset($this->request->get['product_id'])) {
            $data['heading_title'] = $data['heading_title'] . " TEST";
            return $data;
        }
    }
}

Adding this code does not change anything.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VVCh, 2021-02-07
@VVCh

you entered the event code
catalog/view/product/product/before incorrectly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question