Question

While a user who is not logged in, clicks Proceed to checkout, I want them to be taken to the login page. Then, after they've logged in or registered, they should be taken back to the checkout page. in Magento-1 it's possible app/design/frontend/base/default/template/checkout/onepage.phtml.

<?php
          if (!$this->helper('customer')->isLoggedIn()) {
                 header("Location: /customer/account/login/");
                 exit();
          }
   ?>

how can I do same task in Magento2.

Was it helpful?

Solution

For your Requirement , Better Option is Disable Gust Order.

https://docs.magento.com/m2/ce/user_guide/sales/checkout-guest.html

By default, the guest checkout in Magento is enabled and visitors can place an order without registering to the website. Some websites require mandatory login for placing orders, and this default feature should be turned off to disallow guest checkout.

To disable guest checkout, navigate to:

System > Configuration > Sales section > Checkout > Checkout Options

Set Allow Guest Checkout to No

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top