Magento 2: How to redirect to checkout page after product added to cart via Observer/Plugin from category page?Magento2 redirecting to Shopping cartMagento 2: Skipping Shopping Cart Page after Add to CartMagento 2 : Add to Cart Button redirect to contact pageMagento 2: Redirect from Observer Not Working on Category PageRedirect to Category Page after “Add to Cart”Redirect to another category from observerCheckout: How to redirect back to cart after customer logged in within the onepage checkout process?Magento 2: Skipping Shopping Cart Page after Add to CartRedirect Page From ObserverGetting cart empty after redirect issueMagento 2: Redirect from Observer Not Working on Category PageMagento 2 - How to show not visible individually products in mini cart?Redirect from plugin Magento 2Magento 2 plugin change price of products that have a custom attribute with

What is the most common color to indicate the input-field is disabled?

How do I deal with an unproductive colleague in a small company?

Why no variance term in Bayesian logistic regression?

Is it inappropriate for a student to attend their mentor's dissertation defense?

How dangerous is XSS?

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?

I would say: "You are another teacher", but she is a woman and I am a man

How to show a landlord what we have in savings?

Could the museum Saturn V's be refitted for one more flight?

Should I cover my bicycle overnight while bikepacking?

How would I stat a creature to be immune to everything but the Magic Missile spell? (just for fun)

Would Slavery Reparations be considered Bills of Attainder and hence Illegal?

How do I gain back my faith in my PhD degree?

Is "remove commented out code" correct English?

How to tell a function to use the default argument values?

Unable to supress ligatures in headings which are set in Caps

What are some good books on Machine Learning and AI like Krugman, Wells and Graddy's "Essentials of Economics"

Short story with a alien planet, government officials must wear exploding medallions

Why didn't Boeing produce its own regional jet?

Is it acceptable for a professor to tell male students to not think that they are smarter than female students?

Bullying boss launched a smear campaign and made me unemployable

Which is the best way to check return result?

Apex Framework / library for consuming REST services



Magento 2: How to redirect to checkout page after product added to cart via Observer/Plugin from category page?


Magento2 redirecting to Shopping cartMagento 2: Skipping Shopping Cart Page after Add to CartMagento 2 : Add to Cart Button redirect to contact pageMagento 2: Redirect from Observer Not Working on Category PageRedirect to Category Page after “Add to Cart”Redirect to another category from observerCheckout: How to redirect back to cart after customer logged in within the onepage checkout process?Magento 2: Skipping Shopping Cart Page after Add to CartRedirect Page From ObserverGetting cart empty after redirect issueMagento 2: Redirect from Observer Not Working on Category PageMagento 2 - How to show not visible individually products in mini cart?Redirect from plugin Magento 2Magento 2 plugin change price of products that have a custom attribute with













3















I have followed below & it works fine



Magento 2 : Add to Cart Button redirect to contact page



Only issue it should be redirected after product is added to cart.



I have tried different methods but seems not working http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html



I tried using Observer but unable to redirect from Observer because of AJAX. It it's not AJAX then it works fine.



If somebody can guide how to redirect from Checkout page after product is added to cart. It would be better.



I'm using Porto Theme. So don't want to remove AJAX feature while Add to Cart



[UPDATE]



Through plugin I have achieved. Need to achieve something using Observer



public function afterExecute(MagentoCheckoutControllerCartAdd $subject, $result) 
$result = [];
$result['backUrl'] = $this->url->getUrl('checkout');
$subject->getResponse()->representJson($this->objectManager->get('MagentoFrameworkJsonHelperData')->jsonEncode($result));
return;










share|improve this question
















bumped to the homepage by Community 8 mins ago


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















  • magento.stackexchange.com/a/100417/42720 this?

    – Volvox
    Jun 9 '17 at 7:24











  • Below is an answer to redirect to checkout by overriding template file, you can check here magento.stackexchange.com/a/240628/44358

    – Nitesh
    Sep 3 '18 at 12:53















3















I have followed below & it works fine



Magento 2 : Add to Cart Button redirect to contact page



Only issue it should be redirected after product is added to cart.



I have tried different methods but seems not working http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html



I tried using Observer but unable to redirect from Observer because of AJAX. It it's not AJAX then it works fine.



If somebody can guide how to redirect from Checkout page after product is added to cart. It would be better.



I'm using Porto Theme. So don't want to remove AJAX feature while Add to Cart



[UPDATE]



Through plugin I have achieved. Need to achieve something using Observer



public function afterExecute(MagentoCheckoutControllerCartAdd $subject, $result) 
$result = [];
$result['backUrl'] = $this->url->getUrl('checkout');
$subject->getResponse()->representJson($this->objectManager->get('MagentoFrameworkJsonHelperData')->jsonEncode($result));
return;










share|improve this question
















bumped to the homepage by Community 8 mins ago


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















  • magento.stackexchange.com/a/100417/42720 this?

    – Volvox
    Jun 9 '17 at 7:24











  • Below is an answer to redirect to checkout by overriding template file, you can check here magento.stackexchange.com/a/240628/44358

    – Nitesh
    Sep 3 '18 at 12:53













3












3








3








I have followed below & it works fine



Magento 2 : Add to Cart Button redirect to contact page



Only issue it should be redirected after product is added to cart.



I have tried different methods but seems not working http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html



I tried using Observer but unable to redirect from Observer because of AJAX. It it's not AJAX then it works fine.



If somebody can guide how to redirect from Checkout page after product is added to cart. It would be better.



I'm using Porto Theme. So don't want to remove AJAX feature while Add to Cart



[UPDATE]



Through plugin I have achieved. Need to achieve something using Observer



public function afterExecute(MagentoCheckoutControllerCartAdd $subject, $result) 
$result = [];
$result['backUrl'] = $this->url->getUrl('checkout');
$subject->getResponse()->representJson($this->objectManager->get('MagentoFrameworkJsonHelperData')->jsonEncode($result));
return;










share|improve this question
















I have followed below & it works fine



Magento 2 : Add to Cart Button redirect to contact page



Only issue it should be redirected after product is added to cart.



I have tried different methods but seems not working http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html



I tried using Observer but unable to redirect from Observer because of AJAX. It it's not AJAX then it works fine.



If somebody can guide how to redirect from Checkout page after product is added to cart. It would be better.



I'm using Porto Theme. So don't want to remove AJAX feature while Add to Cart



[UPDATE]



Through plugin I have achieved. Need to achieve something using Observer



public function afterExecute(MagentoCheckoutControllerCartAdd $subject, $result) 
$result = [];
$result['backUrl'] = $this->url->getUrl('checkout');
$subject->getResponse()->representJson($this->objectManager->get('MagentoFrameworkJsonHelperData')->jsonEncode($result));
return;







magento2 event-observer custom redirect plugin






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 13 '17 at 12:55









Community

1




1










asked Mar 8 '17 at 3:19









Ankit ShahAnkit Shah

4,951967144




4,951967144





bumped to the homepage by Community 8 mins 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 8 mins ago


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














  • magento.stackexchange.com/a/100417/42720 this?

    – Volvox
    Jun 9 '17 at 7:24











  • Below is an answer to redirect to checkout by overriding template file, you can check here magento.stackexchange.com/a/240628/44358

    – Nitesh
    Sep 3 '18 at 12:53

















  • magento.stackexchange.com/a/100417/42720 this?

    – Volvox
    Jun 9 '17 at 7:24











  • Below is an answer to redirect to checkout by overriding template file, you can check here magento.stackexchange.com/a/240628/44358

    – Nitesh
    Sep 3 '18 at 12:53
















magento.stackexchange.com/a/100417/42720 this?

– Volvox
Jun 9 '17 at 7:24





magento.stackexchange.com/a/100417/42720 this?

– Volvox
Jun 9 '17 at 7:24













Below is an answer to redirect to checkout by overriding template file, you can check here magento.stackexchange.com/a/240628/44358

– Nitesh
Sep 3 '18 at 12:53





Below is an answer to redirect to checkout by overriding template file, you can check here magento.stackexchange.com/a/240628/44358

– Nitesh
Sep 3 '18 at 12:53










1 Answer
1






active

oldest

votes


















0














try this code.



use MagentoFrameworkEventObserverInterface;

class TestObserver implements ObserverInterface

protected $_responseFactory;
protected $_url;

public function __construct(MagentoFrameworkAppResponseFactory $responseFactory,
MagentoFrameworkUrlInterface $url)

$this->_responseFactory = $responseFactory;
$this->_url = $url;


public function execute(MagentoFrameworkEventObserver $observer)

$cartUrl = $this->_url->getUrl('checkout/cart/index');
$this->_responseFactory->create()->setRedirect($cartUrl)->sendResponse();
exit;







share|improve this answer























    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%2f163322%2fmagento-2-how-to-redirect-to-checkout-page-after-product-added-to-cart-via-obse%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    try this code.



    use MagentoFrameworkEventObserverInterface;

    class TestObserver implements ObserverInterface

    protected $_responseFactory;
    protected $_url;

    public function __construct(MagentoFrameworkAppResponseFactory $responseFactory,
    MagentoFrameworkUrlInterface $url)

    $this->_responseFactory = $responseFactory;
    $this->_url = $url;


    public function execute(MagentoFrameworkEventObserver $observer)

    $cartUrl = $this->_url->getUrl('checkout/cart/index');
    $this->_responseFactory->create()->setRedirect($cartUrl)->sendResponse();
    exit;







    share|improve this answer



























      0














      try this code.



      use MagentoFrameworkEventObserverInterface;

      class TestObserver implements ObserverInterface

      protected $_responseFactory;
      protected $_url;

      public function __construct(MagentoFrameworkAppResponseFactory $responseFactory,
      MagentoFrameworkUrlInterface $url)

      $this->_responseFactory = $responseFactory;
      $this->_url = $url;


      public function execute(MagentoFrameworkEventObserver $observer)

      $cartUrl = $this->_url->getUrl('checkout/cart/index');
      $this->_responseFactory->create()->setRedirect($cartUrl)->sendResponse();
      exit;







      share|improve this answer

























        0












        0








        0







        try this code.



        use MagentoFrameworkEventObserverInterface;

        class TestObserver implements ObserverInterface

        protected $_responseFactory;
        protected $_url;

        public function __construct(MagentoFrameworkAppResponseFactory $responseFactory,
        MagentoFrameworkUrlInterface $url)

        $this->_responseFactory = $responseFactory;
        $this->_url = $url;


        public function execute(MagentoFrameworkEventObserver $observer)

        $cartUrl = $this->_url->getUrl('checkout/cart/index');
        $this->_responseFactory->create()->setRedirect($cartUrl)->sendResponse();
        exit;







        share|improve this answer













        try this code.



        use MagentoFrameworkEventObserverInterface;

        class TestObserver implements ObserverInterface

        protected $_responseFactory;
        protected $_url;

        public function __construct(MagentoFrameworkAppResponseFactory $responseFactory,
        MagentoFrameworkUrlInterface $url)

        $this->_responseFactory = $responseFactory;
        $this->_url = $url;


        public function execute(MagentoFrameworkEventObserver $observer)

        $cartUrl = $this->_url->getUrl('checkout/cart/index');
        $this->_responseFactory->create()->setRedirect($cartUrl)->sendResponse();
        exit;








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 '17 at 3:29









        Dhiren VasoyaDhiren Vasoya

        4,38151844




        4,38151844



























            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%2f163322%2fmagento-2-how-to-redirect-to-checkout-page-after-product-added-to-cart-via-obse%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

            Best approach to update all entries in a list that is paginated?Best way to add items to a paginated listChoose Your Country: Best Usability approachUpdate list when a user is viewing the list without annoying themWhen would the best day to update your webpage be?What should happen when I add a Row to a paginated, sorted listShould I adopt infinite scrolling or classical pagination?How to show user that page objects automatically updateWhat is the best location to locate the comments section in a list pageBest way to combine filtering and selecting items in a listWhen one of two inputs must be updated to satisfy a consistency criteria, which should you update (if at all)?

            Вунгтау (аеропорт) Загальні відомості | Див. також | Посилання | Навігаційне меню10°22′00″ пн. ш. 107°05′00″ сх. д. / 10.36667° пн. ш. 107.08333° сх. д. / 10.36667; 107.0833310°22′00″ пн. ш. 107°05′00″ сх. д. / 10.36667° пн. ш. 107.08333° сх. д. / 10.36667; 107.083337731608Vinh AirportVinh airport facelift improves serviceвиправивши або дописавши їївиправивши або дописавши їїр

            Тонконіг бульбистий Зміст Опис | Поширення | Екологія | Господарське значення | Примітки | Див. також | Література | Джерела | Посилання | Навігаційне меню1114601320038-241116202404kew-435458Poa bulbosaЭлектронный каталог сосудистых растений Азиатской России [Електронний каталог судинних рослин Азіатської Росії]Малышев Л. Л. Дикие родичи культурных растений. Poa bulbosa L. - Мятлик луковичный. [Малишев Л. Л. Дикі родичи культурних рослин. Poa bulbosa L. - Тонконіг бульбистий.]Мятлик (POA) Сем. Злаки (Мятликовые) [Тонконіг (POA) Род. Злаки (Тонконогові)]Poa bulbosa Linnaeus, Sp. Pl. 1: 70. 1753. 鳞茎早熟禾 lin jing zao shu he (Description from Flora of China) [Poa bulbosa Linnaeus, Sp. Pl. 1: 70. 1753. 鳞茎早熟禾 lin jing zao shu he (Опис від Флора Китаю)]Poa bulbosa L. – lipnice cibulkatá / lipnica cibulkatáPoa bulbosa в базі даних Poa bulbosa на сайті Poa bulbosa в базі даних «Global Biodiversity Information Facility» (GBIF)Poa bulbosa в базі даних «Euro + Med PlantBase» — інформаційному ресурсі для Євро-середземноморського розмаїття рослинPoa bulbosa L. на сайті «Плантариум»