i have strange problem/issue/bug/feature ... whatever...

Case: Every day on defined times a module will import a few special prices for some products. So in this case the cache and the index has to be rebuild/flushed for each products which has to be updated.

How is it implemented yet: To improve the performance of the import and reduce the load on the database we use the \Magento\Catalog\Model\Product\Action class to update the prices for the products:

/** @var \Magento\Catalog\Model\Product\Action $productAction */
$productAction->updateAttributes([$id], [
  'special_price' => 123.45,
  'special_from_date' => '[...]'
], 0);

Lets get a little bit deeper into Magento and the indexer: There are a few triggers in the database, which listen on the EAV-Tables. So if there is an change on any table (in this case on catalog_product_entity_decimal) there will be an insert into table catalog_product_price_cl which triggers a reindex of the specific product. Thats pretty cool :)

BUT: It seems to be that the parent product of a configurable product will not be reindexed. The customer (shop owner) also reported, that this issue also happens on a normal simple product (without a parent).

So I added an additional trigger to reindex the product and it's parents:

/** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable $configurableTypeInstance */
/** @var \Magento\GroupedProduct\Model\Product\Type\Grouped $groupedTypeInstance */
/** @var \Magento\Catalog\Model\Indexer\Product\Full $indexer */

But this will also not solve the problem, that the prices will not correctly displayed in the frontend. After checking the values in the database I noticed that the prices in the indexes are correct. (I am not sure if the extra-index which I added, is still necessary)

So I checked the installed Varnish-Cache (full_page cache). The Varnish-Cache is also valid. (adding a cache-buster to the URL will get a fresh page .... with the outdated special price :( )

I also checked the Block-HTML & Collection Cache. Also valid. (Cleared it, the price is still outdated.)

Now I have no idea anymore. And this is the reason why i coming up to you. What am I doing wrong?

I look forward for your answers!

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.