Skip to content

Commit 5004a91

Browse files
committed
ACP2E-1524: Page Cache is not cleared for the parent product on the child product save
1 parent b8d0a54 commit 5004a91

File tree

1 file changed

+15
-22
lines changed
  • app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel

1 file changed

+15
-22
lines changed

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

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@
1010

1111
use Magento\Catalog\Api\Data\ProductAttributeInterface;
1212
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
13-
use Magento\Catalog\Model\Indexer\Product\Category;
13+
use Magento\Catalog\Model\Indexer\Product\Category\Action\Rows;
14+
use Magento\Catalog\Model\Indexer\Product\Price\Processor;
1415
use Magento\Catalog\Model\Product as ProductModel;
1516
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
16-
use Magento\CatalogSearch\Model\Indexer\Fulltext as FulltextIndexer;
1717
use Magento\ConfigurableProduct\Api\Data\OptionInterface;
1818
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1919
use Magento\Framework\Api\FilterBuilder;
2020
use Magento\Framework\Api\SearchCriteriaBuilder;
2121
use Magento\Framework\App\ObjectManager;
2222
use Magento\Framework\DataObject;
2323
use Magento\Framework\Indexer\ActionInterface;
24-
use Magento\Framework\Indexer\CacheContext;
2524
use Magento\Framework\Indexer\IndexerRegistry;
2625

2726
/**
@@ -55,14 +54,14 @@ class Product
5554
private $filterBuilder;
5655

5756
/**
58-
* @var CacheContext
57+
* @var IndexerRegistry
5958
*/
60-
private $cacheContext;
59+
private $indexerRegistry;
6160

6261
/**
63-
* @var IndexerRegistry
62+
* @var Rows
6463
*/
65-
private $indexerRegistry;
64+
private $rowsAction;
6665

6766
/**
6867
* Initialize Product dependencies.
@@ -72,17 +71,17 @@ class Product
7271
* @param ProductAttributeRepositoryInterface|null $productAttributeRepository
7372
* @param SearchCriteriaBuilder|null $searchCriteriaBuilder
7473
* @param FilterBuilder|null $filterBuilder
75-
* @param CacheContext|null $cacheContext
7674
* @param IndexerRegistry|null $indexerRegistry
75+
* @param Rows|null $rowsAction
7776
*/
7877
public function __construct(
7978
Configurable $configurable,
8079
ActionInterface $productIndexer,
8180
ProductAttributeRepositoryInterface $productAttributeRepository = null,
8281
?SearchCriteriaBuilder $searchCriteriaBuilder = null,
8382
?FilterBuilder $filterBuilder = null,
84-
?CacheContext $cacheContext = null,
85-
?IndexerRegistry $indexerRegistry = null
83+
?IndexerRegistry $indexerRegistry = null,
84+
?Rows $rowsAction = null
8685
) {
8786
$this->configurable = $configurable;
8887
$this->productIndexer = $productIndexer;
@@ -92,9 +91,10 @@ public function __construct(
9291
->get(SearchCriteriaBuilder::class);
9392
$this->filterBuilder = $filterBuilder ?: ObjectManager::getInstance()
9493
->get(FilterBuilder::class);
95-
$this->cacheContext = $cacheContext ?: ObjectManager::getInstance()->get(CacheContext::class);
9694
$this->indexerRegistry = $indexerRegistry ?: ObjectManager::getInstance()
9795
->get(IndexerRegistry::class);
96+
$this->rowsAction = $rowsAction ?: ObjectManager::getInstance()
97+
->get(Rows::class);
9898
}
9999

100100
/**
@@ -133,17 +133,10 @@ public function afterSave(
133133
DataObject $object
134134
): ProductResource {
135135
$productId = $object->getId();
136-
$parentProductIds = $this->configurable->getParentIdsByChild($productId);
137-
if (count($parentProductIds) > 0) {
138-
$productCategoryIndexer = $this->indexerRegistry->get(Category::INDEXER_ID);
139-
$productCategoryIndexer->reindexRow($productId);
140-
141-
$this->cacheContext->registerEntities(
142-
ProductModel::CACHE_TAG,
143-
array_unique(array_merge([$productId], $parentProductIds))
144-
);
145-
$indexer = $this->indexerRegistry->get(FulltextIndexer::INDEXER_ID);
146-
$indexer->reindexRow($productId);
136+
$priceIndexer = $this->indexerRegistry->get(Processor::INDEXER_ID);
137+
if ($priceIndexer->isScheduled()
138+
&& count($this->configurable->getParentIdsByChild($productId)) > 0) {
139+
$this->rowsAction->execute([$productId]);
147140
}
148141

149142
return $result;

0 commit comments

Comments
 (0)