Note: I had read tons of information here and another sources, including official docs.
I have a payment extension - ex title simplepay.
- I want to know specifically if it is a way to "listen" to a system (predefined) event.
- I want to run some logic when an order status has changed.
In the admin/controller/extension/payment/simplepay.php
I have this (nothing more elsewhere):
public function install()
{
$this->load->model('setting/event');
/** addEvent($code, $trigger, $action, $status = 1, $sort_order = 0); */
$this->model_setting_event->addEvent(
'do_transaction_on_order_status_change',
'catalog/controller/api/order/history/after',
'extension/payment/simplepay/doTransactionOnOrderStatusChange');
}
public function uninstall()
{
$this->load->model('setting/event');
/** deleteEventByCode($code); */
$this->model_setting_event->deleteEventByCode('do_transaction_on_order_status_change');
}
public function doTransactionOnOrderStatusChange(&$route, &$data)
{
// testing purpose for the moment
$log = new Log('aaaaaa.log');
$log->write('Route ' . $route);
}
The event do_transaction_on_order_status_change
is properly registered in events list.
What I am doing wrong?
Nevermind!
After a while I got the point.
My method
doTransactionOnOrderStatusChange(&$route, &$data)
was writted with 3 parameters.Like
doTransactionOnOrderStatusChange(&$route, &$data, &$output)
.The problem is that OC 3+ not accept a third parameter, even if there is a "before" or an "after" event.
And another problem was the related event: it must beadmin/controller/sale/order/history/before
. (or /after)No other event on order change worked. (probably this event is the only admin event, the rest being from catalog).
Later edit
The above works only for trigger the method, but had nonsense to do what was supposed to.
So, after other research time, it was obvious that the event I need to listen to was:
catalog/controller/api/order/history/after
. (an event raised from admin, but from catalog, weird!!).To listen to that event, was need to make another controller in
catalog/controller/extension/payment/simplepay.php
then put that method (doTransactionOnOrderStatusChange
) inside it.Note that my question contains the proper event.
I hope someone will find this helpful!