0

I have added login as customer extension.

When I login to customer from admin panel then I want also admin details on front end side. who admin login as customer.

My Magento v2.0.17

  • you can use Auth model for the same – Aditya Shah Oct 20 '18 at 8:50
  • Which will return details of current login user – Aditya Shah Oct 20 '18 at 8:51
  • When I login as a customer from admin panel then some data will show only for admin...I want to admin all details frontend side like id, name, addrss etc. @AdityaShah – Masud Shaikh Oct 20 '18 at 12:20
  • Customer login successfully from admin side...But I can't find Who admin login as a customer at frontend side. So i will show only advanced data to Admin user at frontend. @AdityaShah – Masud Shaikh Oct 20 '18 at 12:25
  • use Magento\Customer\Model\Context as CustomerContext; use Magento\Customer\Model\Session as CustomerSession; – Aditya Shah Oct 20 '18 at 12:27
1

Back-end

protected $authSession;
public function __construct(
    ....
    \Magento\Backend\Model\Auth\Session $authSession, 
    ....
) {
    ....
    $this->authSession = $authSession;
    ....
}

Get data in method

public function getCurrentUser()
{
    return $this->authSession->getUser();
}

this will give you the current logged in admin. You can later get the details like $user->getUsername() or $user->getEmail()

Front-end

protected $_session;
protected $_context;

public function __construct(
    \Magento\Customer\Model\Session $session,
    \Magento\Framework\View\Element\Template\Context $context
) {     
    parent::__construct($context);
    $this->objectManager = $context->getObjectManager();
} 


public function isCustomerLoggedIn()
{
    $session = $this->objectManager->get('Magento\Customer\Model\Session');    
    return $session->isLoggedIn();
}

public function getCustomerId(){
    $session = $this->objectManager->get('Magento\Customer\Model\Session');    
    return $session->getCustomer()->getId();
}
  • 1
    I will check and update you soon...Thanks – Masud Shaikh Oct 20 '18 at 12:42
  • Hi @AdityaShah Can you check my module? – Masud Shaikh Oct 22 '18 at 6:19
  • Check your module ? How ? – Aditya Shah Oct 22 '18 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.