For some reason I'm not able to get the current Invoice object in my hook. I must be doing something wrong. Here's my code in my plugin bootstrap: PHP: public function onInvoiceAfterInsert(Am_Event $event) { $invoice = $event->getReturn(); $inv_params = $invoice->public_id . "-" . $invoice->invoice_key; $this->getDi()->errorLogTable->log($inv_params); } But all it prints is the hyphen, as if the public_id and invoice_key are empty. Maybe there are properties in this event I can use to fetch the Invoice object and then access methods instead? I appreciate your guidance, thank you.
Nevermind, I figured it out. PHP: $event->getInvoice(); But I don't know what makes that method available. I don't see an method or property in the Event class called invoice. For the future, where is a good place to look to know what the returned $event might be? It does not seem to return the Invoice object explicitly. Thanks.
That method is dynamic. have a look to Am_Event::_call : PHP: public function __call($name, $arguments) { if (strpos($name, 'get')===0) { $var = lcfirst(substr($name, 3)); if (!array_key_exists($var, $this->vars)) { $id = $this->getId(); trigger_error("Event variable [$var] is not set for [$id]", E_USER_WARNING); return null; } return $this->vars[$var]; } trigger_error("Method [$name] does not exists in " . __CLASS__, E_USER_ERROR); }
Oh, ha - pretty clever! So can we use $event->get(ClassName) to get any object that called the event and included itself in the payload? Also, could you please recommend a good way to connect event hooks to plugin controllers? Because I have only been able to catch them with the Bootstrap and am not sure the best way to have the Controller notified. Thanks a lot for your time Alexander.