Php – Magento 1.3.2.2: Fatal error: Call to a member function getUsername() on a non-object

adminfatal errormagentoPHP

In Magento 1.3.2.2 we get a fatal error:

Fatal error: Call to a member function getUsername() on a non-object in 
.../app/design/adminhtml/default/default/template/page/header.phtml on line 31

During an order confirmation, Magento should make a transition to the success page. But we are getting that error instead.

An Admin header is shown with this error. If I refresh, I get to the success page where I should have been taken if everything was ok.

Best Answer

This error happens because header.phtml on line 31 has entry:

$this->getUser()->getUsername();

But getUser() method didn't return valid object. This method pretty simple and looks like this:

return Mage::getSingleton('admin/session')->getUser();

So, you should debug only one place: app/code/core/Mage/Admin/Model/Session.php Only one method setUser() object to session

public function login($username, $password, $request = null) {
    ...
    $this->setUser($user);

If user object loads and valid it is mean that you have problem with session it self:

  • check how cookies sets
  • cookies path and created time

It is not easy find the problem remotely without debugging. So I wish you success.

Related Topic