0

I am getting below error

Magento 2 : Call to a member function getCustomerIsGuest() on null error

on Magento\CustomerBalance\Model\Balance class

In local environment on protected function _ensureCustomer() method i get order data by $this->getOrder() but in live it causes error, i am not sure if $this->getOrder() method exist for this class and in _ensureCustomer() method.

Any advice or thoughts ?

1
  • Any advice or thoughts ?
    – devhs
    Commented Mar 19, 2021 at 7:55

1 Answer 1

1
class A{
    public function foo(){
        echo "foo";
    }

    public function bar(){
        if(method_exists($this, 'foo')){
            echo "method exists";
        }else{
            echo "method does not exist";
        }
    }
}

$obj = new A;
$obj->bar();

but in your case the method or function you are passing on an object is Null. Wrap it to is_null($oject)

Might this help you

13
  • Thanks for the answer but when i add condition it prints method not exist but on using it it gives output if(method_exists($this, 'getOrder')){ echo "method exists"; }else{ echo "method does not exist"; } echo $this->getOrder()->getId(); //i am getting data here even if it shows method not exist exit;
    – devhs
    Commented Mar 19, 2021 at 7:40
  • Any advice or thoughts ?
    – devhs
    Commented Mar 19, 2021 at 7:55
  • Then your getOrder() is not in the same class it is in another class that you have extended and see I have added the is_null method because you are looking wrong thing, please ensure you are looking it into right stuff Commented Mar 19, 2021 at 7:57
  • Its not getting into is_null , so data is their. Actually i just not want to avoid error but find where the getorder method is declared
    – devhs
    Commented Mar 19, 2021 at 8:01
  • 1
    If you use PHP Strom or VS code then add your source code to editor WS and right click and the chose go to definition Commented Mar 19, 2021 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.