Magento how to stop /checkout/onepage/success/ redirecting

I need to style Magento’s order success page /checkout/onepage/success/, but because it redirects when there is no order session I can’t refresh the page to check my changes!

Anyone know how I can temporarily stop this redirect for testing purposes?

5 thoughts on “Magento how to stop /checkout/onepage/success/ redirecting”

  1. You can change the /app/code/core/Mage/Checkout/controllers/OnepageController.php file. Modify the successAction, so it looks like this:

     public function successAction()
        {
           /*
            $session = $this->getOnepage()->getCheckout();
            if (!$session->getLastSuccessQuoteId()) {
                $this->_redirect('checkout/cart');
                return;
            }
    
            $lastQuoteId = $session->getLastQuoteId();
            $lastOrderId = $session->getLastOrderId();
            $lastRecurringProfiles = $session->getLastRecurringProfileIds();
            if (!$lastQuoteId || (!$lastOrderId && empty($lastRecurringProfiles))) {
                $this->_redirect('checkout/cart');
                return;
            }
    
            $session->clear();
            */
    
    
            $this->loadLayout();
            $this->_initLayoutMessages('checkout/session');
            Mage::dispatchEvent('checkout_onepage_controller_success_action', array('order_ids' => array($lastOrderId)));
            $this->renderLayout();
        }
    

    Remember to remove the comments when you’re done!

  2. If anyone would be searching same solution for Magento 2 to stop redirecting from success page after page reload – here it is:

    Quick and dirty solution for debug:

    1. Open /vendor/magento/module-checkout/Controller/Onepage/Success.php
    2. Comment out code

    /* if (!$this->_objectManager->get('MagentoCheckoutModelSessionSuccessValidator')->isValid()) {
    return $this->resultRedirectFactory->create()->setPath('checkout/cart');
    }
    $session->clearQuote(); */

    Right solution using module can be found here https://gielberkers.com/style-checkoutonepagesuccess-page-magento-2/

  3. Firefox would let you disable HTTP redirects, but you may have to temporarily hack a controller to let you stay on the page anyway.

  4. I suggest to replace your successAction with this code:

    /**
     * Order success action
     */
    public function successAction()
    {
    
        $session = $this->getOnepage()->getCheckout();        
    
        $session->setLastSuccessQuoteId(20);  // <<< add your order entity ID
        $session->setLastQuoteId(20);  // <<< add your order entity ID
        $session->setLastOrderId(20);  // <<< add your order entity ID
    
        if (!$session->getLastSuccessQuoteId()) {
            $this->_redirect('checkout/cart');
            return;
        }
    
        $lastQuoteId = $session->getLastQuoteId();
        $lastOrderId = $session->getLastOrderId();
        $lastRecurringProfiles = $session->getLastRecurringProfileIds();
        if (!$lastQuoteId || (!$lastOrderId && empty($lastRecurringProfiles))) {
            $this->_redirect('checkout/cart');
            return;
        }
    
        #$session->clear();  // <<< comment it
    
        $this->loadLayout();
        $this->_initLayoutMessages('checkout/session');
        Mage::dispatchEvent('checkout_onepage_controller_success_action', array('order_ids' => array($lastOrderId)));
        $this->renderLayout();
    }
    

    Regards

Leave a Reply

Your email address will not be published. Required fields are marked *