如何在Magento的观察员中获得付款方式?

时间:2011-05-31 20:16:05

标签: magento paypal observer-pattern

我有一个处理事件的观察者:sales_payment_invoice_pay(或类似的东西)。

我要做的是,如果付款方式是PayPal,则发送发票。

版本1.4中的一切都很好〜通过$ observer-> getEvent() - > getOrder() - > getPayment-> getMethodInstance()。

在版本1.5+中,我似乎无法找到任何解决方案。 我也试过getData()但没有任何结果。

感谢任何帮助。感谢

打电话给我超级绝望的回答将是轻描淡写。

4 个答案:

答案 0 :(得分:3)

传递给sales_order_invoice_pay事件的唯一数据似乎是$this,它将是sales/order_invoice模型。我通过搜索Magneto核心代码找到了这个,它在Invoice.php中被解雇了,如下所示:

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

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

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

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

然而,看看Invoice模型,它似乎有一个很好的getOrder方法,应该可以解决这个问题。我没有测试过,但试试这个:

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

干杯,祝你好运!

答案 1 :(得分:2)

我可以使用此

获取付款方式代码
$observer->getEvent()->getInvoice()->getOrder()->getPayment()->getMethodInstance()->getCode()

答案 2 :(得分:1)

使用varien对象的debug()函数对于这样的事情是一个很好的选择..像这样:http://pastebin.com/wtdJdeLq - 我无法获得在这个网站上工作的代码,不会再费心了。检查pastebin链接。

你有order_id,像往常一样加载订单,getModel('...')(非常快),并获得付款方式。

答案 3 :(得分:0)

用户此代码:$ order-> getPayment() - > getMethodInstance() - > getCode();