@@ -86,11 +86,6 @@ class Grouped implements DimensionalIndexerInterface
86
86
*/
87
87
private $ fullReindexAction ;
88
88
89
- /**
90
- * @var ManagerInterface
91
- */
92
- private $ eventManager ;
93
-
94
89
/**
95
90
* @param BaseFinalPrice $baseFinalPrice
96
91
* @param IndexTableStructureFactory $indexTableStructureFactory
@@ -100,7 +95,6 @@ class Grouped implements DimensionalIndexerInterface
100
95
* @param ResourceConnection $resource
101
96
* @param string $connectionName
102
97
* @param bool $fullReindexAction
103
- * @param ManagerInterface $eventManager
104
98
* @param array $priceModifiers
105
99
*/
106
100
public function __construct (
@@ -112,7 +106,6 @@ public function __construct(
112
106
ResourceConnection $ resource ,
113
107
$ connectionName = 'indexer ' ,
114
108
$ fullReindexAction = false ,
115
- ManagerInterface $ eventManager ,
116
109
array $ priceModifiers = []
117
110
) {
118
111
$ this ->baseFinalPrice = $ baseFinalPrice ;
@@ -124,7 +117,7 @@ public function __construct(
124
117
$ this ->resource = $ resource ;
125
118
$ this ->eavConfig = $ eavConfig ;
126
119
$ this ->fullReindexAction = $ fullReindexAction ;
127
- $ this ->eventManager = $ eventManager ;
120
+ $ this ->connection = $ this -> resource -> getConnection ( $ this -> connectionName ) ;
128
121
}
129
122
130
123
/**
@@ -148,6 +141,7 @@ private function getMainTable($dimensions)
148
141
*/
149
142
public function executeByDimension (array $ dimensions , \Traversable $ entityIds = null )
150
143
{
144
+ /** @var IndexTableStructure $temporaryPriceTable */
151
145
$ temporaryPriceTable = $ this ->indexTableStructureFactory ->create ([
152
146
'tableName ' => $ this ->tableMaintainer ->getMainTmpTable ($ dimensions ),
153
147
'entityField ' => 'entity_id ' ,
@@ -160,22 +154,34 @@ public function executeByDimension(array $dimensions, \Traversable $entityIds =
160
154
'maxPriceField ' => 'max_price ' ,
161
155
'tierPriceField ' => 'tier_price ' ,
162
156
]);
163
- if (!$ this ->hasEntity () && empty ($ entityIds )) {
164
- return $ this ;
165
- }
157
+ $ this ->fillFinalPrice ($ dimensions , $ entityIds , $ temporaryPriceTable );
158
+ $ this ->applyPriceModifiers ($ temporaryPriceTable );
166
159
167
160
// if (!$this->tableStrategy->getUseIdxTable()) {
168
161
// $additionalIdxTable = $this->cteateTempTable($temporaryPriceTable);
169
162
// $this->fillTemporaryTable($entityIds, $additionalIdxTable);
170
163
// $this->updateIdxTable($additionalIdxTable, $temporaryPriceTable->getTableName());
171
164
// $this->connection->dropTemporaryTable($additionalIdxTable);
172
165
// } else {
173
- $ query = $ this ->_prepareGroupedProductPriceDataSelect ($ dimensions , $ entityIds )
166
+ $ query = $ this ->_prepareGroupedProductPriceDataSelect ($ dimensions , iterator_to_array ( $ entityIds) )
174
167
->insertFromSelect ($ temporaryPriceTable ->getTableName ());
175
168
$ this ->connection ->query ($ query );
176
169
// }
177
170
}
178
171
172
+ /**
173
+ * Apply price modifiers to temporary price index table
174
+ *
175
+ * @param IndexTableStructure $temporaryPriceTable
176
+ * @return void
177
+ */
178
+ private function applyPriceModifiers (IndexTableStructure $ temporaryPriceTable )
179
+ {
180
+ foreach ($ this ->priceModifiers as $ priceModifier ) {
181
+ $ priceModifier ->modifyPrice ($ temporaryPriceTable );
182
+ }
183
+ }
184
+
179
185
/**
180
186
* Prepare data index select for Grouped products prices
181
187
* @param $dimensions
@@ -184,52 +190,50 @@ public function executeByDimension(array $dimensions, \Traversable $entityIds =
184
190
*/
185
191
protected function _prepareGroupedProductPriceDataSelect ($ dimensions , $ entityIds = null )
186
192
{
187
- $ table = $ this ->getMainTable ($ dimensions );
188
- $ linkField = $ this ->metadataPool ->getMetadata (ProductInterface::class)->getLinkField ();
193
+ $ select = $ this ->connection ->select ();
189
194
190
- $ select = $ this -> connection -> select () ->from (
195
+ $ select ->from (
191
196
['e ' => $ this ->getTable ('catalog_product_entity ' )],
192
197
'entity_id '
193
- )->joinLeft (
198
+ );
199
+
200
+ $ linkField = $ this ->metadataPool ->getMetadata (ProductInterface::class)->getLinkField ();
201
+ $ select ->joinLeft (
194
202
['l ' => $ this ->getTable ('catalog_product_link ' )],
195
- 'e. ' . $ linkField . ' = l.product_id AND l.link_type_id= ' .
196
- Link::LINK_TYPE_GROUPED ,
203
+ 'e. ' . $ linkField . ' = l.product_id AND l.link_type_id= ' . Link::LINK_TYPE_GROUPED ,
197
204
[]
198
- )->join (
199
- ['cg ' => $ this ->getTable ('customer_group ' )],
200
- '' ,
201
- ['customer_group_id ' ]
202
205
);
203
- $ this ->_addWebsiteJoinToSelect ($ select , true );
204
- $ this ->_addProductWebsiteJoinToSelect ($ select , 'cw.website_id ' , 'e.entity_id ' );
205
- $ minCheckSql = $ this ->connection ->getCheckSql ('le.required_options = 0 ' , 'i.min_price ' , 0 );
206
- $ maxCheckSql = $ this ->connection ->getCheckSql ('le.required_options = 0 ' , 'i.max_price ' , 0 );
207
- $ select ->columns (
208
- 'website_id ' ,
209
- 'cw '
210
- )->joinLeft (
206
+ //aditional infromation about inner products
207
+ $ select ->joinLeft (
211
208
['le ' => $ this ->getTable ('catalog_product_entity ' )],
212
209
'le.entity_id = l.linked_product_id ' ,
213
210
[]
214
- )->joinLeft (
215
- ['i ' => $ table ],
216
- 'i.entity_id = l.linked_product_id AND i.website_id = cw.website_id ' .
217
- ' AND i.customer_group_id = cg.customer_group_id ' ,
211
+ );
212
+ $ select ->columns (
213
+ [
214
+ 'i.customer_group_id ' ,
215
+ 'i.website_id ' ,
216
+ ]
217
+ );
218
+ $ taxClassId = $ this ->connection ->getCheckSql ('MIN(i.tax_class_id) IS NULL ' , '0 ' , 'MIN(i.tax_class_id) ' );
219
+ $ minCheckSql = $ this ->connection ->getCheckSql ('le.required_options = 0 ' , 'i.min_price ' , 0 );
220
+ $ maxCheckSql = $ this ->connection ->getCheckSql ('le.required_options = 0 ' , 'i.max_price ' , 0 );
221
+ $ select ->joinLeft (
222
+ ['i ' => $ this ->getMainTable ($ dimensions )],
223
+ 'i.entity_id = l.linked_product_id ' ,
218
224
[
219
- 'tax_class_id ' => $ this ->connection ->getCheckSql (
220
- 'MIN(i.tax_class_id) IS NULL ' ,
221
- '0 ' ,
222
- 'MIN(i.tax_class_id) '
223
- ),
225
+ 'tax_class_id ' => $ taxClassId ,
224
226
'price ' => new \Zend_Db_Expr ('NULL ' ),
225
227
'final_price ' => new \Zend_Db_Expr ('NULL ' ),
226
228
'min_price ' => new \Zend_Db_Expr ('MIN( ' . $ minCheckSql . ') ' ),
227
229
'max_price ' => new \Zend_Db_Expr ('MAX( ' . $ maxCheckSql . ') ' ),
228
230
'tier_price ' => new \Zend_Db_Expr ('NULL ' ),
229
231
]
230
- )->group (
231
- ['e.entity_id ' , 'cg.customer_group_id ' , 'cw.website_id ' ]
232
- )->where (
232
+ );
233
+ $ select ->group (
234
+ ['e.entity_id ' , 'i.customer_group_id ' , 'i.website_id ' ]
235
+ );
236
+ $ select ->where (
233
237
'e.type_id=? ' ,
234
238
GroupedType::TYPE_CODE
235
239
);
@@ -247,18 +251,6 @@ protected function _prepareGroupedProductPriceDataSelect($dimensions, $entityIds
247
251
}
248
252
}
249
253
250
- /**
251
- * Add additional external limitation
252
- */
253
- $ this ->eventManager ->dispatch (
254
- 'catalog_product_prepare_index_select ' ,
255
- [
256
- 'select ' => $ select ,
257
- 'entity_field ' => new \Zend_Db_Expr ('e.entity_id ' ),
258
- 'website_field ' => new \Zend_Db_Expr ('cw.website_id ' ),
259
- 'store_field ' => new \Zend_Db_Expr ('cs.store_id ' )
260
- ]
261
- );
262
254
return $ select ;
263
255
}
264
256
@@ -298,30 +290,25 @@ protected function _addWebsiteJoinToSelect($select, $store = true, $joinConditio
298
290
return $ this ;
299
291
}
300
292
301
- /**
302
- * Add join for catalog/product_website table
303
- * Joined table has alias pw
304
- *
305
- * @param \Magento\Framework\DB\Select $select the select object
306
- * @param string|\Zend_Db_Expr $website the limitation of website_id
307
- * @param string|\Zend_Db_Expr $product the limitation of product_id
308
- * @return $this
309
- */
310
- protected function _addProductWebsiteJoinToSelect ($ select , $ website , $ product )
293
+ private function getTable ($ tableName )
311
294
{
312
- $ select ->join (
313
- ['pw ' => $ this ->getTable ('catalog_product_website ' )],
314
- "pw.product_id = {$ product } AND pw.website_id = {$ website }" ,
315
- []
316
- );
317
-
318
- return $ this ;
295
+ return $ this ->resource ->getTableName ($ tableName , $ this ->connectionName );
319
296
}
320
297
321
-
322
- private function getTable ($ tableName )
298
+ /**
299
+ * @param array $dimensions
300
+ * @param \Traversable $entityIds
301
+ * @param $temporaryPriceTable
302
+ */
303
+ private function fillFinalPrice (array $ dimensions , \Traversable $ entityIds , $ temporaryPriceTable ): void
323
304
{
324
- return $ this ->resource ->getTableName ($ tableName , $ this ->connectionName );
305
+ $ select = $ this ->baseFinalPrice ->getQuery (
306
+ $ dimensions ,
307
+ GroupedType::TYPE_CODE ,
308
+ iterator_to_array ($ entityIds )
309
+ );
310
+ $ query = $ select ->insertFromSelect ($ temporaryPriceTable ->getTableName (), [], false );
311
+ $ this ->tableMaintainer ->getConnection ()->query ($ query );
325
312
}
326
313
327
314
/**
0 commit comments