12

I have made a custom module in which I have an observer file. I need to display all information about the logged in user.

migrated from stackoverflow.com Aug 6 '13 at 13:04

This question came from our site for professional and enthusiast programmers.

16

Use the event customer_login:

<customer_login>
    <observers>
        <yourobservername>
            <type>model</type>
            <class>yourmodule/path_to_class</class>
            <method>customerLogin</method>
        </yourobservername>
    </observers>
</customer_login>

Your observer class would look like this:

class YourCompany_YourModule_Model_Observer
{
    public function customerLogin($observer)
    {
        $customer = $observer->getCustomer();
    }
}
  • 1
    after i do this the getCustomer returns null. – user2656802 Aug 6 '13 at 13:31
  • See the revision. Cheers. – philwinkle Aug 6 '13 at 13:35
  • Heyy.. I am very new in magento.I also want to do same thing.Can you tell me where i have to put this code in file structure? – Happy Aug 7 '14 at 10:48
  • I want before login action when user login wrong password login. – ravi patel Sep 17 '14 at 6:56
  • @ravipatel ask a new question – philwinkle Sep 17 '14 at 7:03
1

Try This

    if($customer = Mage::getSingleton('customer/session')->isLoggedIn()) {
$customer =  Mage::getSingleton('customer/session')->getCustomer();
       $customerData = Mage::getModel('customer/customer')->load($customer->getId())->getData();
       //for firstname
       $customerFirstName = $customerData['firstname'];
    }
  • 2
    Mage::getSingleton('customer/session')->getCustomer() is enough to get customer details, then why reload customer instance again ? – Rajeev K Tomy May 17 '16 at 8:15
  • Yes it is not required . But I edited according to the code flow $customer -> getFirstname() will also work . – Vivek Khandelwal May 17 '16 at 9:03

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.