Magento 2 : Redirect on cart page after login





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















I want to redirect the customer to cart page after login from anywhere ex.login from checkout page or customer account login.



Anyone know how to do this?



Please help me.










share|improve this question
















bumped to the homepage by Community 10 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















    1















    I want to redirect the customer to cart page after login from anywhere ex.login from checkout page or customer account login.



    Anyone know how to do this?



    Please help me.










    share|improve this question
















    bumped to the homepage by Community 10 hours ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      1












      1








      1








      I want to redirect the customer to cart page after login from anywhere ex.login from checkout page or customer account login.



      Anyone know how to do this?



      Please help me.










      share|improve this question
















      I want to redirect the customer to cart page after login from anywhere ex.login from checkout page or customer account login.



      Anyone know how to do this?



      Please help me.







      magento2 customer redirect






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 7 '17 at 14:15









      Amit Bera

      60k1677178




      60k1677178










      asked Oct 6 '17 at 10:14









      Sneha PanchalSneha Panchal

      540325




      540325





      bumped to the homepage by Community 10 hours ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 10 hours ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          3 Answers
          3






          active

          oldest

          votes


















          0














          Step 1 : Create




          Vendor/Module/etc/frontend/events.xml




          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

          <event name="customer_login">
          <observer name="customer_login_observer" instance="VendorModuleObserverCustomerLogin" />
          </event>

          </config>


          Step 2 :




          Create Vendor/Module/Observer/CustomerLogin.php




          <?php

          namespace VendorModuleObserver;

          use MagentoFrameworkEventObserver;
          use MagentoFrameworkEventObserverInterface;

          class CustomerLogin implements ObserverInterface
          {
          protected $_responseFactory;
          protected $_url;

          public function __construct(
          MagentoFrameworkViewLayout $layout,
          MagentoFrameworkAppResponseFactory $responseFactory,
          MagentoFrameworkUrlInterface $url,
          )
          {
          $this->_layout = $layout;
          $this->_responseFactory = $responseFactory;
          $this->_url = $url;
          }

          public function execute(MagentoFrameworkEventObserver $observer)
          {
          /*$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
          $resultRedirect->setUrl('checkout/cart');
          return $resultRedirect;*/
          $RedirectUrl = $this->_url->getUrl('checkout/cart');
          $this->_responseFactory->create()->setRedirect($RedirectUrl)->sendResponse();
          die();
          }
          }





          share|improve this answer
























          • I'm using magento 2.1.8.it's not working.I'm getting 302 response from customer/ajax/login when I use your code.

            – Sneha Panchal
            Oct 6 '17 at 11:47








          • 2





            bad idea because your observer will interrupt application flow using die function.

            – Max
            Oct 6 '17 at 16:38











          • @SnehaPanchal its working with the same version

            – SagarPPanchal
            Sep 18 '18 at 6:11



















          0














          For customization after-login redirect you need to add after plugin on MagentoCustomerControllerAccountLoginPost::execute where you should check is customer logged in and create custom redirect result.



          Example



          public function afterExecute(LoginPost $subject, ResultInterface $result)
          {
          $isCustomerLoggedIn = $this->httpContext->getValue(Context::CONTEXT_AUTH);
          if ($isCustomerLoggedIn) {
          $result = $this->resultRedirectFactory->create()
          ->setPath('checkout/cart');
          }

          return $result;
          }





          share|improve this answer
























          • This is not working on checkout page with ajax login method Also It is redirecting after customer create and we want to redirect after login to cart page from checkout page.

            – Sneha Panchal
            Oct 9 '17 at 6:19











          • yes, you also need to change behavior of Magento/Checkout/view/frontend/web/js/view/authentication.js component for redirect to custom url during login via checkout page

            – Max
            Oct 9 '17 at 7:48













          • Can I use something else for module development? Because we need to install the module on different instances. Thank You!

            – Sneha Panchal
            Oct 9 '17 at 10:20











          • i do not propose to change core files, you can use some techniques for js component customization's via your modules, such as mixins for example devdocs.magento.com/guides/v2.2/javascript-dev-guide/javascript/…

            – Max
            Oct 9 '17 at 10:28





















          0














          Create events.xml from Module/etc/frontend/ folder and paste it below code.



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">

          <event name="customer_login">
          <observer name="custom_customer_login" instance="ThemeVendorNameObserverRedirectCustomerToLoginAtObserver" />
          </event>

          </config>


          And create RedirectCustomerToLoginAtObserver.php file from Module/Observer folder and paste it below code.



          <?php

          namespace ThemeVendorNameObserver;

          class RedirectCustomerToLoginAtObserver implements MagentoFrameworkEventObserverInterface
          {
          /**
          * @var MagentoFrameworkAppResponseInterface
          */
          protected $_response;

          /**
          * @var MagentoStoreModelStoreManagerInterface
          */
          protected $_storeManager;

          /**
          * @param MagentoFrameworkUrlInterface $url
          * @param MagentoStoreModelStoreManagerInterface $storeManagerInterface
          */
          public function __construct
          (
          MagentoFrameworkUrlInterface $url,
          MagentoStoreModelStoreManagerInterface $storeManagerInterface
          ){
          $this->_storeManager = $storeManagerInterface;
          $this->_url = $url;
          }

          public function execute(MagentoFrameworkEventObserver $observer)
          {
          $storeObj = $this->_storeManager->getStore(1);
          $BaseURL = $storeObj->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB);
          $url = $BaseURL . 'customer/account/login';
          $this->_response->setRedirect($url)->sendResponse();
          }
          }


          Feel free to ask if any.






          share|improve this answer





















          • 1





            bad idea because your observer will interrupt application flow using exit function.

            – Max
            Oct 6 '17 at 16:38











          • It is not working for me :(

            – Sneha Panchal
            Oct 9 '17 at 10:21











          • @SnehaPanchal let me check

            – Bojjaiah
            Oct 9 '17 at 10:37












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f196170%2fmagento-2-redirect-on-cart-page-after-login%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Step 1 : Create




          Vendor/Module/etc/frontend/events.xml




          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

          <event name="customer_login">
          <observer name="customer_login_observer" instance="VendorModuleObserverCustomerLogin" />
          </event>

          </config>


          Step 2 :




          Create Vendor/Module/Observer/CustomerLogin.php




          <?php

          namespace VendorModuleObserver;

          use MagentoFrameworkEventObserver;
          use MagentoFrameworkEventObserverInterface;

          class CustomerLogin implements ObserverInterface
          {
          protected $_responseFactory;
          protected $_url;

          public function __construct(
          MagentoFrameworkViewLayout $layout,
          MagentoFrameworkAppResponseFactory $responseFactory,
          MagentoFrameworkUrlInterface $url,
          )
          {
          $this->_layout = $layout;
          $this->_responseFactory = $responseFactory;
          $this->_url = $url;
          }

          public function execute(MagentoFrameworkEventObserver $observer)
          {
          /*$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
          $resultRedirect->setUrl('checkout/cart');
          return $resultRedirect;*/
          $RedirectUrl = $this->_url->getUrl('checkout/cart');
          $this->_responseFactory->create()->setRedirect($RedirectUrl)->sendResponse();
          die();
          }
          }





          share|improve this answer
























          • I'm using magento 2.1.8.it's not working.I'm getting 302 response from customer/ajax/login when I use your code.

            – Sneha Panchal
            Oct 6 '17 at 11:47








          • 2





            bad idea because your observer will interrupt application flow using die function.

            – Max
            Oct 6 '17 at 16:38











          • @SnehaPanchal its working with the same version

            – SagarPPanchal
            Sep 18 '18 at 6:11
















          0














          Step 1 : Create




          Vendor/Module/etc/frontend/events.xml




          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

          <event name="customer_login">
          <observer name="customer_login_observer" instance="VendorModuleObserverCustomerLogin" />
          </event>

          </config>


          Step 2 :




          Create Vendor/Module/Observer/CustomerLogin.php




          <?php

          namespace VendorModuleObserver;

          use MagentoFrameworkEventObserver;
          use MagentoFrameworkEventObserverInterface;

          class CustomerLogin implements ObserverInterface
          {
          protected $_responseFactory;
          protected $_url;

          public function __construct(
          MagentoFrameworkViewLayout $layout,
          MagentoFrameworkAppResponseFactory $responseFactory,
          MagentoFrameworkUrlInterface $url,
          )
          {
          $this->_layout = $layout;
          $this->_responseFactory = $responseFactory;
          $this->_url = $url;
          }

          public function execute(MagentoFrameworkEventObserver $observer)
          {
          /*$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
          $resultRedirect->setUrl('checkout/cart');
          return $resultRedirect;*/
          $RedirectUrl = $this->_url->getUrl('checkout/cart');
          $this->_responseFactory->create()->setRedirect($RedirectUrl)->sendResponse();
          die();
          }
          }





          share|improve this answer
























          • I'm using magento 2.1.8.it's not working.I'm getting 302 response from customer/ajax/login when I use your code.

            – Sneha Panchal
            Oct 6 '17 at 11:47








          • 2





            bad idea because your observer will interrupt application flow using die function.

            – Max
            Oct 6 '17 at 16:38











          • @SnehaPanchal its working with the same version

            – SagarPPanchal
            Sep 18 '18 at 6:11














          0












          0








          0







          Step 1 : Create




          Vendor/Module/etc/frontend/events.xml




          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

          <event name="customer_login">
          <observer name="customer_login_observer" instance="VendorModuleObserverCustomerLogin" />
          </event>

          </config>


          Step 2 :




          Create Vendor/Module/Observer/CustomerLogin.php




          <?php

          namespace VendorModuleObserver;

          use MagentoFrameworkEventObserver;
          use MagentoFrameworkEventObserverInterface;

          class CustomerLogin implements ObserverInterface
          {
          protected $_responseFactory;
          protected $_url;

          public function __construct(
          MagentoFrameworkViewLayout $layout,
          MagentoFrameworkAppResponseFactory $responseFactory,
          MagentoFrameworkUrlInterface $url,
          )
          {
          $this->_layout = $layout;
          $this->_responseFactory = $responseFactory;
          $this->_url = $url;
          }

          public function execute(MagentoFrameworkEventObserver $observer)
          {
          /*$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
          $resultRedirect->setUrl('checkout/cart');
          return $resultRedirect;*/
          $RedirectUrl = $this->_url->getUrl('checkout/cart');
          $this->_responseFactory->create()->setRedirect($RedirectUrl)->sendResponse();
          die();
          }
          }





          share|improve this answer













          Step 1 : Create




          Vendor/Module/etc/frontend/events.xml




          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

          <event name="customer_login">
          <observer name="customer_login_observer" instance="VendorModuleObserverCustomerLogin" />
          </event>

          </config>


          Step 2 :




          Create Vendor/Module/Observer/CustomerLogin.php




          <?php

          namespace VendorModuleObserver;

          use MagentoFrameworkEventObserver;
          use MagentoFrameworkEventObserverInterface;

          class CustomerLogin implements ObserverInterface
          {
          protected $_responseFactory;
          protected $_url;

          public function __construct(
          MagentoFrameworkViewLayout $layout,
          MagentoFrameworkAppResponseFactory $responseFactory,
          MagentoFrameworkUrlInterface $url,
          )
          {
          $this->_layout = $layout;
          $this->_responseFactory = $responseFactory;
          $this->_url = $url;
          }

          public function execute(MagentoFrameworkEventObserver $observer)
          {
          /*$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
          $resultRedirect->setUrl('checkout/cart');
          return $resultRedirect;*/
          $RedirectUrl = $this->_url->getUrl('checkout/cart');
          $this->_responseFactory->create()->setRedirect($RedirectUrl)->sendResponse();
          die();
          }
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Oct 6 '17 at 10:57









          Dinesh YadavDinesh Yadav

          4,0831937




          4,0831937













          • I'm using magento 2.1.8.it's not working.I'm getting 302 response from customer/ajax/login when I use your code.

            – Sneha Panchal
            Oct 6 '17 at 11:47








          • 2





            bad idea because your observer will interrupt application flow using die function.

            – Max
            Oct 6 '17 at 16:38











          • @SnehaPanchal its working with the same version

            – SagarPPanchal
            Sep 18 '18 at 6:11



















          • I'm using magento 2.1.8.it's not working.I'm getting 302 response from customer/ajax/login when I use your code.

            – Sneha Panchal
            Oct 6 '17 at 11:47








          • 2





            bad idea because your observer will interrupt application flow using die function.

            – Max
            Oct 6 '17 at 16:38











          • @SnehaPanchal its working with the same version

            – SagarPPanchal
            Sep 18 '18 at 6:11

















          I'm using magento 2.1.8.it's not working.I'm getting 302 response from customer/ajax/login when I use your code.

          – Sneha Panchal
          Oct 6 '17 at 11:47







          I'm using magento 2.1.8.it's not working.I'm getting 302 response from customer/ajax/login when I use your code.

          – Sneha Panchal
          Oct 6 '17 at 11:47






          2




          2





          bad idea because your observer will interrupt application flow using die function.

          – Max
          Oct 6 '17 at 16:38





          bad idea because your observer will interrupt application flow using die function.

          – Max
          Oct 6 '17 at 16:38













          @SnehaPanchal its working with the same version

          – SagarPPanchal
          Sep 18 '18 at 6:11





          @SnehaPanchal its working with the same version

          – SagarPPanchal
          Sep 18 '18 at 6:11













          0














          For customization after-login redirect you need to add after plugin on MagentoCustomerControllerAccountLoginPost::execute where you should check is customer logged in and create custom redirect result.



          Example



          public function afterExecute(LoginPost $subject, ResultInterface $result)
          {
          $isCustomerLoggedIn = $this->httpContext->getValue(Context::CONTEXT_AUTH);
          if ($isCustomerLoggedIn) {
          $result = $this->resultRedirectFactory->create()
          ->setPath('checkout/cart');
          }

          return $result;
          }





          share|improve this answer
























          • This is not working on checkout page with ajax login method Also It is redirecting after customer create and we want to redirect after login to cart page from checkout page.

            – Sneha Panchal
            Oct 9 '17 at 6:19











          • yes, you also need to change behavior of Magento/Checkout/view/frontend/web/js/view/authentication.js component for redirect to custom url during login via checkout page

            – Max
            Oct 9 '17 at 7:48













          • Can I use something else for module development? Because we need to install the module on different instances. Thank You!

            – Sneha Panchal
            Oct 9 '17 at 10:20











          • i do not propose to change core files, you can use some techniques for js component customization's via your modules, such as mixins for example devdocs.magento.com/guides/v2.2/javascript-dev-guide/javascript/…

            – Max
            Oct 9 '17 at 10:28


















          0














          For customization after-login redirect you need to add after plugin on MagentoCustomerControllerAccountLoginPost::execute where you should check is customer logged in and create custom redirect result.



          Example



          public function afterExecute(LoginPost $subject, ResultInterface $result)
          {
          $isCustomerLoggedIn = $this->httpContext->getValue(Context::CONTEXT_AUTH);
          if ($isCustomerLoggedIn) {
          $result = $this->resultRedirectFactory->create()
          ->setPath('checkout/cart');
          }

          return $result;
          }





          share|improve this answer
























          • This is not working on checkout page with ajax login method Also It is redirecting after customer create and we want to redirect after login to cart page from checkout page.

            – Sneha Panchal
            Oct 9 '17 at 6:19











          • yes, you also need to change behavior of Magento/Checkout/view/frontend/web/js/view/authentication.js component for redirect to custom url during login via checkout page

            – Max
            Oct 9 '17 at 7:48













          • Can I use something else for module development? Because we need to install the module on different instances. Thank You!

            – Sneha Panchal
            Oct 9 '17 at 10:20











          • i do not propose to change core files, you can use some techniques for js component customization's via your modules, such as mixins for example devdocs.magento.com/guides/v2.2/javascript-dev-guide/javascript/…

            – Max
            Oct 9 '17 at 10:28
















          0












          0








          0







          For customization after-login redirect you need to add after plugin on MagentoCustomerControllerAccountLoginPost::execute where you should check is customer logged in and create custom redirect result.



          Example



          public function afterExecute(LoginPost $subject, ResultInterface $result)
          {
          $isCustomerLoggedIn = $this->httpContext->getValue(Context::CONTEXT_AUTH);
          if ($isCustomerLoggedIn) {
          $result = $this->resultRedirectFactory->create()
          ->setPath('checkout/cart');
          }

          return $result;
          }





          share|improve this answer













          For customization after-login redirect you need to add after plugin on MagentoCustomerControllerAccountLoginPost::execute where you should check is customer logged in and create custom redirect result.



          Example



          public function afterExecute(LoginPost $subject, ResultInterface $result)
          {
          $isCustomerLoggedIn = $this->httpContext->getValue(Context::CONTEXT_AUTH);
          if ($isCustomerLoggedIn) {
          $result = $this->resultRedirectFactory->create()
          ->setPath('checkout/cart');
          }

          return $result;
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Oct 6 '17 at 16:36









          MaxMax

          2,846818




          2,846818













          • This is not working on checkout page with ajax login method Also It is redirecting after customer create and we want to redirect after login to cart page from checkout page.

            – Sneha Panchal
            Oct 9 '17 at 6:19











          • yes, you also need to change behavior of Magento/Checkout/view/frontend/web/js/view/authentication.js component for redirect to custom url during login via checkout page

            – Max
            Oct 9 '17 at 7:48













          • Can I use something else for module development? Because we need to install the module on different instances. Thank You!

            – Sneha Panchal
            Oct 9 '17 at 10:20











          • i do not propose to change core files, you can use some techniques for js component customization's via your modules, such as mixins for example devdocs.magento.com/guides/v2.2/javascript-dev-guide/javascript/…

            – Max
            Oct 9 '17 at 10:28





















          • This is not working on checkout page with ajax login method Also It is redirecting after customer create and we want to redirect after login to cart page from checkout page.

            – Sneha Panchal
            Oct 9 '17 at 6:19











          • yes, you also need to change behavior of Magento/Checkout/view/frontend/web/js/view/authentication.js component for redirect to custom url during login via checkout page

            – Max
            Oct 9 '17 at 7:48













          • Can I use something else for module development? Because we need to install the module on different instances. Thank You!

            – Sneha Panchal
            Oct 9 '17 at 10:20











          • i do not propose to change core files, you can use some techniques for js component customization's via your modules, such as mixins for example devdocs.magento.com/guides/v2.2/javascript-dev-guide/javascript/…

            – Max
            Oct 9 '17 at 10:28



















          This is not working on checkout page with ajax login method Also It is redirecting after customer create and we want to redirect after login to cart page from checkout page.

          – Sneha Panchal
          Oct 9 '17 at 6:19





          This is not working on checkout page with ajax login method Also It is redirecting after customer create and we want to redirect after login to cart page from checkout page.

          – Sneha Panchal
          Oct 9 '17 at 6:19













          yes, you also need to change behavior of Magento/Checkout/view/frontend/web/js/view/authentication.js component for redirect to custom url during login via checkout page

          – Max
          Oct 9 '17 at 7:48







          yes, you also need to change behavior of Magento/Checkout/view/frontend/web/js/view/authentication.js component for redirect to custom url during login via checkout page

          – Max
          Oct 9 '17 at 7:48















          Can I use something else for module development? Because we need to install the module on different instances. Thank You!

          – Sneha Panchal
          Oct 9 '17 at 10:20





          Can I use something else for module development? Because we need to install the module on different instances. Thank You!

          – Sneha Panchal
          Oct 9 '17 at 10:20













          i do not propose to change core files, you can use some techniques for js component customization's via your modules, such as mixins for example devdocs.magento.com/guides/v2.2/javascript-dev-guide/javascript/…

          – Max
          Oct 9 '17 at 10:28







          i do not propose to change core files, you can use some techniques for js component customization's via your modules, such as mixins for example devdocs.magento.com/guides/v2.2/javascript-dev-guide/javascript/…

          – Max
          Oct 9 '17 at 10:28













          0














          Create events.xml from Module/etc/frontend/ folder and paste it below code.



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">

          <event name="customer_login">
          <observer name="custom_customer_login" instance="ThemeVendorNameObserverRedirectCustomerToLoginAtObserver" />
          </event>

          </config>


          And create RedirectCustomerToLoginAtObserver.php file from Module/Observer folder and paste it below code.



          <?php

          namespace ThemeVendorNameObserver;

          class RedirectCustomerToLoginAtObserver implements MagentoFrameworkEventObserverInterface
          {
          /**
          * @var MagentoFrameworkAppResponseInterface
          */
          protected $_response;

          /**
          * @var MagentoStoreModelStoreManagerInterface
          */
          protected $_storeManager;

          /**
          * @param MagentoFrameworkUrlInterface $url
          * @param MagentoStoreModelStoreManagerInterface $storeManagerInterface
          */
          public function __construct
          (
          MagentoFrameworkUrlInterface $url,
          MagentoStoreModelStoreManagerInterface $storeManagerInterface
          ){
          $this->_storeManager = $storeManagerInterface;
          $this->_url = $url;
          }

          public function execute(MagentoFrameworkEventObserver $observer)
          {
          $storeObj = $this->_storeManager->getStore(1);
          $BaseURL = $storeObj->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB);
          $url = $BaseURL . 'customer/account/login';
          $this->_response->setRedirect($url)->sendResponse();
          }
          }


          Feel free to ask if any.






          share|improve this answer





















          • 1





            bad idea because your observer will interrupt application flow using exit function.

            – Max
            Oct 6 '17 at 16:38











          • It is not working for me :(

            – Sneha Panchal
            Oct 9 '17 at 10:21











          • @SnehaPanchal let me check

            – Bojjaiah
            Oct 9 '17 at 10:37
















          0














          Create events.xml from Module/etc/frontend/ folder and paste it below code.



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">

          <event name="customer_login">
          <observer name="custom_customer_login" instance="ThemeVendorNameObserverRedirectCustomerToLoginAtObserver" />
          </event>

          </config>


          And create RedirectCustomerToLoginAtObserver.php file from Module/Observer folder and paste it below code.



          <?php

          namespace ThemeVendorNameObserver;

          class RedirectCustomerToLoginAtObserver implements MagentoFrameworkEventObserverInterface
          {
          /**
          * @var MagentoFrameworkAppResponseInterface
          */
          protected $_response;

          /**
          * @var MagentoStoreModelStoreManagerInterface
          */
          protected $_storeManager;

          /**
          * @param MagentoFrameworkUrlInterface $url
          * @param MagentoStoreModelStoreManagerInterface $storeManagerInterface
          */
          public function __construct
          (
          MagentoFrameworkUrlInterface $url,
          MagentoStoreModelStoreManagerInterface $storeManagerInterface
          ){
          $this->_storeManager = $storeManagerInterface;
          $this->_url = $url;
          }

          public function execute(MagentoFrameworkEventObserver $observer)
          {
          $storeObj = $this->_storeManager->getStore(1);
          $BaseURL = $storeObj->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB);
          $url = $BaseURL . 'customer/account/login';
          $this->_response->setRedirect($url)->sendResponse();
          }
          }


          Feel free to ask if any.






          share|improve this answer





















          • 1





            bad idea because your observer will interrupt application flow using exit function.

            – Max
            Oct 6 '17 at 16:38











          • It is not working for me :(

            – Sneha Panchal
            Oct 9 '17 at 10:21











          • @SnehaPanchal let me check

            – Bojjaiah
            Oct 9 '17 at 10:37














          0












          0








          0







          Create events.xml from Module/etc/frontend/ folder and paste it below code.



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">

          <event name="customer_login">
          <observer name="custom_customer_login" instance="ThemeVendorNameObserverRedirectCustomerToLoginAtObserver" />
          </event>

          </config>


          And create RedirectCustomerToLoginAtObserver.php file from Module/Observer folder and paste it below code.



          <?php

          namespace ThemeVendorNameObserver;

          class RedirectCustomerToLoginAtObserver implements MagentoFrameworkEventObserverInterface
          {
          /**
          * @var MagentoFrameworkAppResponseInterface
          */
          protected $_response;

          /**
          * @var MagentoStoreModelStoreManagerInterface
          */
          protected $_storeManager;

          /**
          * @param MagentoFrameworkUrlInterface $url
          * @param MagentoStoreModelStoreManagerInterface $storeManagerInterface
          */
          public function __construct
          (
          MagentoFrameworkUrlInterface $url,
          MagentoStoreModelStoreManagerInterface $storeManagerInterface
          ){
          $this->_storeManager = $storeManagerInterface;
          $this->_url = $url;
          }

          public function execute(MagentoFrameworkEventObserver $observer)
          {
          $storeObj = $this->_storeManager->getStore(1);
          $BaseURL = $storeObj->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB);
          $url = $BaseURL . 'customer/account/login';
          $this->_response->setRedirect($url)->sendResponse();
          }
          }


          Feel free to ask if any.






          share|improve this answer















          Create events.xml from Module/etc/frontend/ folder and paste it below code.



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">

          <event name="customer_login">
          <observer name="custom_customer_login" instance="ThemeVendorNameObserverRedirectCustomerToLoginAtObserver" />
          </event>

          </config>


          And create RedirectCustomerToLoginAtObserver.php file from Module/Observer folder and paste it below code.



          <?php

          namespace ThemeVendorNameObserver;

          class RedirectCustomerToLoginAtObserver implements MagentoFrameworkEventObserverInterface
          {
          /**
          * @var MagentoFrameworkAppResponseInterface
          */
          protected $_response;

          /**
          * @var MagentoStoreModelStoreManagerInterface
          */
          protected $_storeManager;

          /**
          * @param MagentoFrameworkUrlInterface $url
          * @param MagentoStoreModelStoreManagerInterface $storeManagerInterface
          */
          public function __construct
          (
          MagentoFrameworkUrlInterface $url,
          MagentoStoreModelStoreManagerInterface $storeManagerInterface
          ){
          $this->_storeManager = $storeManagerInterface;
          $this->_url = $url;
          }

          public function execute(MagentoFrameworkEventObserver $observer)
          {
          $storeObj = $this->_storeManager->getStore(1);
          $BaseURL = $storeObj->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB);
          $url = $BaseURL . 'customer/account/login';
          $this->_response->setRedirect($url)->sendResponse();
          }
          }


          Feel free to ask if any.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jun 27 '18 at 6:22









          Dhaduk Mitesh

          656218




          656218










          answered Oct 6 '17 at 10:38









          BojjaiahBojjaiah

          2,5132775




          2,5132775








          • 1





            bad idea because your observer will interrupt application flow using exit function.

            – Max
            Oct 6 '17 at 16:38











          • It is not working for me :(

            – Sneha Panchal
            Oct 9 '17 at 10:21











          • @SnehaPanchal let me check

            – Bojjaiah
            Oct 9 '17 at 10:37














          • 1





            bad idea because your observer will interrupt application flow using exit function.

            – Max
            Oct 6 '17 at 16:38











          • It is not working for me :(

            – Sneha Panchal
            Oct 9 '17 at 10:21











          • @SnehaPanchal let me check

            – Bojjaiah
            Oct 9 '17 at 10:37








          1




          1





          bad idea because your observer will interrupt application flow using exit function.

          – Max
          Oct 6 '17 at 16:38





          bad idea because your observer will interrupt application flow using exit function.

          – Max
          Oct 6 '17 at 16:38













          It is not working for me :(

          – Sneha Panchal
          Oct 9 '17 at 10:21





          It is not working for me :(

          – Sneha Panchal
          Oct 9 '17 at 10:21













          @SnehaPanchal let me check

          – Bojjaiah
          Oct 9 '17 at 10:37





          @SnehaPanchal let me check

          – Bojjaiah
          Oct 9 '17 at 10:37


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f196170%2fmagento-2-redirect-on-cart-page-after-login%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Alcázar de San Juan

          Griza ansero

          Donsieders