10
10
11
11
use Magento \Catalog \Api \Data \ProductAttributeInterface ;
12
12
use Magento \Catalog \Api \ProductAttributeRepositoryInterface ;
13
- use Magento \Catalog \Model \Indexer \Product \Price \Processor ;
14
13
use Magento \Catalog \Model \Product as ProductModel ;
15
14
use Magento \Catalog \Model \ResourceModel \Product as ProductResource ;
16
15
use Magento \ConfigurableProduct \Api \Data \OptionInterface ;
20
19
use Magento \Framework \App \ObjectManager ;
21
20
use Magento \Framework \DataObject ;
22
21
use Magento \Framework \Indexer \ActionInterface ;
22
+ use Magento \Framework \Indexer \CacheContext ;
23
+ use Magento \Indexer \Model \Indexer \DeferredCacheCleaner ;
23
24
24
25
/**
25
26
* Plugin product resource model
27
+ *
28
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26
29
*/
27
30
class Product
28
31
{
@@ -52,9 +55,14 @@ class Product
52
55
private $ filterBuilder ;
53
56
54
57
/**
55
- * @var Processor
58
+ * @var DeferredCacheCleaner
59
+ */
60
+ private $ cacheCleaner ;
61
+
62
+ /**
63
+ * @var CacheContext
56
64
*/
57
- private $ priceIndexProcessor ;
65
+ private $ cacheContext ;
58
66
59
67
/**
60
68
* Initialize Product dependencies.
@@ -64,15 +72,17 @@ class Product
64
72
* @param ProductAttributeRepositoryInterface|null $productAttributeRepository
65
73
* @param SearchCriteriaBuilder|null $searchCriteriaBuilder
66
74
* @param FilterBuilder|null $filterBuilder
67
- * @param Processor|null $priceIndexProcessor
75
+ * @param DeferredCacheCleaner|null $cacheCleaner
76
+ * @param CacheContext|null $cacheContext
68
77
*/
69
78
public function __construct (
70
79
Configurable $ configurable ,
71
80
ActionInterface $ productIndexer ,
72
81
ProductAttributeRepositoryInterface $ productAttributeRepository = null ,
73
82
?SearchCriteriaBuilder $ searchCriteriaBuilder = null ,
74
83
?FilterBuilder $ filterBuilder = null ,
75
- ?Processor $ priceIndexProcessor = null
84
+ ?DeferredCacheCleaner $ cacheCleaner = null ,
85
+ ?CacheContext $ cacheContext = null
76
86
) {
77
87
$ this ->configurable = $ configurable ;
78
88
$ this ->productIndexer = $ productIndexer ;
@@ -82,8 +92,8 @@ public function __construct(
82
92
->get (SearchCriteriaBuilder::class);
83
93
$ this ->filterBuilder = $ filterBuilder ?: ObjectManager::getInstance ()
84
94
->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);
87
97
}
88
98
89
99
/**
@@ -123,8 +133,9 @@ public function afterSave(
123
133
): ProductResource {
124
134
$ configurableProductIds = $ this ->configurable ->getParentIdsByChild ($ object ->getId ());
125
135
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 ();
128
139
}
129
140
130
141
return $ result ;
0 commit comments