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("test@m2s.com"); 

$this->_customerSession->setCustomerAsLoggedIn($customer);
  • Can you please upload your full code ? – Rohan Hapani Jul 30 '19 at 6:49
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.

| improve this answer | |

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.