Magento – Getting PHP Fatal error: Call to a member function getMethodInstance() on boolean in app/code/core/Mage/Payment/Model/Observer.php on line 46

bugmagento-1.9orderspayment

I'm trying to do the following:

$order->setTotalPaid($amount);
$order->save();

But I keep getting the following error:

Call to a member function getMethodInstance() on boolean in /mnt/webdrive/foo.foo-web.net/app/code/core/Mage/Payment/Model/Observer.php on line 46

The payment is returning as a boolean! Not a null, and when I go into the orders page in the CMS, I see that a payment method had been set in the payment information! Payment Information: My Wallet Payments

What's weird is, even when I try setting the payment again with

$order->setPaymentMethod('foopayment');
$order->save();

It's giving the exact same error!

What is causing this issue?

Best Answer

if the Payment has a deleted flag, it will not be returned by the getPayment method and if there are only payments with the deleted flag, the method will return false:

https://github.com/bragento/magento-core/blob/1.9/app/code/core/Mage/Sales/Model/Order.php#L912