I want to redirect to cart from onepage checkout.

When customer change address postcode of shipping that time i want to redirect to cart page.

in this i am matching the postcode of billing and shipping if its not same than i want to redirect to cart page in Onepagecontroller.php I am changing this in saveShipping method:

if($pcode == 0){


but its not redirect to cart page,How can i do this?


1 Answer 1


Magento saves all checkout step data using AJAX.

Magento has a feature to go back to the cart page whenever an AJAX request goes to onFailure state during any of the checkout steps.

            onComplete: function(){
ajaxFailure: function(){
        location.href = this.failureUrl;

An AJAX response calls the onFailure() function whenever a header response isHTTP/1.1 500 Internal Server Error`.

 $this->getResponse()->clearHeaders()->setHeader('HTTP/1.1', '500 Internal Server Error')->sendResponse();

Or use 403 (permission denied):

$this->getResponse()->clearHeaders()->setHeader('HTTP/1.1', '403 Forbidden')->sendResponse()->sendResponse();

...Or 503 (service unavailable):

$this->getResponse()->clearHeaders()->setHeader('HTTP/1.1', '503 Service Unavailable')->sendResponse();

In your case you need to send a 500/403/503 header response code to ensure that the Prototype AJAX onFailure is called.

saveShipping() function saves shipping data using AJAX` and the response is the JSON content.

On receipt of this response the checkout is going to move to the next step.

That means that $this->_redirect('checkout/cart'); is not being run.

  • i m set error to 1 but its not redirecting
    – Newbie
    Nov 5, 2015 at 7:43
  • wait.. i will give u solution
    – Amit Bera
    Nov 5, 2015 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.