gutterboy Posted September 16, 2014 Report Posted September 16, 2014 I'm trying to create something so that when a transaction is created I trigger another function, which is working, but I'm having trouble understanding how to get the event details of the transaction. For example, in my plugin handler file I have this: public function getEvents() { return array( array( 'event' => "Transactions.add", 'callback' => array("this", "run") ) ); } public function run($event) { ob_start(); var_dump($event); $content = ob_end_clean(); file_put_contents(dirname(__FILE__) . '/output.txt', $content); } All I get in the contents of output.txt is: 1 How can I get the event details such as how much they paid etc? Quote
flangefrog Posted September 16, 2014 Report Posted September 16, 2014 If you look at the EventObject class, you should be able to call the following methods. $event->getName(); $event->getParams(); $event->getReturnVal(); A useful thing to note is that you can use print_r($event, true); and it will return the data instead of printing it. Quote
gutterboy Posted September 16, 2014 Author Report Posted September 16, 2014 If you look at the EventObject class, you should be able to call the following methods. $event->getName(); $event->getParams(); $event->getReturnVal(); A useful thing to note is that you can use print_r($event, true); and it will return the data instead of printing it. Hmmmmmm....... why doesn't the var_dump() output the object data then? Anyway....... I tried those and it didn't give me much information; $event->getParams() just returned an ID, which I assume is the id of the transaction? Quote
flangefrog Posted September 16, 2014 Report Posted September 16, 2014 The EventObject vars that store the info are protected so that might be var_dump() doesn't output them. Yes, if you look at where the transaction event is registered and triggered you can see it is the transaction id (seems there is actually a transaction.transaction_id and transaction.id, this is the former. $this->Events->register("Transactions.add", array("EventsTransactionsCallback", "add")); $this->Events->trigger(new EventObject("Transactions.add", compact("transaction_id"))); $this->Events->register("Transactions.edit", array("EventsTransactionsCallback", "edit")); $this->Events->trigger(new EventObject("Transactions.edit", compact("transaction_id"))); You can get the actual transaction like this if (!isset($this->Transactions)) Loader::loadModels($this, array("Transactions")); $this->Transactions->getByTransactionId($transaction_id); Quote
gutterboy Posted September 16, 2014 Author Report Posted September 16, 2014 The EventObject vars that store the info are protected so that might be var_dump() doesn't output them. Yes, if you look at where the transaction event is registered and triggered you can see it is the transaction id (seems there is actually a transaction.transaction_id and transaction.id, this is the former. $this->Events->register("Transactions.add", array("EventsTransactionsCallback", "add")); $this->Events->trigger(new EventObject("Transactions.add", compact("transaction_id"))); $this->Events->register("Transactions.edit", array("EventsTransactionsCallback", "edit")); $this->Events->trigger(new EventObject("Transactions.edit", compact("transaction_id"))); You can get the actual transaction like this if (!isset($this->Transactions)) Loader::loadModels($this, array("Transactions")); $this->Transactions->getByTransactionId($transaction_id); Awesome - thank you! Quote
gutterboy Posted September 16, 2014 Author Report Posted September 16, 2014 That worked but I had to change: $this->Transactions->getByTransactionId($transaction_id); to.. $this->Transactions->get($transaction_id); flangefrog 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.