5

I am facing one issue in block rewrite. I am trying to rewrite app/code/Magento/Catalog/view/base/layout/catalog_product_prices.xml I want to Call my own tier_prices.phtml

<code>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/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">Magento_Catalog::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="group_price" xsi:type="array">
                        <item name="render_template" xsi:type="string">Magento_Catalog::product/price/group_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/option.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>
                </argument>
        </arguments>
    </block>
</layout>
</code>

Can anybody help me regarding this?

Thanks in advance.

2 Answers 2

9

Suppose package:Learning and module: Custom

Module.xml looks like

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Learning_Custom" setup_version="2.0.0">
        <sequence>
            <module name="Magento_Catalog"/>
        </sequence>
    </module>
</config>

And then create a layout xml following path -> app/code/Learning/Custom/view/frontend/layout/catalog_product_prices.xml

<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/layout_generic.xsd">
    <referenceBlock name="render.product.prices">
        <arguments>
            <argument name="default" xsi:type="array">
                <item name="prices" xsi:type="array">
                    <item name="tier_price" xsi:type="array">
                        <item name="render_template" xsi:type="string">Learning_Custom::product/price/tier_prices.phtml
                    </item>
                </item>
            </argument>
        </arguments>
    </referenceBlock>
</layout>

Create template inside your module or copy base template file inside your module path should be -> app/code/Learning/Custom/view/frontend/templates/product/price/tier_prices.phtml

5
  • Thanks for your answer but its not working. Oct 24, 2015 at 8:35
  • It's tested code. Could you run following command after module creation -> php bin/magento setup:upgrade . Clear magento cache.
    – Sohel Rana
    Oct 24, 2015 at 9:05
  • Yes, Its working after command run. Oct 24, 2015 at 10:47
  • not working for me. has this method changed in latest magento ? May 27, 2016 at 2:28
  • Works for me. I would like to do it only on certain pages though..
    – Erfan
    Oct 12, 2017 at 7:16
2

You can do like this

<referenceBlock name='contactForm'>
    <action method='setTemplate'>
        <argument name='template' xsi:type='string'>Vendorname_Modulename::form_new.phtml</argument>
    </action>
</referenceBlock>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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