Skip to content

Commit 7b990ec

Browse files
committed
MAGETWO-59400: Invalid join condition in Product Flat Indexer
- Fix sql queries.
1 parent 9f8bfc8 commit 7b990ec

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

app/code/Magento/Catalog/Model/Indexer/Product/Flat/AbstractAction.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ protected function _reindex($storeId, array $changedIds = [])
169169
}
170170

171171
/**
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
174173
*
175174
* @return array
176175
*/
@@ -213,17 +212,19 @@ protected function _updateRelationProducts($storeId, $productIds = null)
213212
) {
214213
$columns = $this->_productIndexerHelper->getFlatColumns();
215214
$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+
);
219220
/** @var $select \Magento\Framework\DB\Select */
220221
$select = $this->_connection->select()->from(
221222
['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')]
223224
)->join(
224225
['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+
[]
227228
)->join(
228229
['e' => $this->_productIndexerHelper->getFlatTableName($storeId)],
229230
"e.entity_id = t.{$relation->getChildFieldName()}",
@@ -232,10 +233,10 @@ protected function _updateRelationProducts($storeId, $productIds = null)
232233
if ($relation->getWhere() !== null) {
233234
$select->where($relation->getWhere());
234235
}
235-
if ($productIds !== null) {
236+
if (!empty($productIds)) {
236237
$cond = [
237238
$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),
239240
];
240241

241242
$select->where(implode(' OR ', $cond));
@@ -273,15 +274,11 @@ protected function _cleanRelationProducts($storeId)
273274
$select = $this->_connection->select()->distinct(
274275
true
275276
)->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()
282279
);
283280
$joinLeftCond = [
284-
"e.entity_id = entity_table.entity_id",
281+
"e.{$metadata->getLinkField()} = t.{$relation->getParentFieldName()}",
285282
"e.child_id = t.{$relation->getChildFieldName()}",
286283
];
287284
if ($relation->getWhere() !== null) {
@@ -302,7 +299,7 @@ protected function _cleanRelationProducts($storeId)
302299
'e.is_child = ?',
303300
1
304301
)->where(
305-
'e.entity_id IN(?)',
302+
"e.{$metadata->getLinkField()} IN(?)",
306303
$entitySelect
307304
)->where(
308305
"t.{$relation->getChildFieldName()} IS NULL"
@@ -335,6 +332,8 @@ protected function _isFlatTableExists($storeId)
335332
}
336333

337334
/**
335+
* Get Metadata Pool
336+
*
338337
* @return \Magento\Framework\EntityManager\MetadataPool
339338
*/
340339
private function getMetadataPool()

0 commit comments

Comments
 (0)