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?
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.
gutterboy Posted September 16, 2014 Author Report Posted September 16, 2014 On 9/16/2014 at 12:04 PM, flangefrog said: 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?
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);
gutterboy Posted September 16, 2014 Author Report Posted September 16, 2014 On 9/16/2014 at 1:50 PM, flangefrog said: 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!
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
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now