Skip to content

Commit cb820af

Browse files
committed
ACP2E-1524: Page Cache is not cleared for the parent product on the child product save
1 parent 4d76fd7 commit cb820af

File tree

1 file changed

+20
-9
lines changed
  • app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel

1 file changed

+20
-9
lines changed

app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Product.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use Magento\Catalog\Api\Data\ProductAttributeInterface;
1212
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
13-
use Magento\Catalog\Model\Indexer\Product\Price\Processor;
1413
use Magento\Catalog\Model\Product as ProductModel;
1514
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
1615
use Magento\ConfigurableProduct\Api\Data\OptionInterface;
@@ -20,9 +19,13 @@
2019
use Magento\Framework\App\ObjectManager;
2120
use Magento\Framework\DataObject;
2221
use Magento\Framework\Indexer\ActionInterface;
22+
use Magento\Framework\Indexer\CacheContext;
23+
use Magento\Indexer\Model\Indexer\DeferredCacheCleaner;
2324

2425
/**
2526
* Plugin product resource model
27+
*
28+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2629
*/
2730
class Product
2831
{
@@ -52,9 +55,14 @@ class Product
5255
private $filterBuilder;
5356

5457
/**
55-
* @var Processor
58+
* @var DeferredCacheCleaner
59+
*/
60+
private $cacheCleaner;
61+
62+
/**
63+
* @var CacheContext
5664
*/
57-
private $priceIndexProcessor;
65+
private $cacheContext;
5866

5967
/**
6068
* Initialize Product dependencies.
@@ -64,15 +72,17 @@ class Product
6472
* @param ProductAttributeRepositoryInterface|null $productAttributeRepository
6573
* @param SearchCriteriaBuilder|null $searchCriteriaBuilder
6674
* @param FilterBuilder|null $filterBuilder
67-
* @param Processor|null $priceIndexProcessor
75+
* @param DeferredCacheCleaner|null $cacheCleaner
76+
* @param CacheContext|null $cacheContext
6877
*/
6978
public function __construct(
7079
Configurable $configurable,
7180
ActionInterface $productIndexer,
7281
ProductAttributeRepositoryInterface $productAttributeRepository = null,
7382
?SearchCriteriaBuilder $searchCriteriaBuilder = null,
7483
?FilterBuilder $filterBuilder = null,
75-
?Processor $priceIndexProcessor = null
84+
?DeferredCacheCleaner $cacheCleaner = null,
85+
?CacheContext $cacheContext = null
7686
) {
7787
$this->configurable = $configurable;
7888
$this->productIndexer = $productIndexer;
@@ -82,8 +92,8 @@ public function __construct(
8292
->get(SearchCriteriaBuilder::class);
8393
$this->filterBuilder = $filterBuilder ?: ObjectManager::getInstance()
8494
->get(FilterBuilder::class);
85-
$this->priceIndexProcessor = $priceIndexProcessor ?: ObjectManager::getInstance()
86-
->get(Processor::class);
95+
$this->cacheCleaner = $cacheCleaner ?? ObjectManager::getInstance()->get(DeferredCacheCleaner::class);
96+
$this->cacheContext = $cacheContext ?? ObjectManager::getInstance()->get(CacheContext::class);
8797
}
8898

8999
/**
@@ -123,8 +133,9 @@ public function afterSave(
123133
): ProductResource {
124134
$configurableProductIds = $this->configurable->getParentIdsByChild($object->getId());
125135
if (count($configurableProductIds) > 0) {
126-
$priceIndexer = $this->priceIndexProcessor->getIndexer();
127-
$priceIndexer->reindexList($configurableProductIds);
136+
$this->cacheCleaner->start();
137+
$this->cacheContext->registerEntities(ProductModel::CACHE_TAG, $configurableProductIds);
138+
$this->cacheCleaner->flush();
128139
}
129140

130141
return $result;

0 commit comments

Comments
 (0)