1

I have a Magento 2.2.4 store where prices are automatically updated every 10 minutes from an stock management system. This works fine on product pages and any custom 'featured products' sections etc, but on category pages the prices are stuck and not updating.

Any way I can change this so the prices are not cached on category pages?

-1

You can disable caching in this class "FinalPriceBox"

I used to do override this class

\Magento\Catalog\Pricing\Render\FinalPriceBox

add to your di.xml file this line

<preference for="Magento\Catalog\Pricing\Render\FinalPriceBox"  type="{vendor}\{module}\Pricing\Render\FinalPriceBox"/>

then create FinalPriceBox.php file in this path **{vendor}{module}\Pricing\Render**

<?php

namespace {vendor}\{module}\Pricing\Render;

use Magento\Catalog\Pricing\Price;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Module\Manager;
use Magento\Framework\Pricing\Render;
use Magento\Framework\Pricing\Render\PriceBox as BasePriceBox;
use Magento\Msrp\Pricing\Price\MsrpPrice;
use Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\Pricing\SaleableInterface;
use Magento\Framework\Pricing\Price\PriceInterface;
use Magento\Framework\Pricing\Render\RendererPool;

class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
{

    public function getCacheLifetime()
    {
            return null;
    }
}
  • Please keep in mind that by adding this the entire category page will become non-cacheable. As the Magento 2 developer documentation notes: Do not configure content pages (i.e., catalog, product, and CMS pages) to be uncacheable. Doing so has an adverse affect on performance. – Kenny Jul 5 at 12:20

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.