3

How can we override/ extend a base layout file via Module in Magento2? For example, I need to override the "catalog_product_prices.xml" from

module-catalog/view/base/layout/catalog_product_prices.xml

to my module say "Mynamespace_Mymodule"?

The content of xml file is

<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
<block class="Magento\Framework\Pricing\Render\RendererPool" name="render.product.prices">
    <arguments>
        <argument name="default" xsi:type="array">
            <item name="default_render_class" xsi:type="string">Magento\Catalog\Pricing\Render\PriceBox</item>
            <item name="default_render_template" xsi:type="string">Magento_Catalog::product/price/default.phtml</item>
            <item name="default_amount_render_class" xsi:type="string">Magento\Framework\Pricing\Render\Amount</item>
            <item name="default_amount_render_template" xsi:type="string">Mymodule_CustomPrice::product/price/amount/default.phtml</item>
            <item name="prices" xsi:type="array">
                <item name="special_price" xsi:type="array">
                    <item name="render_template" xsi:type="string">Magento_Catalog::product/price/special_price.phtml</item>
                </item>
                <item name="tier_price" xsi:type="array">
                    <item name="render_template" xsi:type="string">Magento_Catalog::product/price/tier_prices.phtml</item>
                </item>
                <item name="final_price" xsi:type="array">
                    <item name="render_class" xsi:type="string">Magento\Catalog\Pricing\Render\FinalPriceBox</item>
                    <item name="render_template" xsi:type="string">Magento_Catalog::product/price/final_price.phtml</item>
                </item>
                <item name="custom_option_price" xsi:type="array">
                    <item name="amount_render_template" xsi:type="string">Magento_Catalog::product/price/amount/default.phtml</item>
                </item>
                <item name="configured_price" xsi:type="array">
                    <item name="render_class" xsi:type="string">Magento\Catalog\Pricing\Render\ConfiguredPriceBox</item>
                    <item name="render_template" xsi:type="string">Magento_Catalog::product/price/configured_price.phtml</item>
                </item>
            </item>
            <!--<item name="adjustments" xsi:type="array"></item>-->
        </argument>
    </arguments>
</block>

And here is the image of my folder structure

enter image description here

1

You have to just create below path,

Mynamespace_Mymodule/view/frontend/layout/catalog_product_prices.xml

You have to create directory structure same as core module in your Custom module and do changes in xml file.

| improve this answer | |
  • Hi @Rakesh I have created the file under Mynamespace_CustomPrice/view/frontend/layout/catalog_product_prices.xml and changed the phtml in the xml as <item name="default_amount_render_template" xsi:type="string">MynameSpace_CustomPrice::product/price/amount/default.phtml</item> But it is not taking. Can I include the "base" folder there? – Varun Jyothi Jan 24 '17 at 10:20
  • please post your full code of xml – Rakesh Jesadiya Jan 24 '17 at 10:23
  • Hi @Rakesh, iI have updated the question. Please have alook – Varun Jyothi Jan 24 '17 at 10:42
  • which line you have override from core file? – Rakesh Jesadiya Jan 24 '17 at 11:01
  • Have you keep at start of xml file, <?xml version="1.0"?> – Rakesh Jesadiya Jan 24 '17 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.