Page 1 of 1

Opencart 2.0 Events

Posted: Thu Aug 28, 2014 4:41 pm
by justcurious
Can anyone (James?) provide a bit more information about, and an example of how you would implement an Opencart 2.0 Event?

From what I can gather, it is a way of adding additional methods in the model files, but not the controller files.

There are three scenarios where I can imagine adding an event may be relevant :
  • Say I have an extension that requires additional fields in the product table, I would normally use Vqmod to edit the model/catalog/product file that does this and add an additional mysql UPDATE query for the additional fields in both the addProduct and editProduct functions leaving the original queries untouched.
  • Sometimes, I want to change the output from a core function either in terms of the actual data returned or the way it is formatted; in this case I would normally (via vqmod) add a similarly named custom version of the function and edit the the calling code accordingly

    Code: Select all

    $data = $this->model_catalog_product->someFunction();
    $data = $this->model_catalog_product->myCustomisedFunction();
  • In other cases, I might want to create a completely new function within a core script, so I would simply add it to the model file using vqmod as in the above scenario and edit the controller file to add a new variable to hold the new output.
Would I use Events for all three scenarios?
  • Where would I place the code to register the events (is it added to the controller file of the script I'm editing, or the install.php file as indicated in the github Modification System wiki)?
  • How would I remove the event when the module is uninstalled (is there an uninstall.php file?)
  • Once registered, do the Events remain in place, or do they naturally expire when the next page is loaded?
A short tutorial covering the above (and any other relevant) scenarios, would be extremely useful.

Re: Opencart 2.0 Events

Posted: Fri Aug 29, 2014 2:46 pm
by sv2109
Did you see this page ... cations%29 ?
But it contains an old code for event register.

Re: Opencart 2.0 Events

Posted: Mon Sep 01, 2014 11:14 pm
by justcurious
sv2109 wrote:Did you see this page ... cations%29 ?
But it contains an old code for event register.
I did see the page you have indicated and that's what triggered the question. I hadn't seen the message that the page was out of date and was waiting to be updated, though.