In Magento, i found a problem after upgrading the version from 1.7 to 1.9, after add to cart a product when I click on “Place order” button from one-page checkout it does not proceed to order success page but stay on the same page after displaying the image attempts to load for a flick second.
After inspecting the issue, I found that when “Place order” button is clicked Magento sends an AJAX request to this http://www.your-domain.com/index.php/checkout/onepage/saveOrder/ URL with POST method and the status code return from the server is 302 which means Moved Temporarily.
As you can see in the above image (in chrome browser with inspect element on Network tab), after clicking place order it sends a request to /checkout/onepage/saveOrder/ and the status code from the server is 302 Moved Temporarily.
Now to know why the server returned 302 I checked app/code/core/Mage/Checkout/controllers/OnepageController.php this file (which is upgraded to 1.9 controller file) and see
public function saveOrderAction() { if (!$this->_validateFormKey()) { $this->_redirect('*/*'); return; } if ($this->_expireAjax()) { return; } $result = array(); ...
so it has a form key validation at the very beginning of the method saveOrderAction.
then i compare this file with same (app/code/core/Mage/Checkout/controllers/OnepageController.php) older version 1.7 file and i found in older version 1.7 does not any form key validation.
public function saveOrderAction() { if ($this->_expireAjax()) { return; } $result = array(); ...
The problem happened when i upgraded the version from 1.7 to 1.9, the system updated only the magento core files but not my custom theme files which should send a validation key along with from data to place a new order.
To get this issue resolved /app/design/frontend/default/your-theme/template/checkout/onepage/review/info.phtml open this file with your favorite editor and replace the following code (you will find this snippet at the end of the file).
<script type="text/javascript"> //<![CDATA[ review = new Review('<?php echo $this->getUrl('checkout/onepage/saveOrder') ?>', '<?php echo $this->getUrl('checkout/onepage/success') ?>', $('checkout-agreements')); //]]> </script>
with this.
<script type="text/javascript"> //<![CDATA[ review = new Review('<?php echo $this->getUrl('checkout/onepage/saveOrder', array('form_key' => Mage::getSingleton('core/session')->getFormKey())) ?>', '<?php echo $this->getUrl('checkout/onepage/success') ?>', $('checkout-agreements')); //]]> </script>
That is it. Same thing may also happen if you applied newly released patch to your older magento versions like 1.7 or 1.8.