I tried to get the information about a logged customer into an observer, but I can't get it even when I get customer object and maybe it's because I have the "protected" data

In the Observer file:

$observer->getEvent()->getCustomer(); // works
DEBUG (7): Mage_Customer_Model_Customer Object
    [_eventPrefix:protected] => customer
    [_eventObject:protected] => customer
    [_errors:protected] => Array

    [_isObjectNew:protected] => 
    [_data:protected] => Array
            [website_id] => 1
            [entity_id] => 2

// Call to a member function getData() on null

How can I get the customer data?


I don't know if it's a good way to do it, but it works better:

$customer = Mage::getSingleton('customer/session')->getCustomer();
  • Can you specify which information of customer you want into observer? – Dhiren Vasoya Jul 31 '18 at 10:38
  • With the customerId could be enought – ooootramas Jul 31 '18 at 10:47

To get customer Id, you need to used this code.

$customer = $observer->getEvent()->getCustomer();
$customer_Id = $customer->getId();


$customer = $observer->getEvent()->getCustomer();
$customer_Id = $customer->getEntityId();
  • But if I didn't use the if it didn't works, it's like the code should wait a moment to load the customer – ooootramas Jul 31 '18 at 11:32
  • Which event observer you are specify? Do you mean, you do not put if condition then you didn't get infromation? – Dhiren Vasoya Jul 31 '18 at 11:35
  • I don't think the event is important. The responses are: $customer->getData(); // error, $customer is null, but if I did: if($customer){$customer->getData();} // works – ooootramas Aug 1 '18 at 6:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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