Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 563
sulman Avatar asked Mar 24 '11 09:03

sulman


5 Answers

You can stop checkout success page redirection after refresh page, for styling and testing purposes, with this below code:

Go to this file:

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

and comment Out Line No : 22

//$session->clearQuote();

Now you will be able to refresh and debug success page without redirecting.

Don't forget to uncomment after working.

like image 98
Ajwad Syed Avatar answered Dec 02 '22 23:12

Ajwad Syed


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!

like image 45
mcmil Avatar answered Dec 02 '22 23:12

mcmil


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('Magento\Checkout\Model\Session\SuccessValidator')->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/

like image 31
Memfis Avatar answered Dec 02 '22 23:12

Memfis


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

like image 30
Michelangelo Avatar answered Dec 02 '22 21:12

Michelangelo


Whilst the code changes might be desirous, there is an extension specifically for this:

https://www.yireo.com/blog/1672-testing-the-magento-checkout-success-page

Disclosure: I am by no means a coder/dev, so the extension route appeals to me (even though I am comfortable making these changes).

like image 29
tmarsh1 Avatar answered Dec 02 '22 22:12

tmarsh1