How to test or style the Order Success Page Or how to stop Success Page redirecting in Magento 2

magento.stackexchange https://magento.stackexchange.com/questions/313218

  •  14-04-2021
  •  | 
  •  

Question

I have an issue in Magento 2 success page, its showing blank after successfully placed order. I am trying to debug it but the issue is when trying to refresh the success page after changing the code it a clear current session and redirecting to the home page. I want to stop redirecting the success page and stay the same page when the refresh page.

Have anybody Idea in Magento 2? Please let me know if anyone already does this?

Was it helpful?

Solution

You can stop checkout success page redirection after refresh page, check below code

vendor/magento/module-checkout/Controller/Onepage/Success.php

Comment Out Line No : 22

//$session->clearQuote();

Now you can debug checkout success page.

OTHER TIPS

Kindly open Magento\Checkout\Controller\Onepage\Success.php and comment below line

$session->clearQuote(); 

for temporary purpose.

You can also install the Magepal module which works perfectly without any code modification. Make sure to install it as a dev requirements:

composer require --dev magepal/magento2-preview-checkout-success-page

You can stop checkout success page redirection after refresh page, check below code

vendor/magento/module-checkout/Controller/Onepage/Success.php

Comment Out Line No : 22 And in Magento 2.3... Line No : 26

//$session->clearQuote();

Ex :-

public function execute()
    {
        $session = $this->getOnepage()->getCheckout();
        if (!$this->_objectManager->get(\Magento\Checkout\Model\Session\SuccessValidator::class)->isValid()) {
            return $this->resultRedirectFactory->create()->setPath('checkout/cart');
        }

        // $session->clearQuote();            ***** COMMENT THIS LINE *****

        //@todo: Refactor it to match CQRS
        $resultPage = $this->resultPageFactory->create();
        $this->_eventManager->dispatch(
            'checkout_onepage_controller_success_action',
            [
                'order_ids' => [$session->getLastOrderId()],
                'order' => $session->getLastRealOrder()
            ]
        );
        return $resultPage;
    }

Now you can debug checkout success page.

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