如何在Magento的观察员中获得付款方式? [英] How to get payment method in an observer in Magento?

查看:97
本文介绍了如何在Magento的观察员中获得付款方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个负责处理该事件的观察员:sales_payment_invoice_pay(或类似的东西).

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

如果付款方式为PayPal,我要发送发票.

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

通过$ observer-> getEvent()-> getOrder()-> getPayment-> getMethodInstance(),一切在1.4版本中都是可以的.

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

在1.5版或更高版本中,我似乎找不到任何解决方案. 我也尝试过使用getData(),但没有任何结果.

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

感谢您的帮助.谢谢

叫我绝望地回答我会轻描淡写.

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

推荐答案

看起来,传递给sales_order_invoice_pay事件的唯一数据是$this,它将成为sales/order_invoice模型.我通过搜索Magneto核心代码发现了这一点,它像这样在Invoice.php中被触发了:

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));

查看类似事件(sales_order_invoice_register),该事件具有观察者(在Enterprise中为核心,至少在GiftCardAccount中为-increaseOrderGiftCardInvoicedAmount()),您可以在Observer方法中访问类似这样的Invoice对象:

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();

发票是您将能够获得的全部,因为它是dispatchEvent()传递给观察员的唯一内容.您无法像尝试那样直接访问订单.

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.

但是,看看Invoice模型,它似乎有一个不错的getOrder方法,应该可以解决问题.我还没有测试过,但是尝试一下:

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();

干杯,祝你好运!

这篇关于如何在Magento的观察员中获得付款方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆