Usage of ob_start() in fixing one-page checkout issues

One page checkout steps are so sensitive that even a single character echoed from anywhere (due to some mistakes or PHP errors) will make your checkout steps not working.

I just recently faced one issue: One-page checkout was not redirecting to order confirmation page after clicking on Place Order button (Review Page). When I checked the console via firebug i found the following ajax response:

f{"success":true,"error":false}

You can note there is extra character ‘f’ which makes the JSON response invalid and the opcheckout.js can’t operate properly & hence no further redirection to third party or order confirmation page.

Since the client was in rush, i solved the issue using the concept of ob_start() function of php as:
File: app/code/core/Mage/Checkout/OnepageController.php

public function saveOrderAction() 
{
    ob_start();
    //....
    $outputBuffer = ob_get_contents();
    ob_end_clean();
    Mage::log('outputTrapped::' . $outputBuffer, null, 'onepagecheckout.log');
    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}

By using the ob_start() on the start of the function, output are captured in the buffer instead of direct output to the browser.

I know best bet is to find the related place and prevent the direct output to the browser but I just posted this as an example on dealing with ob_start() in case of one-page checkout steps.

Hope this gave some idea.

3 thoughts on “Usage of ob_start() in fixing one-page checkout issues”

  1. Thank you for sharing this great post.

    That is what I am looking for and you made my day.

    Just keep doing good job and you will make people happy!

    Thank You Once Again 🙂

    Reply
  2. Thanks a lot for this (and all the other) great articles. I think it’s useful with other functions too, like those with redirections, mails, …

    Reply
  3. Hello Thank you for your nice post, i had the same problem

    00000000{“success”:true,”error”:false}, i got 0000 i don’t know why i’m gettings this as i followed your post but still i got the same problem please guide me to resolve the issue

    Many Thanks Vishwa

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.