Magento2.3.2: How to redirect customer to login page if not logged in before checkout?
-
08-03-2021 - |
Domanda
How to redirect the customer to the signin/signup page if not logged in before proceeding to checkout?
Soluzione
Magento has an option for logged in based checkout
Store -> Configuration -> Sales -> Checkout
In Checkout Options you need to select Allow Guest Checkout to "No"
This will show a login popup on cart page if the customer is not logged in. It is better than redirecting the user to the login page.
Edit
If you still want to redirect the user to login page before checkout Goto
vendor/magento/module-checkout/view/frontend/templates/onepage.phtml
Then in the top of the file use this:
//Redirect to login page if customer is not logged in
if(!$this->customerSession->isLoggedIn()) {
$this->customerSession->setAfterAuthUrl($this->urlInterface->getCurrentUrl());
$this->customerSession->authenticate();
}
...
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange