1

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.

peti
  • 11
  • 1
  • 3

3 Answers3

3

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!

thaddeusmt
  • 15,410
  • 9
  • 67
  • 67
  • It isn't working unfortunately. That is how I tried it as well. – peti Jun 01 '11 at 06:10
  • Sorry it's not working yet - it's time to bust out `Mage::log()` then I guess. Make sure your Observer is firing first (nothing will work if your event isn't being triggered properly!). Then perhaps dump what `$observer->getEvent()->getInvoice()` returns, to make sure it's an Invoice. Keep working your way up that call chain until you get to `getMethodInstance`. There are lots of good articles on the web about debugging Magento, good luck. – thaddeusmt Jun 01 '11 at 12:49
2

i can get the payment method code using this

$observer->getEvent()->getInvoice()->getOrder()->getPayment()->getMethodInstance()->getCode()
Yohanes Pradono
  • 294
  • 1
  • 4
  • 16
0

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