Question

How to redirect the customer to the signin/signup page if not logged in before proceeding to checkout?

Was it helpful?

Solution

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();
    }
    ...
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top