2

I want to add custom notices directly behind every price on product detail and category pages. On product detail page this works fine with layout.xml:

<referenceContainer name="product.info.price">
    <block before="product.info.stock.sku" after="product.price.final" class="..." name="after_price" as="after.price" template="..."/>
</referenceContainer>

But actually that doesn't work for category pages. If I look into Magento\Catalog\Block\Product\ListProduct which is the block on the category page, there is a function called getProductPrice() which is called for price rendering. Internally it calls getPriceRender() which calls a block from layout which renders the price:

$this->getLayout()->getBlock('product.price.render.default');

So I thought I just create a catalog_category_view.xml layout file with the following content:

<referenceBlock name="product.price.render.default">
    <block class="..." before="category.product.type.details.renderers" template="..."/>
</referenceBlock>

But unfortunately this is not the solution, it doesn't work. I thought the reason is that product.price.render.default is added dynamically as it only can be found on product detail page's layout xml files and not category layout files. But I can't find where it is added. And why does my layout file not work? I don't want to overwrite the template Magento_Catalog::product/list.phtml as different themes will overwrite my changes.

  • what is the problem behind override template files? This is possible using override template files from core – Rakesh Jesadiya May 6 '16 at 7:21
  • When you use a theme the template gets overridden again and my changes are lost. – tester May 6 '16 at 9:03
  • Perhaps try using a custom Renderer to avoid any .phtml changes? blog.belvg.com/renderer-in-magento-2-0.html – B00MER May 11 '16 at 1:44

Your Answer

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

Browse other questions tagged or ask your own question.