AbanteCart Community
AbanteCart Development => Development Help Needed => Topic started by: renato.aloi on April 06, 2017, 10:03:10 AM
-
Hi there!
I am trying to create a Hook for update method of ModelCheckoutOrder class.
$this->extensions->hk_update($this, $order_id, $order_status_id, $comment, $notify);
I have learned I must do as follows:
public function beforeModelCheckoutOrder_update() { }
I need now gain access to $order_id parameter inside my hook function. How can I do it?
Thanks in advance!
-
usually all controllers and models have public property $this->data.
You can access to it from your hook via
$this->baseObject->data
-
Thank you for the quick reply, Dmitriy!
Unfortunely that controller in question does not make use of data public member.
I found a way to solve the problem. The hook declaration must be like this in order to work properly:
public function beforeModelCheckoutOrder_update($order_id, $order_status_id, $comment, $notify)
{
$that = $this->baseObject;
$method = $this->baseObject_method;
echo print_r($order_id, true) . "<br/>";
echo print_r($order_status_id, true) . "<br/>";
echo print_r($comment, true) . "<br/>";
echo print_r($notify, true) . "<br/>";
// ...
}
I realized I was declaring the hook wrong with the first parameter $this. Then I saw this example at docs:
class ExtensionName extends Extension {
public function afterClassNameMethodName($param1, $param2) {
// hook $this->performSomeAction()
$this->hkPerformSomeAction();
}
public function performSomeAction() {
// ...
}
}
And I realized the parameter $this should be skipped...
Now is working as expected.
Thank you!