Magento 2 - How to Redirect Customer for Checkout After Login when cart is not emptyException Plugin class doesn't existMagento 2 - Redirect customer to custom page after loginHow to check whether a product is in the cart?How to change or redirect home page to customer login?Redirect 'add to cart' button to the account login screen when customer is not loged inMake cart empty after loginHow can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderCustomer redirect issue with plugin method magento2Magento : Around Plugin for LoginPost

Ensuring all network services on a device use strong TLS cipher suites

Does travel insurance for short flight delays exist?

Are modern clipless shoes and pedals that much better than toe clips and straps?

Is for(( ... )) ... ; a valid shell syntax? In which shells?

Handling Disruptive Student on the Autistic Spectrum

Why were the crew so desperate to catch Truman and return him to Seahaven?

Was there ever a treaty between 2 entities with significantly different translations to the detriment of one party?

Would it be possible to have a GMO that produces chocolate?

Is there any method of inflicting the incapacitated condition and no other condition?

What are some interesting features that are common cross-linguistically but don't exist in English?

Confirming resignation after resignation letter ripped up

How to find multiple values on the same line in any permutation using Notepad++?

How to gently end involvement with an online community?

Compelling story with the world as a villain

Why did MS-DOS applications built using Turbo Pascal fail to start with a division by zero error on faster systems?

Why do banks “park” their money at the European Central Bank?

How do I get a decreased-by-one x in a foreach loop?

Is using a hyperlink to close a modal a poor design decision?

Is “I am getting married with my sister” ambiguous?

How to respectfully refuse to assist co-workers with IT issues?

Justifying the use of directed energy weapons

Can a Rogue PC teach an NPC to perform Sneak Attack?

What is the difference between Major and Minor Bug?

Can you pop_back a vector and still use the iterator to the last element?



Magento 2 - How to Redirect Customer for Checkout After Login when cart is not empty


Exception Plugin class doesn't existMagento 2 - Redirect customer to custom page after loginHow to check whether a product is in the cart?How to change or redirect home page to customer login?Redirect 'add to cart' button to the account login screen when customer is not loged inMake cart empty after loginHow can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderCustomer redirect issue with plugin method magento2Magento : Around Plugin for LoginPost






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








1















How to redirect customers to the checkout page after login when the cart is not empty for the customer?



LoginpostRedirectetcfrontenddi.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerControllerAccountLoginPost">
<plugin name="loginpost_redirect_loginpostplugin" type="LoginPostRedirectPluginLoginPostPlugin" sortOrder="1" />
</type>
</config>


LoginpostRedirectPluginLoginPostPlugin.php



 <?php

namespace LoginpostRedirectPlugin;

class LoginPostPlugin

public function afterExecute(
MagentoCustomerControllerAccountLoginPost $subject,
$result)

$result->setPath('/checkout');
return $result;





Now I'm getting following error after adding this plugin to my project.



plugin class does not exist error










share|improve this question
































    1















    How to redirect customers to the checkout page after login when the cart is not empty for the customer?



    LoginpostRedirectetcfrontenddi.xml



    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="MagentoCustomerControllerAccountLoginPost">
    <plugin name="loginpost_redirect_loginpostplugin" type="LoginPostRedirectPluginLoginPostPlugin" sortOrder="1" />
    </type>
    </config>


    LoginpostRedirectPluginLoginPostPlugin.php



     <?php

    namespace LoginpostRedirectPlugin;

    class LoginPostPlugin

    public function afterExecute(
    MagentoCustomerControllerAccountLoginPost $subject,
    $result)

    $result->setPath('/checkout');
    return $result;





    Now I'm getting following error after adding this plugin to my project.



    plugin class does not exist error










    share|improve this question




























      1












      1








      1


      1






      How to redirect customers to the checkout page after login when the cart is not empty for the customer?



      LoginpostRedirectetcfrontenddi.xml



      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      <type name="MagentoCustomerControllerAccountLoginPost">
      <plugin name="loginpost_redirect_loginpostplugin" type="LoginPostRedirectPluginLoginPostPlugin" sortOrder="1" />
      </type>
      </config>


      LoginpostRedirectPluginLoginPostPlugin.php



       <?php

      namespace LoginpostRedirectPlugin;

      class LoginPostPlugin

      public function afterExecute(
      MagentoCustomerControllerAccountLoginPost $subject,
      $result)

      $result->setPath('/checkout');
      return $result;





      Now I'm getting following error after adding this plugin to my project.



      plugin class does not exist error










      share|improve this question
















      How to redirect customers to the checkout page after login when the cart is not empty for the customer?



      LoginpostRedirectetcfrontenddi.xml



      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      <type name="MagentoCustomerControllerAccountLoginPost">
      <plugin name="loginpost_redirect_loginpostplugin" type="LoginPostRedirectPluginLoginPostPlugin" sortOrder="1" />
      </type>
      </config>


      LoginpostRedirectPluginLoginPostPlugin.php



       <?php

      namespace LoginpostRedirectPlugin;

      class LoginPostPlugin

      public function afterExecute(
      MagentoCustomerControllerAccountLoginPost $subject,
      $result)

      $result->setPath('/checkout');
      return $result;





      Now I'm getting following error after adding this plugin to my project.



      plugin class does not exist error







      magento2 customer-account redirect






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 13 at 9:25







      ashanr

















      asked Aug 12 at 7:29









      ashanrashanr

      407 bronze badges




      407 bronze badges























          2 Answers
          2






          active

          oldest

          votes


















          1















          You can use a plugin for your requirement.



          Create a di.xml file /Vendor/Module/etc/frontend/di.xml with below content



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <type name="MagentoCustomerControllerAccountLoginPost">
          <plugin name="vendor_module_loginpostplugin" type="VendorModulePluginLoginPostPlugin" sortOrder="1" />
          </type>
          </config>


          Create LoginPostPlugin.php file /Vendor/Module/Plugin/LoginPostPlugin.php with below content.



          <?php

          namespace VendorModulePlugin;

          class LoginPostPlugin

          public function afterExecute(
          MagentoCustomerControllerAccountLoginPost $subject,
          $result)

          $result->setPath('/checkout');
          return $result;






          Reference from
          Magento 2 - Redirect customer to custom page after login







          share|improve this answer

























          • i'm new to magento and there is no directory named module inside vendor. instead of that can I create this plugin inside app/code directory ?

            – ashanr
            Aug 12 at 8:33






          • 1





            You need to create a new folder under app/code/[vendor_name]/[module_name]. You can choose the Vendor and Module name as per your requirements. For example, /Sumit/CustomerLogin/Plugin/LoginPostPlugin.php

            – Sumit
            Aug 12 at 9:22











          • I have don't this. But still not redirecting to checkout page after login. Are these two the only files inside this module ?

            – ashanr
            Aug 13 at 8:51






          • 1





            No, you need to create basic extension having Registration.php and module.xml file in etc folder. For example, /Sumit/CustomerLogin/etc/module.xml

            – Sumit
            Aug 13 at 8:53







          • 1





            Perfect, you can check it by current cart quote of the customer while login in the same plugin. If the customer having any product in the cart then redirect to the checkout.

            – Sumit
            Aug 16 at 7:13


















          0















          you need to create observer that fire event after customer login.



          Create observer as below



          <?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="<Your_packagename><Your_modulename>ObserverRedirectCustommer" />
          </event>
          </config>


          Create RedirectCustommer.php under "Your_packagenameYour_modulenameObserver"



          <?php

          namespace YourPackageYourModleObserver;

          use MagentoFrameworkEventObserverInterface;
          use MagentoFrameworkControllerResultFactory;

          class RedirectCustommer implements ObserverInterface


          /**
          *@varMagentoQuoteModelQuoteFactory
          */
          protected $quoteFactory;


          public function __construct(
          MagentoFrameworkAppResponseFactory $responseFactory,
          MagentoQuoteModelQuoteFactory $quoteFactory
          )

          $this->quoteFactory = $quoteFactory;


          public function execute(MagentoFrameworkEventObserver $observer)

          $customer = $observer->getEvent()->getCustomer();
          $landingurl = $this->getRedirectUrl($customer->getId());
          if ($landingurl)
          $resultRedirect = $this->responseFactory->create();
          $resultRedirect->setRedirect($landingurl)->sendResponse('200');
          exit();



          public function getRedirectUrl($customerId)


          $quote = $this->quoteFactory->create()->getCollection()->addFieldToFilter('customer_id',$customerId);
          if($quote->getId())

          return $block->getUrl('checkout', ['_secure' => true]);

          return false;









          share|improve this answer



























          • Amit, Plugin is the best method to override Magento's functionality instead of using observer.

            – Sumit
            Aug 12 at 7:48











          • Considered,But plugin is what used for change argument behavior and return value.

            – Amitkumar solanki
            Aug 12 at 8:26











          • @Amitkumarsolanki so what is the ideal way to do this ? using an observer or plugin. i'm using magento 2.1 for this project.

            – ashanr
            Aug 12 at 8:29






          • 1





            Both will be fine. but in some cases you should consider loading time for both.

            – Amitkumar solanki
            Aug 12 at 8:35













          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%2f285118%2fmagento-2-how-to-redirect-customer-for-checkout-after-login-when-cart-is-not-e%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1















          You can use a plugin for your requirement.



          Create a di.xml file /Vendor/Module/etc/frontend/di.xml with below content



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <type name="MagentoCustomerControllerAccountLoginPost">
          <plugin name="vendor_module_loginpostplugin" type="VendorModulePluginLoginPostPlugin" sortOrder="1" />
          </type>
          </config>


          Create LoginPostPlugin.php file /Vendor/Module/Plugin/LoginPostPlugin.php with below content.



          <?php

          namespace VendorModulePlugin;

          class LoginPostPlugin

          public function afterExecute(
          MagentoCustomerControllerAccountLoginPost $subject,
          $result)

          $result->setPath('/checkout');
          return $result;






          Reference from
          Magento 2 - Redirect customer to custom page after login







          share|improve this answer

























          • i'm new to magento and there is no directory named module inside vendor. instead of that can I create this plugin inside app/code directory ?

            – ashanr
            Aug 12 at 8:33






          • 1





            You need to create a new folder under app/code/[vendor_name]/[module_name]. You can choose the Vendor and Module name as per your requirements. For example, /Sumit/CustomerLogin/Plugin/LoginPostPlugin.php

            – Sumit
            Aug 12 at 9:22











          • I have don't this. But still not redirecting to checkout page after login. Are these two the only files inside this module ?

            – ashanr
            Aug 13 at 8:51






          • 1





            No, you need to create basic extension having Registration.php and module.xml file in etc folder. For example, /Sumit/CustomerLogin/etc/module.xml

            – Sumit
            Aug 13 at 8:53







          • 1





            Perfect, you can check it by current cart quote of the customer while login in the same plugin. If the customer having any product in the cart then redirect to the checkout.

            – Sumit
            Aug 16 at 7:13















          1















          You can use a plugin for your requirement.



          Create a di.xml file /Vendor/Module/etc/frontend/di.xml with below content



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <type name="MagentoCustomerControllerAccountLoginPost">
          <plugin name="vendor_module_loginpostplugin" type="VendorModulePluginLoginPostPlugin" sortOrder="1" />
          </type>
          </config>


          Create LoginPostPlugin.php file /Vendor/Module/Plugin/LoginPostPlugin.php with below content.



          <?php

          namespace VendorModulePlugin;

          class LoginPostPlugin

          public function afterExecute(
          MagentoCustomerControllerAccountLoginPost $subject,
          $result)

          $result->setPath('/checkout');
          return $result;






          Reference from
          Magento 2 - Redirect customer to custom page after login







          share|improve this answer

























          • i'm new to magento and there is no directory named module inside vendor. instead of that can I create this plugin inside app/code directory ?

            – ashanr
            Aug 12 at 8:33






          • 1





            You need to create a new folder under app/code/[vendor_name]/[module_name]. You can choose the Vendor and Module name as per your requirements. For example, /Sumit/CustomerLogin/Plugin/LoginPostPlugin.php

            – Sumit
            Aug 12 at 9:22











          • I have don't this. But still not redirecting to checkout page after login. Are these two the only files inside this module ?

            – ashanr
            Aug 13 at 8:51






          • 1





            No, you need to create basic extension having Registration.php and module.xml file in etc folder. For example, /Sumit/CustomerLogin/etc/module.xml

            – Sumit
            Aug 13 at 8:53







          • 1





            Perfect, you can check it by current cart quote of the customer while login in the same plugin. If the customer having any product in the cart then redirect to the checkout.

            – Sumit
            Aug 16 at 7:13













          1














          1










          1









          You can use a plugin for your requirement.



          Create a di.xml file /Vendor/Module/etc/frontend/di.xml with below content



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <type name="MagentoCustomerControllerAccountLoginPost">
          <plugin name="vendor_module_loginpostplugin" type="VendorModulePluginLoginPostPlugin" sortOrder="1" />
          </type>
          </config>


          Create LoginPostPlugin.php file /Vendor/Module/Plugin/LoginPostPlugin.php with below content.



          <?php

          namespace VendorModulePlugin;

          class LoginPostPlugin

          public function afterExecute(
          MagentoCustomerControllerAccountLoginPost $subject,
          $result)

          $result->setPath('/checkout');
          return $result;






          Reference from
          Magento 2 - Redirect customer to custom page after login







          share|improve this answer













          You can use a plugin for your requirement.



          Create a di.xml file /Vendor/Module/etc/frontend/di.xml with below content



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <type name="MagentoCustomerControllerAccountLoginPost">
          <plugin name="vendor_module_loginpostplugin" type="VendorModulePluginLoginPostPlugin" sortOrder="1" />
          </type>
          </config>


          Create LoginPostPlugin.php file /Vendor/Module/Plugin/LoginPostPlugin.php with below content.



          <?php

          namespace VendorModulePlugin;

          class LoginPostPlugin

          public function afterExecute(
          MagentoCustomerControllerAccountLoginPost $subject,
          $result)

          $result->setPath('/checkout');
          return $result;






          Reference from
          Magento 2 - Redirect customer to custom page after login








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 12 at 7:44









          SumitSumit

          4361 silver badge14 bronze badges




          4361 silver badge14 bronze badges















          • i'm new to magento and there is no directory named module inside vendor. instead of that can I create this plugin inside app/code directory ?

            – ashanr
            Aug 12 at 8:33






          • 1





            You need to create a new folder under app/code/[vendor_name]/[module_name]. You can choose the Vendor and Module name as per your requirements. For example, /Sumit/CustomerLogin/Plugin/LoginPostPlugin.php

            – Sumit
            Aug 12 at 9:22











          • I have don't this. But still not redirecting to checkout page after login. Are these two the only files inside this module ?

            – ashanr
            Aug 13 at 8:51






          • 1





            No, you need to create basic extension having Registration.php and module.xml file in etc folder. For example, /Sumit/CustomerLogin/etc/module.xml

            – Sumit
            Aug 13 at 8:53







          • 1





            Perfect, you can check it by current cart quote of the customer while login in the same plugin. If the customer having any product in the cart then redirect to the checkout.

            – Sumit
            Aug 16 at 7:13

















          • i'm new to magento and there is no directory named module inside vendor. instead of that can I create this plugin inside app/code directory ?

            – ashanr
            Aug 12 at 8:33






          • 1





            You need to create a new folder under app/code/[vendor_name]/[module_name]. You can choose the Vendor and Module name as per your requirements. For example, /Sumit/CustomerLogin/Plugin/LoginPostPlugin.php

            – Sumit
            Aug 12 at 9:22











          • I have don't this. But still not redirecting to checkout page after login. Are these two the only files inside this module ?

            – ashanr
            Aug 13 at 8:51






          • 1





            No, you need to create basic extension having Registration.php and module.xml file in etc folder. For example, /Sumit/CustomerLogin/etc/module.xml

            – Sumit
            Aug 13 at 8:53







          • 1





            Perfect, you can check it by current cart quote of the customer while login in the same plugin. If the customer having any product in the cart then redirect to the checkout.

            – Sumit
            Aug 16 at 7:13
















          i'm new to magento and there is no directory named module inside vendor. instead of that can I create this plugin inside app/code directory ?

          – ashanr
          Aug 12 at 8:33





          i'm new to magento and there is no directory named module inside vendor. instead of that can I create this plugin inside app/code directory ?

          – ashanr
          Aug 12 at 8:33




          1




          1





          You need to create a new folder under app/code/[vendor_name]/[module_name]. You can choose the Vendor and Module name as per your requirements. For example, /Sumit/CustomerLogin/Plugin/LoginPostPlugin.php

          – Sumit
          Aug 12 at 9:22





          You need to create a new folder under app/code/[vendor_name]/[module_name]. You can choose the Vendor and Module name as per your requirements. For example, /Sumit/CustomerLogin/Plugin/LoginPostPlugin.php

          – Sumit
          Aug 12 at 9:22













          I have don't this. But still not redirecting to checkout page after login. Are these two the only files inside this module ?

          – ashanr
          Aug 13 at 8:51





          I have don't this. But still not redirecting to checkout page after login. Are these two the only files inside this module ?

          – ashanr
          Aug 13 at 8:51




          1




          1





          No, you need to create basic extension having Registration.php and module.xml file in etc folder. For example, /Sumit/CustomerLogin/etc/module.xml

          – Sumit
          Aug 13 at 8:53






          No, you need to create basic extension having Registration.php and module.xml file in etc folder. For example, /Sumit/CustomerLogin/etc/module.xml

          – Sumit
          Aug 13 at 8:53





          1




          1





          Perfect, you can check it by current cart quote of the customer while login in the same plugin. If the customer having any product in the cart then redirect to the checkout.

          – Sumit
          Aug 16 at 7:13





          Perfect, you can check it by current cart quote of the customer while login in the same plugin. If the customer having any product in the cart then redirect to the checkout.

          – Sumit
          Aug 16 at 7:13













          0















          you need to create observer that fire event after customer login.



          Create observer as below



          <?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="<Your_packagename><Your_modulename>ObserverRedirectCustommer" />
          </event>
          </config>


          Create RedirectCustommer.php under "Your_packagenameYour_modulenameObserver"



          <?php

          namespace YourPackageYourModleObserver;

          use MagentoFrameworkEventObserverInterface;
          use MagentoFrameworkControllerResultFactory;

          class RedirectCustommer implements ObserverInterface


          /**
          *@varMagentoQuoteModelQuoteFactory
          */
          protected $quoteFactory;


          public function __construct(
          MagentoFrameworkAppResponseFactory $responseFactory,
          MagentoQuoteModelQuoteFactory $quoteFactory
          )

          $this->quoteFactory = $quoteFactory;


          public function execute(MagentoFrameworkEventObserver $observer)

          $customer = $observer->getEvent()->getCustomer();
          $landingurl = $this->getRedirectUrl($customer->getId());
          if ($landingurl)
          $resultRedirect = $this->responseFactory->create();
          $resultRedirect->setRedirect($landingurl)->sendResponse('200');
          exit();



          public function getRedirectUrl($customerId)


          $quote = $this->quoteFactory->create()->getCollection()->addFieldToFilter('customer_id',$customerId);
          if($quote->getId())

          return $block->getUrl('checkout', ['_secure' => true]);

          return false;









          share|improve this answer



























          • Amit, Plugin is the best method to override Magento's functionality instead of using observer.

            – Sumit
            Aug 12 at 7:48











          • Considered,But plugin is what used for change argument behavior and return value.

            – Amitkumar solanki
            Aug 12 at 8:26











          • @Amitkumarsolanki so what is the ideal way to do this ? using an observer or plugin. i'm using magento 2.1 for this project.

            – ashanr
            Aug 12 at 8:29






          • 1





            Both will be fine. but in some cases you should consider loading time for both.

            – Amitkumar solanki
            Aug 12 at 8:35















          0















          you need to create observer that fire event after customer login.



          Create observer as below



          <?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="<Your_packagename><Your_modulename>ObserverRedirectCustommer" />
          </event>
          </config>


          Create RedirectCustommer.php under "Your_packagenameYour_modulenameObserver"



          <?php

          namespace YourPackageYourModleObserver;

          use MagentoFrameworkEventObserverInterface;
          use MagentoFrameworkControllerResultFactory;

          class RedirectCustommer implements ObserverInterface


          /**
          *@varMagentoQuoteModelQuoteFactory
          */
          protected $quoteFactory;


          public function __construct(
          MagentoFrameworkAppResponseFactory $responseFactory,
          MagentoQuoteModelQuoteFactory $quoteFactory
          )

          $this->quoteFactory = $quoteFactory;


          public function execute(MagentoFrameworkEventObserver $observer)

          $customer = $observer->getEvent()->getCustomer();
          $landingurl = $this->getRedirectUrl($customer->getId());
          if ($landingurl)
          $resultRedirect = $this->responseFactory->create();
          $resultRedirect->setRedirect($landingurl)->sendResponse('200');
          exit();



          public function getRedirectUrl($customerId)


          $quote = $this->quoteFactory->create()->getCollection()->addFieldToFilter('customer_id',$customerId);
          if($quote->getId())

          return $block->getUrl('checkout', ['_secure' => true]);

          return false;









          share|improve this answer



























          • Amit, Plugin is the best method to override Magento's functionality instead of using observer.

            – Sumit
            Aug 12 at 7:48











          • Considered,But plugin is what used for change argument behavior and return value.

            – Amitkumar solanki
            Aug 12 at 8:26











          • @Amitkumarsolanki so what is the ideal way to do this ? using an observer or plugin. i'm using magento 2.1 for this project.

            – ashanr
            Aug 12 at 8:29






          • 1





            Both will be fine. but in some cases you should consider loading time for both.

            – Amitkumar solanki
            Aug 12 at 8:35













          0














          0










          0









          you need to create observer that fire event after customer login.



          Create observer as below



          <?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="<Your_packagename><Your_modulename>ObserverRedirectCustommer" />
          </event>
          </config>


          Create RedirectCustommer.php under "Your_packagenameYour_modulenameObserver"



          <?php

          namespace YourPackageYourModleObserver;

          use MagentoFrameworkEventObserverInterface;
          use MagentoFrameworkControllerResultFactory;

          class RedirectCustommer implements ObserverInterface


          /**
          *@varMagentoQuoteModelQuoteFactory
          */
          protected $quoteFactory;


          public function __construct(
          MagentoFrameworkAppResponseFactory $responseFactory,
          MagentoQuoteModelQuoteFactory $quoteFactory
          )

          $this->quoteFactory = $quoteFactory;


          public function execute(MagentoFrameworkEventObserver $observer)

          $customer = $observer->getEvent()->getCustomer();
          $landingurl = $this->getRedirectUrl($customer->getId());
          if ($landingurl)
          $resultRedirect = $this->responseFactory->create();
          $resultRedirect->setRedirect($landingurl)->sendResponse('200');
          exit();



          public function getRedirectUrl($customerId)


          $quote = $this->quoteFactory->create()->getCollection()->addFieldToFilter('customer_id',$customerId);
          if($quote->getId())

          return $block->getUrl('checkout', ['_secure' => true]);

          return false;









          share|improve this answer















          you need to create observer that fire event after customer login.



          Create observer as below



          <?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="<Your_packagename><Your_modulename>ObserverRedirectCustommer" />
          </event>
          </config>


          Create RedirectCustommer.php under "Your_packagenameYour_modulenameObserver"



          <?php

          namespace YourPackageYourModleObserver;

          use MagentoFrameworkEventObserverInterface;
          use MagentoFrameworkControllerResultFactory;

          class RedirectCustommer implements ObserverInterface


          /**
          *@varMagentoQuoteModelQuoteFactory
          */
          protected $quoteFactory;


          public function __construct(
          MagentoFrameworkAppResponseFactory $responseFactory,
          MagentoQuoteModelQuoteFactory $quoteFactory
          )

          $this->quoteFactory = $quoteFactory;


          public function execute(MagentoFrameworkEventObserver $observer)

          $customer = $observer->getEvent()->getCustomer();
          $landingurl = $this->getRedirectUrl($customer->getId());
          if ($landingurl)
          $resultRedirect = $this->responseFactory->create();
          $resultRedirect->setRedirect($landingurl)->sendResponse('200');
          exit();



          public function getRedirectUrl($customerId)


          $quote = $this->quoteFactory->create()->getCollection()->addFieldToFilter('customer_id',$customerId);
          if($quote->getId())

          return $block->getUrl('checkout', ['_secure' => true]);

          return false;










          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 12 at 8:23

























          answered Aug 12 at 7:46









          Amitkumar solankiAmitkumar solanki

          4722 silver badges16 bronze badges




          4722 silver badges16 bronze badges















          • Amit, Plugin is the best method to override Magento's functionality instead of using observer.

            – Sumit
            Aug 12 at 7:48











          • Considered,But plugin is what used for change argument behavior and return value.

            – Amitkumar solanki
            Aug 12 at 8:26











          • @Amitkumarsolanki so what is the ideal way to do this ? using an observer or plugin. i'm using magento 2.1 for this project.

            – ashanr
            Aug 12 at 8:29






          • 1





            Both will be fine. but in some cases you should consider loading time for both.

            – Amitkumar solanki
            Aug 12 at 8:35

















          • Amit, Plugin is the best method to override Magento's functionality instead of using observer.

            – Sumit
            Aug 12 at 7:48











          • Considered,But plugin is what used for change argument behavior and return value.

            – Amitkumar solanki
            Aug 12 at 8:26











          • @Amitkumarsolanki so what is the ideal way to do this ? using an observer or plugin. i'm using magento 2.1 for this project.

            – ashanr
            Aug 12 at 8:29






          • 1





            Both will be fine. but in some cases you should consider loading time for both.

            – Amitkumar solanki
            Aug 12 at 8:35
















          Amit, Plugin is the best method to override Magento's functionality instead of using observer.

          – Sumit
          Aug 12 at 7:48





          Amit, Plugin is the best method to override Magento's functionality instead of using observer.

          – Sumit
          Aug 12 at 7:48













          Considered,But plugin is what used for change argument behavior and return value.

          – Amitkumar solanki
          Aug 12 at 8:26





          Considered,But plugin is what used for change argument behavior and return value.

          – Amitkumar solanki
          Aug 12 at 8:26













          @Amitkumarsolanki so what is the ideal way to do this ? using an observer or plugin. i'm using magento 2.1 for this project.

          – ashanr
          Aug 12 at 8:29





          @Amitkumarsolanki so what is the ideal way to do this ? using an observer or plugin. i'm using magento 2.1 for this project.

          – ashanr
          Aug 12 at 8:29




          1




          1





          Both will be fine. but in some cases you should consider loading time for both.

          – Amitkumar solanki
          Aug 12 at 8:35





          Both will be fine. but in some cases you should consider loading time for both.

          – Amitkumar solanki
          Aug 12 at 8:35

















          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%2f285118%2fmagento-2-how-to-redirect-customer-for-checkout-after-login-when-cart-is-not-e%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

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

          Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?