3

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' [] []
4
  • What do you want to do in onepage.php file? Commented Dec 6, 2016 at 5:40
  • I want to add new function . i am learning magento 2 and performing overriding task Commented Dec 6, 2016 at 5:45
  • please add your function with code which you want to add inside onepage file Commented Dec 6, 2016 at 5:47
  • it's simple function which return only text return 'Test'; i just want to test Commented Dec 6, 2016 at 5:49

1 Answer 1

3

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');
3
  • here is my template file Mymodule/Test/View/frontend/templates/onepage.phtml Commented Dec 6, 2016 at 5:52
  • View should be lowercase - Mymodule/Test/view/frontend/templates/onepage.phtml Commented Dec 6, 2016 at 5:55
  • ohhh just silly mistake now it's working thanks Commented Dec 6, 2016 at 5:57

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.