Magento Forum

Mage/Paypal/Model/Ipn.php on line 389
 
Skivers
Jr. Member
 
Total Posts:  26
Joined:  2008-11-13
 

I’m seeing this error pop up in my error_log file after a customer checks out with Paypal. Anyone have any idea?

PHP Fatal error:  Call to a member function getIncrementId() on a non-object in public_html/XXXX/app/code/core/Mage/Paypal/Model/Ipn.php on line 389

Line 389 in IPN.php

// notify customer
if ($invoice = $payment->getCreatedInvoice() && !$this->_order->getEmailSent()) {
$comment = $this->_order->sendNewOrderEmail()->addStatusHistoryComment(
Mage::helper(’paypal’)->__(’Notified customer about invoice #%s.’, $invoice->getIncrementId())
)
->setIsCustomerNotified(true)
->save();
}

It also seems the order confirmation email does not show the items ordered in the email. Everything else is there.

This does not happen with other types of payment methods.

Anyone?

 
Magento Community Magento Community
Magento Community
Magento Community
 
TEmelie
Jr. Member
 
Total Posts:  12
Joined:  2010-09-08
 

I’m getting the same error. Any ideas ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Andre N
Sr. Member
 
Avatar
Total Posts:  186
Joined:  2009-12-09
CA
 

I’m getting this error too in 1.6.0.1 rc-1

In Mage Paypal Model Ipn you have:

// notify customer
        if ($invoice $payment->getCreatedInvoice() && !$this->_order->getEmailSent()) {
            $comment 
$this->_order->sendNewOrderEmail()->addStatusHistoryComment(
                    
Mage::helper('paypal')->__('Notified customer about invoice #%s.'$invoice->getIncrementId())
                )
                ->
setIsCustomerNotified(true)
                ->
save();
        
}
It looks like what was intended was to initialize the $invoice object AND make sure the email wasn’t already sent but,
it seems to me as if this portion
$invoice $payment->getCreatedInvoice() && !$this->_order->getEmailSent()

would cause the $invoice object to be instantiated as a boolean (object &&’d with boolean)

Then when it tries to get the invoice #

$invoice->getIncrementId()

it throws the fatal error ‘Call to a member function getIncrementId() on a non-object’ because $invoice is not an object, it is a boolean.

I rewrote this portion of code as follows:

// notify customer
        if (!$this->_order->getEmailSent()) {
            $invoice 
$payment->getCreatedInvoice();
            
$comment $this->_order->sendNewOrderEmail()->addStatusHistoryComment(
                    
Mage::helper('paypal')->__('Notified customer about invoice #%s.'$invoice->getIncrementId())
                )
                ->
setIsCustomerNotified(true)
                ->
save();
        
}
Which will do the same thing and should fix the problem… hopefully smile
 
Magento Community Magento Community
Magento Community
Magento Community
 
TEmelie
Jr. Member
 
Total Posts:  12
Joined:  2010-09-08
 

Thanks! I just modified the code smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
gbarnolas
Jr. Member
 
Total Posts:  2
Joined:  2011-02-07
 

Hi to all,

I have the same problem. Thanks for your reply Andre, if it works that’s great, but the line:

$invoice $payment->getCreatedInvoice() && !$this->_order->getEmailSent()

doesn’t instantiate $invoice as boolean. $invoice will always be what $payment->getCreatedInvoice() returns. That line is used because many methods return “false” when something goes wrong. The problem here is that probably getCreatedInvoice() is not returning an object, and neither “false”.

Regards, Guillem.

 
Magento Community Magento Community
Magento Community
Magento Community
 
gbarnolas
Jr. Member
 
Total Posts:  2
Joined:  2011-02-07
 

Sorry, after reviewing your code, it will also fail (the reason is what I told you in my previous message). If

$invoice $payment->getCreatedInvoice();

doesn\’t return an object of class Mage_Sales_Model_Invoice, then

$invoice->getIncrementId();

will also fail.

You can check that with

if ($invoice instanceof Mage_Sales_Model_Invoice){
....
}

that will always work.

Regards, Guillem.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mChelevich
Jr. Member
 
Avatar
Total Posts:  20
Joined:  2009-03-31
 

Unfortunately && has bigger priority in PHP than =
So the expression elements are compared first, we get boolean and it goes to $invoice
http://www.php.net/manual/en/language.operators.precedence.php#102341

For quick fix you may just replace && with AND
Or move out the $invoice initialization above the if-statement.

 
Magento Community Magento Community
Magento Community
Magento Community
 
linuxconsult
Jr. Member
 
Total Posts:  17
Joined:  2010-03-02
 

Hello,

We had the same bug, we just changed the && by AND , there is no more error in the logs but the invoice is still not send,
And even with the $invoice = $payment->getCreatedInvoice(); before the if statement, the mail is still not sent

Any suggestion ?

Thanks for your help

 
Magento Community Magento Community
Magento Community
Magento Community
 
cahein
Jr. Member
 
Total Posts:  3
Joined:  2009-05-07
 

This is not a fix, but the error is avoided.

if ($invoice $payment->getCreatedInvoice() && !$this->_order->getEmailSent()) {
            $this
->_order->sendNewOrderEmail()
                ->
addStatusHistoryComment('invoice incrementId error')
                ->
setIsCustomerNotified(true)
                ->
save();
}

The history comment is changed from
Mage::helper(’paypal’)->__(’Notified customer about invoice #%s.’, $invoice->getIncrementId()
to
‘invoice incrementid error’

Don’t know of any further problems resulting from this change. We are not sure why it needs a invoice created at this point.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jEzEk CHiCKi
Jr. Member
 
Avatar
Total Posts:  4
Joined:  2011-01-24
 

I think better solution is to add parenthesis, like this:

// notify customer
        if (($invoice $payment->getCreatedInvoice()) && !$this->_order->getEmailSent()) {
            $comment 
$this->_order->sendNewOrderEmail()->addStatusHistoryComment(
                    
Mage::helper('paypal')->__('Notified customer about invoice #%s.'$invoice->getIncrementId())
                )
                ->
setIsCustomerNotified(true)
                ->
save();
        
}

cause your solution does not check if $invoice is not false.

Andre N - 31 October 2011 05:37 PM

I’m getting this error too in 1.6.0.1 rc-1

In Mage Paypal Model Ipn you have:

// notify customer
        if ($invoice $payment->getCreatedInvoice() && !$this->_order->getEmailSent()) {
            $comment 
$this->_order->sendNewOrderEmail()->addStatusHistoryComment(
                    
Mage::helper('paypal')->__('Notified customer about invoice #%s.'$invoice->getIncrementId())
                )
                ->
setIsCustomerNotified(true)
                ->
save();
        
}
It looks like what was intended was to initialize the $invoice object AND make sure the email wasn’t already sent but,
it seems to me as if this portion
$invoice $payment->getCreatedInvoice() && !$this->_order->getEmailSent()

would cause the $invoice object to be instantiated as a boolean (object &&’d with boolean)

Then when it tries to get the invoice #
$invoice->getIncrementId()

it throws the fatal error ‘Call to a member function getIncrementId() on a non-object’ because $invoice is not an object, it is a boolean.

I rewrote this portion of code as follows:
// notify customer
        if (!$this->_order->getEmailSent()) {
            $invoice 
$payment->getCreatedInvoice();
            
$comment $this->_order->sendNewOrderEmail()->addStatusHistoryComment(
                    
Mage::helper('paypal')->__('Notified customer about invoice #%s.'$invoice->getIncrementId())
                )
                ->
setIsCustomerNotified(true)
                ->
save();
        
}
Which will do the same thing and should fix the problem… hopefully smile
 
Magento Community Magento Community
Magento Community
Magento Community
 
loeffel
Guru
 
Avatar
Total Posts:  427
Joined:  2009-02-03
 

I replaced && with AND and am now occasionally seeing this notice:

2013-08-13T20:57:36+00:00 ERR (3): Notice: Undefined index: invoice [...]/app/code/local/Mage/Paypal/Model/Ipn.php on line 171

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top