@@ -169,8 +169,7 @@ protected function _reindex($storeId, array $changedIds = [])
169
169
}
170
170
171
171
/**
172
- * Retrieve Product Type Instances
173
- * as key - type code, value - instance model
172
+ * Retrieve Product Type Instances as key - type code, value - instance model
174
173
*
175
174
* @return array
176
175
*/
@@ -213,17 +212,19 @@ protected function _updateRelationProducts($storeId, $productIds = null)
213
212
) {
214
213
$ columns = $ this ->_productIndexerHelper ->getFlatColumns ();
215
214
$ fieldList = array_keys ($ columns );
216
- unset($ columns ['entity_id ' ]);
217
- unset($ columns ['child_id ' ]);
218
- unset($ columns ['is_child ' ]);
215
+ unset(
216
+ $ columns ['entity_id ' ],
217
+ $ columns ['child_id ' ],
218
+ $ columns ['is_child ' ]
219
+ );
219
220
/** @var $select \Magento\Framework\DB\Select */
220
221
$ select = $ this ->_connection ->select ()->from (
221
222
['t ' => $ this ->_productIndexerHelper ->getTable ($ relation ->getTable ())],
222
- [$ relation ->getChildFieldName (), new \Zend_Db_Expr ('1 ' )]
223
+ [' entity_table.entity_id ' , $ relation ->getChildFieldName (), new \Zend_Db_Expr ('1 ' )]
223
224
)->join (
224
225
['entity_table ' => $ this ->_connection ->getTableName ('catalog_product_entity ' )],
225
- ' entity_table. ' . $ metadata ->getLinkField () . ' t. ' . $ relation ->getParentFieldName (),
226
- [$ relation -> getParentFieldName () => ' entity_table.entity_id ' ]
226
+ " entity_table. { $ metadata ->getLinkField ()} = t. { $ relation ->getParentFieldName ()}" ,
227
+ []
227
228
)->join (
228
229
['e ' => $ this ->_productIndexerHelper ->getFlatTableName ($ storeId )],
229
230
"e.entity_id = t. {$ relation ->getChildFieldName ()}" ,
@@ -232,10 +233,10 @@ protected function _updateRelationProducts($storeId, $productIds = null)
232
233
if ($ relation ->getWhere () !== null ) {
233
234
$ select ->where ($ relation ->getWhere ());
234
235
}
235
- if ($ productIds !== null ) {
236
+ if (! empty ( $ productIds) ) {
236
237
$ cond = [
237
238
$ this ->_connection ->quoteInto ("{$ relation ->getChildFieldName ()} IN(?) " , $ productIds ),
238
- $ this ->_connection ->quoteInto (" entity_table.entity_id IN(?) " , $ productIds ),
239
+ $ this ->_connection ->quoteInto (' entity_table.entity_id IN(?) ' , $ productIds ),
239
240
];
240
241
241
242
$ select ->where (implode (' OR ' , $ cond ));
@@ -273,15 +274,11 @@ protected function _cleanRelationProducts($storeId)
273
274
$ select = $ this ->_connection ->select ()->distinct (
274
275
true
275
276
)->from (
276
- ['t ' => $ this ->_productIndexerHelper ->getTable ($ relation ->getTable ())],
277
- []
278
- )->join (
279
- ['entity_table ' => $ this ->_connection ->getTableName ('catalog_product_entity ' )],
280
- 'entity_table. ' . $ metadata ->getLinkField () . 't. ' . $ relation ->getParentFieldName (),
281
- [$ relation ->getParentFieldName () => 'entity_table.entity_id ' ]
277
+ $ this ->_productIndexerHelper ->getTable ($ relation ->getTable ()),
278
+ $ relation ->getParentFieldName ()
282
279
);
283
280
$ joinLeftCond = [
284
- "e.entity_id = entity_table.entity_id " ,
281
+ "e. { $ metadata -> getLinkField ()} = t. { $ relation -> getParentFieldName ()} " ,
285
282
"e.child_id = t. {$ relation ->getChildFieldName ()}" ,
286
283
];
287
284
if ($ relation ->getWhere () !== null ) {
@@ -302,7 +299,7 @@ protected function _cleanRelationProducts($storeId)
302
299
'e.is_child = ? ' ,
303
300
1
304
301
)->where (
305
- ' e.entity_id IN(?)' ,
302
+ " e. { $ metadata -> getLinkField ()} IN(?) " ,
306
303
$ entitySelect
307
304
)->where (
308
305
"t. {$ relation ->getChildFieldName ()} IS NULL "
@@ -335,6 +332,8 @@ protected function _isFlatTableExists($storeId)
335
332
}
336
333
337
334
/**
335
+ * Get Metadata Pool
336
+ *
338
337
* @return \Magento\Framework\EntityManager\MetadataPool
339
338
*/
340
339
private function getMetadataPool ()
0 commit comments