Magento2 – Checkout Index XML Not Overriding

checkoutmagento2xml

I am creating Magento 2 theme using the blank theme as the base. Now the problem is Magento 2 blank theme removing the top header, search bar, mini cart on http://www.yourdomain/checkout page

vendor\magento\theme-frontend-blank\Magento_Checkout\layoutcheckout_cart_index.xml

they have removed using

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot; layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="minicart" remove="true"/>
        <referenceContainer name="header.panel" remove="true"/>
        <referenceBlock name="top.search" remove="true"/>
        <referenceBlock name="catalog.compare.link" remove="true"/>
        <referenceBlock name="catalog.topnav" remove="true"/>
        <referenceContainer name="footer-container" remove="true"/>
    </body>
</page>

If I override the same theme with here it is not working. What I want is not remove those elements so I have to override XML file here

app\design\frontend\NAMESPACE\themename\Magento_Checkout\layout\checkout_index_index.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="minicart" remove="false"/>
        <referenceContainer name="header.panel" remove="false"/>
        <referenceBlock name="top.search" remove="false"/>
        <referenceBlock name="catalog.compare.link" remove="false"/>
        <referenceBlock name="catalog.topnav" remove="false"/>
        <referenceContainer name="footer-container" remove="false"/>

    </body>
</page>

I have written remove="false" to not to remove those elements from checkout.

But it is still remove theme an idea ?

I have checked after clear cache and re-indexing but not working

Best Answer

To override a layout XML file (rather than extend) you need to add it to a slightly different directory, more info can be found in the official docs

<theme_dir>
  |__/<Namespace_Module>
    |__/layout
      |__/override
         |__/theme
            |__/<Parent_Vendor>
               |__/<parent_theme>
                  |--<layout1>.xml
                  |--<layout2>.xml

So for your case where you need to override Magento\Blank it would be:

app\design\frontend\NAMESPACE\themename\Magento_Checkout\layout\override\theme\Magento\blank\checkout_index_index.xml

If overriding the theme doesn't work, make sure you don't need to override the layout coming from the module itself rather than the theme's XML. To do this read the 'Override base layouts' section in the docs linked above.

Related Topic