I want to alterate under specefic conditions the final_price in the front product view (not changing his value but only adding some text).

Ex : Instead of printing 5€ , I will print 5€ HT

In order to do such a thing, I used a preference on


And this is approximatively what the override does

public function render($priceCode, SaleableInterface $saleableItem, array $arguments = [])
    $useArguments = array_replace($this->_data, $arguments);

    /** @var \Magento\Framework\Pricing\Render\RendererPool $rendererPool */
    $rendererPool = $this->priceLayout->getBlock('render.product.prices');
    if (!$rendererPool) {
        throw new \RuntimeException('Wrong Price Rendering layout configuration. Factory block is missed');

    // obtain concrete Price Render
    $priceRender = $rendererPool->createPriceRender($priceCode, $saleableItem, $useArguments);
    $priceHtmlBlock = $priceRender->toHtml();
    if($priceCode == 'final_price'){
        $productId = $saleableItem->getId();
        $product = $this->productCollectionFactory->create()->getItemById($productId);

        $currentStore = $this->helperPro->getCurrentStore();
        $isStorePro = $this->helperPro->isProStore($currentStore->getCode());

        $productAttributeSetId = $product->getAttributeSetId();

        $attributeSet = $this->attributeSetFactory->create()->getItemById($productAttributeSetId);
        $attributeValue = $attributeSet->getAttributeSetName();
        $isCoffee = ($attributeValue == 'Cafe');
        $isAccessories = ($attributeValue == 'Accessoire');
        if($isStorePro && ($isCoffee || $isAccessories)){
            $priceHtmlBlock = str_replace('€','€ HT',$priceHtmlBlock);
    return $priceHtmlBlock;

This is working, the html returned has the HT I'm looking for.

The issue is that even after doing that, in front I will still have 5€.

I told myself it might be a cache issue, so I've been setup:upgrade to clean the caches.

And here I saw the HT appearing. I thought it was a win...but as the js continue loading...at some point one of them ignored my modification and setup again the old value without HT.

Any ideas ?

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.