Tips & Tricks

Magento: Get User Details

In this quick tip we will see how we can get details of logged in customer in Magento.

You can use below code snippet in any model, controller or phtml file.

Get Magento User Details

[cc lang=”php”]
// Retrieve Session Object
$session = Mage::getSingleton(‘customer/session’);

// Check if user is logged in or not.
if($session->isLoggedIn())
{
$customer = $session->getCustomer();

// Get Customer ID
echo $customer->getID();

// Get Customer Name
echo $customer->getName();

}
[/cc]

Let me know if there is any room for improvement in above code snippet.

Shares:
  • Cathlyn
    Cathlyn
    April 27, 2013 at 8:10 am

    You saved my lots of hours!!!!! thanks for sharing.!!!!!

    Reply
  • BiztechCS
    May 13, 2013 at 10:03 am

    Finally, I got the answer. My searching ended here from your post. Thanks Avinash. You solved my problem.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *