Previous Article

Testing your Magento success page

Next Article

There are several plugins that add functionality to the order success page in Magento, testing to make sure the styling matches your site layout can become tedious if you have to enter multiple orders.

I've found a way to circumvent the need to enter orders to view the page, it does require edits to the Magento core files and should be changed back as soon as you've completed your testing. Failure to do so will prevent the system functioning correctly for all future orders!

For this to work you need to have 1 successful order in the system as we need to reference this in the update.

Open /app/code/core/Mage/Checkout/controllers/OnepageController.php you need to look for the successAction() method around line 275 as this is method that controls the success page logic. It should look very similar to the code below.

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();
}

First you need to comment out the code that handles redirecting if the required sessions aren't set. If this isn't done then you will get redirected back to the cart page.

/*
$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();
*/

Then we need to add some extra code immediately after the closing comment that sets the successful quote ID and Order ID, this will then display the information on the success page. To get this information simply navigate to your database and access the sales_flat_order table you will need to enter the entity_id field into the $orderId variable and the quote_id field into the $quoteId variable.

$session = $this->getOnepage()->getCheckout();

$orderId = 1;
$quoteId = 2;

$session->setLastSuccessQuoteId($quoteId);
$session->setLastQuoteId($quoteId);
$session->setLastOrderId($orderId);

Now you have made this update your code should look like the below.

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();
  */

  /* TESTING */
  $session = $this->getOnepage()->getCheckout();

  $orderId = 1;
  $quoteId = 2;

  $session->setLastSuccessQuoteId($quoteId);
  $session->setLastQuoteId($quoteId);
  $session->setLastOrderId($orderId);
  /* EO: TESTING */

  $this->loadLayout();
  $this->_initLayoutMessages('checkout/session');

  Mage::dispatchEvent('checkout_onepage_controller_success_action', array('order_ids' => array($lastOrderId)));

  $this->renderLayout();
}

Once you upload this page you can simply navigate to your Magento checkout success page, the url should be http://www.yourdomain.co.uk/checkout/onepage/success/. You should see the results of the order you entered. Now you can refresh as much as you want to get your styling perfect.

Don't forget to remove the changes before your site goes live to avoid any site issues.

Avatar of Clive Walkden

Clive Walkden

Posted:

Latest Articles

Linux command line tools, installations etc

Linux

How to Install NordLayer VPN Client on Ubuntu 20.04 and Connect to a Virtual Network

A simple to follow installation guide for NordLayer VPN

MySQL usage, tweaks and learnings

MySQL

Mastering MySQL Database Imports on Linux

Learn efficient ways to import MySQL databases on Linux using the mysql command-line client. Explore the --source option and < operator for seamless data migration. Master MySQL imports on Linux with our comprehensive guide.

DevOps principles and tool usage

DevOps

Mastering SSH Key Conversions for DevOps

A guide to convert SSH keys from one version to another using Linux CLI