Question

I am trying to override Magento\Checkout\Block\Onepage and it's display blank page

Here is my Mymodule/Test/etc/di.xml

<?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <preference for="Magento\Checkout\Block\Onepage" type="Mymodule\Test\Block\Onepage" />
    </config>

Mymodule/Test/Block/Onepage.php

<?php
    namespace Mymodule\Test\Block;
    class Onepage extends \Magento\Checkout\Block\Onepage
    {

    }

?>

system.log is

[2016-12-06 05:28:57] main.INFO: Cache file with merged layout: LAYOUT_frontend_STORE1_59779d713e3fbb1543956771d12cf7164 and handles default, checkout_index_index: Please correct the XML data and try again.  [] []
[2016-12-06 05:28:57] main.INFO: Cache file with merged layout: LAYOUT_frontend_STORE1_5177627f91af678a9b03e993f1a91917f and handles checkout: Please correct the XML data and try again.  [] []
[2016-12-06 05:28:57] main.CRITICAL: Broken reference: the 'header.panel.wrapper' element cannot be added as child to 'header.container', because the latter doesn't exist [] []
[2016-12-06 05:28:57] main.CRITICAL: Broken reference: the 'header-wrapper' element cannot be added as child to 'header.container', because the latter doesn't exist [] []
[2016-12-06 05:28:57] main.CRITICAL: Broken reference: the 'navigation.sections' element cannot be added as child to 'page.top', because the latter doesn't exist [] []
[2016-12-06 05:28:57] main.CRITICAL: Broken reference: the 'top.container' element cannot be added as child to 'page.top', because the latter doesn't exist [] []
[2016-12-06 05:28:57] main.CRITICAL: Broken reference: the 'breadcrumbs' element cannot be added as child to 'page.top', because the latter doesn't exist [] []
[2016-12-06 05:28:57] main.CRITICAL: Broken reference: the 'footer' element cannot be added as child to 'footer-container', because the latter doesn't exist [] []
[2016-12-06 05:28:57] main.CRITICAL: Broken reference: the 'catalog.compare.sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2016-12-06 05:28:57] main.CRITICAL: Broken reference: the 'sale.reorder.sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2016-12-06 05:28:57] main.CRITICAL: Broken reference: the 'wishlist_sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2016-12-06 05:28:57] main.CRITICAL: Broken reference: the 'footer-top' element cannot be added as child to 'footer-container', because the latter doesn't exist [] []
[2016-12-06 05:28:57] main.CRITICAL: Broken reference: the 'footer-center' element cannot be added as child to 'footer-container', because the latter doesn't exist [] []
[2016-12-06 05:28:57] main.CRITICAL: Broken reference: the 'header.panel.wrapper' tries to reorder itself towards '', but their parents are different: 'header.container' and '' respectively. [] []
[2016-12-06 05:28:57] main.CRITICAL: Broken reference: the 'navigation.sections' tries to reorder itself towards '', but their parents are different: 'page.top' and '' respectively. [] []
[2016-12-06 05:28:57] main.CRITICAL: Broken reference: the 'footer-center' tries to reorder itself towards 'footer-top', but their parents are different: 'footer-container' and '' respectively. [] []
[2016-12-06 05:28:58] main.INFO: Cache file with merged layout: LAYOUT_frontend_STORE1_56f1b068ec7ccf4878f9284dd1137afd1 and handles catalog_product_prices: Please correct the XML data and try again.  [] []
[2016-12-06 05:28:58] main.CRITICAL: Invalid template file: 'onepage.phtml' in module: 'Mymodule_Test' block's name: 'checkout.root' [] []
Was it helpful?

Solution

Unless your also overriding the template in your module, you need to change the module name for your class, otherwise magento looks for the template file in your module instead of the core module. You can do it by adding this method:

public function getModuleName()
{
    return 'Magento_Checkout';
}

or by setting it in the constructor like this:

$this->setModuleName('Magento_Checkout');
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top