1
votes

I have an observer that handles the event: sales_payment_invoice_pay (or something like that).

What I'm trying to do is to send an invoice if the payment method is PayPal.

Everything is ok in version 1.4~ by doing $observer->getEvent()->getOrder()->getPayment->getMethodInstance().

In version 1.5+ however I can't seem to find any solutions. I also tried with getData() but without any results.

Any help is appreciated. thanks

Calling me super desperate for an answer would be an understatement.

4

4 Answers

3
votes

It looks like the only data passed in to the sales_order_invoice_pay event is $this, which will be the sales/order_invoice model. I found this by searching through the Magneto core code, it's fired off in Invoice.php like so:

Mage::dispatchEvent('sales_order_invoice_pay', array($this->_eventObject=>$this));

Looking at a similar event (sales_order_invoice_register) which has an observer in the core (of Enterprise, at least - increaseOrderGiftCardInvoicedAmount() in GiftCardAccount) you can access the Invoice object like this in your Observer method:

$invoice = $observer->getEvent()->getInvoice();

The invoice is all you will be able to get though, since it's the only thing passed to the Observers by dispatchEvent(). You cannot directly access the order, like you are trying to do.

Looking at the Invoice model, however, it appears to have a nice getOrder method, which should do the trick. I haven't tested it, but try this:

$observer->getEvent()->getInvoice()->getOrder()->getPayment->getMethodInstance();

Cheers and good luck!

2
votes

i can get the payment method code using this

$observer->getEvent()->getInvoice()->getOrder()->getPayment()->getMethodInstance()->getCode()
1
votes

Using the debug() function of varien object is a good choice for such things.. like this: http://pastebin.com/wtdJdeLq - I can't get the code thingie to work on this site, not gonna bother trying anymore. Check the pastebin link.

There you have the order_id, load the order like you normally would, getModel('...') (is pretty fast), and get the payment method.

0
votes

user this code:$order->getPayment()->getMethodInstance()->getCode() ;