Simply put, I'm trying to load order information on the Onepage Checkout Success page. I have a module set up, these files are under app/code/Tainted/Checkout:

registration.php (standard)


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="Magento\Checkout\Block\Onepage\Success" type="Tainted\Checkout\Block\Onepage\Success" />


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Tainted_Checkout" setup_version="0.0.1"/>

Finally, Block/Onepage/Success.php:

namespace Tainted\Checkout\Block\Onepage;

class Success extends \Magento\Checkout\Block\Onepage\Success
     * Prepares block data
     * @return void
    protected function prepareBlockData()
        $order = $this->_checkoutSession->getLastRealOrder();

                'is_order_visible' => $this->isVisible($order),
                'view_order_url' => $this->getUrl(
                    ['order_id' => $order->getEntityId()]
                'print_url' => $this->getUrl(
                    ['order_id' => $order->getEntityId()]
                'can_print_order' => $this->isVisible($order),
                'can_view_order'  => $this->canViewOrder($order),
                'order_id'  => $order->getIncrementId(),
                'grand_total' => $order->getGrandTotal(),
                'delivery_method' => $order->getAddressShippingMethod(),
                'items' => $order->getAllItems()

The prepareBlockData function is copied from the original class and I've added a few extra lines to it to pass more data to the frontend template. E.g. grand total.

However, when I checkout the success page is missing the success.phtml template and the only errors I can find appear in the system.log as follows:

[2017-04-27 16:17:41] main.CRITICAL: Invalid template file: 'button.phtml' in module: 'Tainted_Checkout' block's name: 'checkout.success.print.button' [] []
[2017-04-27 16:17:41] main.CRITICAL: Invalid template file: 'success.phtml' in module: 'Tainted_Checkout' block's name: 'checkout.success' [] []

I haven't touched those templates yet but that error reads as though they're missing, not broken anyway. I've tried copying them in to app/design/frontend/Tainted/theme/Magento_Checkout/templates and I've copied the checkout_onepage_success.xml file in to the layout folder but that hasn't helped either.

It feels like I'm trying to do something very simple (in Magento 2 terms) but I can't see where I've gone wrong. Any help would be greatly appreciated.

2 Answers 2


The templates are being referenced like template="button.phtml" in checkout_onepage_success.xml so you need to add

protected function _construct()

to your block to tell magento where to look for those templates, otherwise it looks in the current module.

Usually templates are referenced with the module name, e.i. Some_Module::template.phtml, in which case you wouldn't have to do this.

  • thanks Aaron, been banging my head against a wall trying to override \Magento\Sales\Block\Order\History and even without a single function, the sales order history stopped loading. This solved it
    – pixiemedia
    Sep 2, 2017 at 15:56

Try this:

If you don't already have a default.xml file in your module, create it at view/frontend/layout/default.xml. Then add the following handle at the top, right after the <page> tag:

<update handle="checkout_onepage_success"/>

That will pull in the layout xml for the base module into your module. To be explicitly clear about that process, here's the full code:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="checkout_onepage_success"/>

This should pull in the XML into your module. I haven't tried it but give it a go and let me know if that works.

  • 2
    Very close to the solution and it got me thinking. I copied the success and button phtml files in to the modules templates folder and that fixed the problem. I'm still not sure why it wasn't falling back to the templates from the base Magento module though. Apr 27, 2017 at 16:57
  • In the end the net effect of this was to show the onepage success template on all pages. By a happy accident that made debugging and styling the page template really easy. Apr 28, 2017 at 8:29

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.