2

How to login a user with an E-mail to magento2 site without triggering event customer_login.

Actually, I am able to login with email using customer session but the customer session also triggers the customer_login events.

I don't want to use a trigger.

$customer = $this->_customer->loadByEmail("[email protected]"); 

$this->_customerSession->setCustomerAsLoggedIn($customer);
1
  • Can you please upload your full code ? Commented Jul 30, 2019 at 6:49

1 Answer 1

2

To modify any default functionality of magento you can simply override it's class.

Use this reference to do the same.

In this case you have to override this method.

Magento\Customer\Model\Session::setCustomerAsLoggedIn()

Remove the line from setCustomerAsLoggedIn() function which trigger 'customer_login' event.

 $this->_eventManager->dispatch('customer_login', ['customer' => $customer]);

Your function setCustomerAsLoggedIn will look like this.

 public function setCustomerAsLoggedIn($customer)
{
    $this->setCustomer($customer);
    $this->_eventManager->dispatch('customer_data_object_login', ['customer' => $this->getCustomerDataObject()]);
    $this->regenerateId();
    return $this;
}

I hope it will helps you. And let me know if you need further help.

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.