phpopencartopencart2.xopencart-events

How can we use opencart events?


I have searched a lot about opencart triggers but didn't find a proper example. In opencart 2.0 there are triggers on which developer can hook function and perform something just like wordpress action and filters i guess. For example in

catalog/model/checkout/order.php

there is a trigger $this->event->trigger('post.order.history.add', $order_id)

Can someone help me to hook my function on the above trigger?


Solution

  • Important Note: this answer applies to OC >2.0.x.x and <2.2.x.x.

    The problem here is a wrong word being used (and searched for) - the right one you should be searching for is event, and from it derived event listener and trigger event (unfortunately, hadn't luck when trying to search for those either and the documentation for 2.0 is still missing).

    Now I believe the whole background is much more understandable, especially if you have some knowledge about events from other frameworks (maybe jQuery?) but here is just a quick guide how to work with events (in OC 2.0):

    For more information or to figure it out on your own you may have a look into system/engine/event.php (there is nothing more to work with right now).