0

I have 2 customizations of the FinalPriceBox block, one I would like to be the default for the site, the other only on the product view page. I've added a layout update view/frontend/layout/catalog_product_prices.xml to my custom module; in there I specify a custom block FinalPriceBoxGeneral and template final_price_general.phtml

<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="prices" xsi:type="array">
                    <item name="final_price" xsi:type="array">
                        <item name="render_class" xsi:type="string">Moxune\Amazing\Block\Catalog\Pricing\Render\FinalPriceBoxGeneral</item>
                        <item name="render_template" xsi:type="string">Moxune_Amazing::product/price/final_price_general.phtml</item>

This works to change the block & template everywhere on the site.

I've now tried to get change the block and template on just the product view page by adding to view/frontend/layout/catalog_product_view.xml in my plugin

<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="render.product.prices">
            <arguments>
                <argument name="default" xsi:type="array">
                    <item name="prices" xsi:type="array">
                        <item name="render_class" xsi:type="string">Moxune\Amazing\Block\Catalog\Pricing\Render\FinalPriceBoxDetail</item>
                        <item name="render_template" xsi:type="string">Moxune_Amazing::product/price/final_price_detail.phtml</item>

However this seems to have no effect on the product view page.

2

I got this working by creating a custom price type which you can read about in this magento dev doc. Specifically, they say

To add a custom price type, create a corresponding class extending AbstractPrice.

So I created a simple class Moxune\Amazing\Pricing\DetailPrice

namespace Moxune\Amazing\Pricing;

class DetailPrice extends \Magento\Catalog\Pricing\Price\FinalPrice
{
    const PRICE_CODE = 'detail_price';
}

add the new price type, detail_price in di.xml

<virtualType name="Magento\Catalog\Pricing\Price\Pool" type="Magento\Framework\Pricing\Price\Pool">
    <arguments>
        <argument name="prices" xsi:type="array">
            <item name="detail_price" xsi:type="string">Moxune\Amazing\Pricing\DetailPrice</item>
        </argument>
    </arguments>
</virtualType>

Now, the layout update for the product detail page becomes, changing price_type_code to detail_price (the new price type)

<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <container name="product.info.main" htmlTag="div" htmlClass="product-info-main" before="-">
                <container name="product.info.price" label="Product info auxiliary container" htmlTag="div" htmlClass="product-info-price" after="product.info.review">
                    <block class="Magento\Catalog\Block\Product\View" name="product.info.review" template="product/view/review.phtml" after="product.info.stock.sku" />
                    <block class="Magento\Catalog\Pricing\Render" name="product.price.final" after="product.info.sku">
                        <arguments>
                            <argument name="price_render" xsi:type="string">product.price.render.default</argument>
                            <argument name="price_type_code" xsi:type="string">detail_price</argument>
                            <argument name="zone" xsi:type="string">item_view</argument>
                        </arguments>
                    </block>
| improve this answer | |

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.