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

8
  • you can use Auth model for the same Commented Oct 20, 2018 at 8:50
  • Which will return details of current login user Commented Oct 20, 2018 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 Commented Oct 20, 2018 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 Commented Oct 20, 2018 at 12:25
  • use Magento\Customer\Model\Context as CustomerContext; use Magento\Customer\Model\Session as CustomerSession; Commented Oct 20, 2018 at 12:27

1 Answer 1

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();
}
3
  • 1
    I will check and update you soon...Thanks Commented Oct 20, 2018 at 12:42
  • Hi @AdityaShah Can you check my module? Commented Oct 22, 2018 at 6:19
  • Check your module ? How ? Commented Oct 22, 2018 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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