-1

The code bellow isn't working on product listing page:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

  $customerSession = $objectManager->get('Magento\Customer\Model\Session');

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

Source ref: How to check if customer is logged in or not in magento 2? Any help! appreciated!

kunj
  • 3,699
  • 2
  • 10
  • 25
Juliano Vargas
  • 2,521
  • 3
  • 25
  • 81

2 Answers2

0

Try this code :

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $customerSession = $objectManager->create('Magento\Customer\Model\Session');


if ($customerSession->isLoggedIn()) {
    $customerSession->getCustomerId();
    $customerSession->getCustomer();
    $customerSession->getCustomerData();

    echo $customerSession->getCustomer()->getName();  
    echo $customerSession->getCustomer()->getEmail();
}
Nikunj Vadariya
  • 4,037
  • 1
  • 20
  • 30
0

Its working for me on list.phtml when create a new instance of object $objectManager->create('Magento\Customer\Model\Session');