Magento: Get User Details

By Avinash

April 23, 2013Tips & Tricks2 Comments

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

// 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(); }
// 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();
   
}

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

Share This Article

Tags:
  • Cathlyn

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

  • http://www.biztechconsultancy.com/magento-development.htm Magento Development

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