10
10
11
11
use Magento \Catalog \Api \Data \ProductAttributeInterface ;
12
12
use Magento \Catalog \Api \ProductAttributeRepositoryInterface ;
13
- use Magento \Catalog \Model \Indexer \Product \Category \Action \Rows ;
14
13
use Magento \Catalog \Model \Indexer \Product \Price \Processor ;
15
14
use Magento \Catalog \Model \Product as ProductModel ;
16
15
use Magento \Catalog \Model \ResourceModel \Product as ProductResource ;
21
20
use Magento \Framework \App \ObjectManager ;
22
21
use Magento \Framework \DataObject ;
23
22
use Magento \Framework \Indexer \ActionInterface ;
24
- use Magento \Framework \Indexer \IndexerRegistry ;
25
23
26
24
/**
27
25
* Plugin product resource model
28
- *
29
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
30
26
*/
31
27
class Product
32
28
{
@@ -56,14 +52,9 @@ class Product
56
52
private $ filterBuilder ;
57
53
58
54
/**
59
- * @var IndexerRegistry
60
- */
61
- private $ indexerRegistry ;
62
-
63
- /**
64
- * @var Rows
55
+ * @var Processor
65
56
*/
66
- private $ rowsAction ;
57
+ private $ priceIndexProcessor ;
67
58
68
59
/**
69
60
* Initialize Product dependencies.
@@ -73,17 +64,15 @@ class Product
73
64
* @param ProductAttributeRepositoryInterface|null $productAttributeRepository
74
65
* @param SearchCriteriaBuilder|null $searchCriteriaBuilder
75
66
* @param FilterBuilder|null $filterBuilder
76
- * @param IndexerRegistry|null $indexerRegistry
77
- * @param Rows|null $rowsAction
67
+ * @param Processor|null $priceIndexProcessor
78
68
*/
79
69
public function __construct (
80
70
Configurable $ configurable ,
81
71
ActionInterface $ productIndexer ,
82
72
ProductAttributeRepositoryInterface $ productAttributeRepository = null ,
83
73
?SearchCriteriaBuilder $ searchCriteriaBuilder = null ,
84
74
?FilterBuilder $ filterBuilder = null ,
85
- ?IndexerRegistry $ indexerRegistry = null ,
86
- ?Rows $ rowsAction = null
75
+ ?Processor $ priceIndexProcessor = null
87
76
) {
88
77
$ this ->configurable = $ configurable ;
89
78
$ this ->productIndexer = $ productIndexer ;
@@ -93,10 +82,8 @@ public function __construct(
93
82
->get (SearchCriteriaBuilder::class);
94
83
$ this ->filterBuilder = $ filterBuilder ?: ObjectManager::getInstance ()
95
84
->get (FilterBuilder::class);
96
- $ this ->indexerRegistry = $ indexerRegistry ?: ObjectManager::getInstance ()
97
- ->get (IndexerRegistry::class);
98
- $ this ->rowsAction = $ rowsAction ?: ObjectManager::getInstance ()
99
- ->get (Rows::class);
85
+ $ this ->priceIndexProcessor = $ priceIndexProcessor ?: ObjectManager::getInstance ()
86
+ ->get (Processor::class);
100
87
}
101
88
102
89
/**
@@ -134,11 +121,10 @@ public function afterSave(
134
121
ProductResource $ result ,
135
122
DataObject $ object
136
123
): ProductResource {
137
- $ productId = $ object ->getId ();
138
- $ priceIndexer = $ this ->indexerRegistry ->get (Processor::INDEXER_ID );
139
- if ($ priceIndexer ->isScheduled ()
140
- && count ($ this ->configurable ->getParentIdsByChild ($ productId )) > 0 ) {
141
- $ this ->rowsAction ->execute ([$ productId ]);
124
+ $ configurableProductIds = $ this ->configurable ->getParentIdsByChild ($ object ->getId ());
125
+ if (count ($ configurableProductIds ) > 0 ) {
126
+ $ priceIndexer = $ this ->priceIndexProcessor ->getIndexer ();
127
+ $ priceIndexer ->reindexList ($ configurableProductIds );
142
128
}
143
129
144
130
return $ result ;
0 commit comments