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.

2 Answers 2

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();
    }
}
5
  • 1
    after i do this the getCustomer returns null. Commented Aug 6, 2013 at 13:31
  • See the revision. Cheers.
    – philwinkle
    Commented Aug 6, 2013 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
    Commented Aug 7, 2014 at 10:48
  • I want before login action when user login wrong password login. Commented Sep 17, 2014 at 6:56
  • @ravipatel ask a new question
    – philwinkle
    Commented Sep 17, 2014 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
  • 2
    Mage::getSingleton('customer/session')->getCustomer() is enough to get customer details, then why reload customer instance again ? Commented May 17, 2016 at 8:15
  • Yes it is not required . But I edited according to the code flow $customer -> getFirstname() will also work . Commented May 17, 2016 at 9:03

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.