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 ;
13
+ use Magento \Catalog \Model \Indexer \Product \Category \Action \Rows ;
14
+ use Magento \Catalog \Model \Indexer \Product \Price \Processor ;
14
15
use Magento \Catalog \Model \Product as ProductModel ;
15
16
use Magento \Catalog \Model \ResourceModel \Product as ProductResource ;
16
- use Magento \CatalogSearch \Model \Indexer \Fulltext as FulltextIndexer ;
17
17
use Magento \ConfigurableProduct \Api \Data \OptionInterface ;
18
18
use Magento \ConfigurableProduct \Model \Product \Type \Configurable ;
19
19
use Magento \Framework \Api \FilterBuilder ;
20
20
use Magento \Framework \Api \SearchCriteriaBuilder ;
21
21
use Magento \Framework \App \ObjectManager ;
22
22
use Magento \Framework \DataObject ;
23
23
use Magento \Framework \Indexer \ActionInterface ;
24
- use Magento \Framework \Indexer \CacheContext ;
25
24
use Magento \Framework \Indexer \IndexerRegistry ;
26
25
27
26
/**
@@ -55,14 +54,14 @@ class Product
55
54
private $ filterBuilder ;
56
55
57
56
/**
58
- * @var CacheContext
57
+ * @var IndexerRegistry
59
58
*/
60
- private $ cacheContext ;
59
+ private $ indexerRegistry ;
61
60
62
61
/**
63
- * @var IndexerRegistry
62
+ * @var Rows
64
63
*/
65
- private $ indexerRegistry ;
64
+ private $ rowsAction ;
66
65
67
66
/**
68
67
* Initialize Product dependencies.
@@ -72,17 +71,17 @@ class Product
72
71
* @param ProductAttributeRepositoryInterface|null $productAttributeRepository
73
72
* @param SearchCriteriaBuilder|null $searchCriteriaBuilder
74
73
* @param FilterBuilder|null $filterBuilder
75
- * @param CacheContext|null $cacheContext
76
74
* @param IndexerRegistry|null $indexerRegistry
75
+ * @param Rows|null $rowsAction
77
76
*/
78
77
public function __construct (
79
78
Configurable $ configurable ,
80
79
ActionInterface $ productIndexer ,
81
80
ProductAttributeRepositoryInterface $ productAttributeRepository = null ,
82
81
?SearchCriteriaBuilder $ searchCriteriaBuilder = null ,
83
82
?FilterBuilder $ filterBuilder = null ,
84
- ?CacheContext $ cacheContext = null ,
85
- ?IndexerRegistry $ indexerRegistry = null
83
+ ?IndexerRegistry $ indexerRegistry = null ,
84
+ ?Rows $ rowsAction = null
86
85
) {
87
86
$ this ->configurable = $ configurable ;
88
87
$ this ->productIndexer = $ productIndexer ;
@@ -92,9 +91,10 @@ public function __construct(
92
91
->get (SearchCriteriaBuilder::class);
93
92
$ this ->filterBuilder = $ filterBuilder ?: ObjectManager::getInstance ()
94
93
->get (FilterBuilder::class);
95
- $ this ->cacheContext = $ cacheContext ?: ObjectManager::getInstance ()->get (CacheContext::class);
96
94
$ this ->indexerRegistry = $ indexerRegistry ?: ObjectManager::getInstance ()
97
95
->get (IndexerRegistry::class);
96
+ $ this ->rowsAction = $ rowsAction ?: ObjectManager::getInstance ()
97
+ ->get (Rows::class);
98
98
}
99
99
100
100
/**
@@ -133,17 +133,10 @@ public function afterSave(
133
133
DataObject $ object
134
134
): ProductResource {
135
135
$ 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 ]);
147
140
}
148
141
149
142
return $ result ;
0 commit comments