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 开发者_C百科purposes?
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!
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.
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:
- Open /vendor/magento/module-checkout/Controller/Onepage/Success.php
- 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/
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
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).
Firefox would let you disable HTTP redirects, but you may have to temporarily hack a controller to let you stay on the page anyway.
精彩评论