Magento Magento2 PHP Web Development

How to Get Logged In Customer Details in Magento2

How to Get Logged In Customer Details in Magento2 June 9, 2017Leave a comment

Hello World, I am Chandra Kumar from New Delhi, India. I am professionally developer, programmer and blogger. I am the founder of WebShouters.com.

In this tutorial, we will show how you can get the logged in customer details in Magento2. After the successful login the customer information will be stored in $om->get('Magento\Customer\Model\Session'); customer session object.

The the best way is to get logged in customer in any place is use Magento \Customer\Model\Session model , we are going to use magneto object manager to access to session model as follow.

Get Logged In User Details:

The below php script will return the logged in user details.

<?php
$om = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $om->get('Magento\Customer\Model\Session');
if($customerSession->isLoggedIn()) {
  echo $customerSession->getCustomer()->getId()."<br/>";  // get Customer Id
  echo $customerSession->getCustomer()->getName()."<br/>";  // get  Full Name
  echo $customerSession->getCustomer()->getEmail()."<br/>"; // get Email Name
  echo $customerSession->getCustomer()->getGroupId()."<br/>";  // get Customer Group Id
  echo $customerSession->getCustomer();
  echo $customerSession->getCustomerData();
}  
?>
How to Get Logged In Customer Details in Magento2
5 (100%) 1 vote

(Visited 18 times, 1 visits today)

Hello World, I am Chandra Kumar from New Delhi, India. I am professionally developer, programmer and blogger. I am the founder of WebShouters.com.

Leave a Reply

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