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)
etc/di.xml
<?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" />
</config>
etc/module.xml
<?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"/>
</config>
Finally, Block/Onepage/Success.php:
<?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();
$this->addData(
[
'is_order_visible' => $this->isVisible($order),
'view_order_url' => $this->getUrl(
'sales/order/view/',
['order_id' => $order->getEntityId()]
),
'print_url' => $this->getUrl(
'sales/order/print',
['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.