Post by justcurious » Thu Aug 28, 2014 4:41 pm

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

    //BEFORE
    $data = $this->model_catalog_product->someFunction();
    
    //AFTER
    $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.

Google Product Feed - Get your products into Google Shopping. Includes a bulk update facility.
Backup Pro - Backup (on demand or scheduled), Restore and Clone your store.
Freestyle Box - Add multiple information boxes on multiple pages of your store. Includes optional "Code Mode".
View my other extensions


User avatar
Active Member

Posts

Joined
Sat Dec 24, 2011 4:36 pm
Location - UK

Post by sv2109 » Fri Aug 29, 2014 2:46 pm

Did you see this page https://github.com/opencart/opencart/wi ... cations%29 ?
But it contains an old code for event register.

My php is more better than my english.

You can find my Extensions here.


User avatar
Newbie

Posts

Joined
Sun Nov 04, 2012 6:10 am
Location - Ukraine

Post by justcurious » Mon Sep 01, 2014 11:14 pm

sv2109 wrote:Did you see this page https://github.com/opencart/opencart/wi ... 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.

Google Product Feed - Get your products into Google Shopping. Includes a bulk update facility.
Backup Pro - Backup (on demand or scheduled), Restore and Clone your store.
Freestyle Box - Add multiple information boxes on multiple pages of your store. Includes optional "Code Mode".
View my other extensions


User avatar
Active Member

Posts

Joined
Sat Dec 24, 2011 4:36 pm
Location - UK
Who is online

Users browsing this forum: No registered users and 2 guests