2

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

1
  • 1
    Good to hear that you have resolved this :) Jul 23, 2019 at 7:21

1 Answer 1

2

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();
    }
    ...
7
  • Let me update my answer then Jul 23, 2019 at 5:45
  • Please checkout updated answer Jul 23, 2019 at 5:49
  • I don't know exactly the path for checkout controller, let me search on google, will share if I get anything Jul 23, 2019 at 6:08
  • I have edited your answer without your permission. dont mind Jul 23, 2019 at 7:22
  • 1
    That's ok, it would help others in future :) Jul 23, 2019 at 7:23

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.