PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 16, 2022

[FIXED] How can we use opencart events?

 October 16, 2022     opencart, opencart-events, opencart2.x, php     No comments   

Issue

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):

  • first we need to register an event listener, like this:

    $this->event->register('post.order.history.add', 'checkout/order/send_email');

  • on certain places an event is triggered, e.g.

    $this->event->trigger('pre.order.history.add', $order_id);

    and

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

  • if the event (identified by it's name post.order.history.add) listener was registered it will be invoked on trigger

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).



Answered By - shadyyx
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing