0

How to override Magento/Catalog/view/base/templates/product/price/amount/default.phtml

My layout file:

Dckap/Cnet/view/base/layout/catalog_product_prices.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<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="custom_option_price" xsi:type="array">               
                <item name="default_amount_render_template" xsi:type="string">Dckap_Cnet::product/price/amount/default.phtml</item>
            </argument>
        </arguments>
    </block>
</layout>

View file: Dckap/Cnet/view/base/templates/product/product/amount/default.phtml

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>

<?php /** @var \Magento\Framework\Pricing\Render\Amount $block */ ?>
Custom File
<span class="price-container <?= /* @escapeNotVerified */ $block->getAdjustmentCssClasses() ?>"
        <?= $block->getSchema() ? ' itemprop="offers" itemscope itemtype="http://schema.org/Offer"' : '' ?>>
    <?php if ($block->getDisplayLabel()): ?>
        <span class="price-label"><?= /* @escapeNotVerified */ $block->getDisplayLabel() ?></span>
    <?php endif; ?>
    <span <?php if ($block->getPriceId()): ?> id="<?= /* @escapeNotVerified */ $block->getPriceId() ?>"<?php endif;?>
        <?= ($block->getPriceDisplayLabel()) ? 'data-label="' . $block->getPriceDisplayLabel() . $block->getPriceDisplayInclExclTaxes() . '"' : '' ?>
        data-price-amount="<?= /* @escapeNotVerified */ $block->getDisplayValue() ?>"
        data-price-type="<?= /* @escapeNotVerified */ $block->getPriceType() ?>"
        class="price-wrapper <?= /* @escapeNotVerified */ $block->getPriceWrapperCss() ?>"
    ><?= /* @escapeNotVerified */ $block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer()) ?></span>
    <?php if ($block->hasAdjustmentsHtml()): ?>
        <?= $block->getAdjustmentsHtml() ?>
    <?php endif; ?>
    <?php if ($block->getSchema()): ?>
        <meta itemprop="price" content="<?= /* @escapeNotVerified */ $block->getDisplayValue() ?>" />
        <meta itemprop="priceCurrency" content="<?= /* @escapeNotVerified */ $block->getDisplayCurrencyCode() ?>" />
    <?php endif; ?>
</span>
```

0

In module.xml File :-

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

In Layout File:-

<?xml version="1.0"?>
<referenceBlock name="render.product.prices">
    <arguments>
        <argument name="default" xsi:type="array">               
            <item name="default_amount_render_template" xsi:type="string">Dckap_Cnet::product/price/amount/default.phtml</item>
        </argument>
    </arguments>
</referenceBlock>
  • Our layout file and above files are same. – Soundararajan m Mar 18 '19 at 11:03
  • Your just copied from my layout file – Soundararajan m Mar 18 '19 at 11:04
  • argument name "default" – Rk Rathod Mar 18 '19 at 11:05
  • After changing your file still now not reflecting – Soundararajan m Mar 18 '19 at 11:06
  • check updated answer – Rk Rathod Mar 18 '19 at 11:35
0

I have recently worked on this above requirement.

I will share my suggestion. Please check whether it works for you.

Vendor/ModuleName/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="TM_PlpPrice" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Catalog"/>
            <module name="Magento_CatalogWidget"/>
            <module name="Magento_Widget"/>
        </sequence>
    </module>
</config>

Vendor/ModuleName/view/base/layout/catalog_product_prices.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
    <referenceBlock name="render.product.prices">
        <arguments>
            <argument name="default" xsi:type="array">
                <item name="default_amount_render_template" xsi:type="string">Vendor_ModuleName::product/price/amount/default.phtml</item>
                <item name="prices" xsi:type="array">
                    <item name="custom_option_price" xsi:type="array">
                        <item name="amount_render_template" xsi:type="string">Vendor_ModuleName::product/price/amount/default.phtml</item>
                    </item>
                </item>
            </argument>
        </arguments>
    </referenceBlock>
</layout>

And I have written my custom code on

Vendor/ModuleName/product/price/amount/default.phtml

It works for me.

  • Not working.... What did you used it for??? Did you added a session or something? – Zeeshan Oct 31 '19 at 13:50
  • I need to customize the PLP page pricing details based on customer group. So I was used this approach. No, I didn't add any session. – Ramya Nov 1 '19 at 7:23
  • Okay, thanks. I wanted to use it for session. – Zeeshan Nov 1 '19 at 10: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.