Skip to content

Commit ffa34cd

Browse files
committed
MAGETWO-90362: Fix 'table not found' in segmentation for Category Product Indexer
1 parent 17f9341 commit ffa34cd

File tree

1 file changed

+31
-11
lines changed
  • app/code/Magento/Catalog/Model/ResourceModel

1 file changed

+31
-11
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product.php

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -375,22 +375,42 @@ public function getAvailableInCategories($object)
375375
// fetching all parent IDs, including those are higher on the tree
376376
$entityId = (int)$object->getEntityId();
377377
if (!isset($this->availableCategoryIdsCache[$entityId])) {
378-
$this->availableCategoryIdsCache[$entityId] = $this->getConnection()->fetchCol(
379-
$this->getConnection()->select()->distinct()->from(
380-
$this->tableMaintainer->getMainTable($object->getStoreId()),
381-
['category_id']
382-
)->where(
383-
'product_id = ? AND is_parent = 1',
384-
$entityId
385-
)->where(
386-
'visibility != ?',
387-
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE
388-
)
378+
foreach ($this->_storeManager->getStores() as $store) {
379+
$unionTables[] = $this->getAvailableInCategoriesSelect(
380+
$entityId,
381+
$this->tableMaintainer->getMainTable($store->getId())
382+
);
383+
}
384+
$unionSelect = new \Magento\Framework\DB\Sql\UnionExpression(
385+
$unionTables,
386+
\Magento\Framework\DB\Select::SQL_UNION_ALL
389387
);
388+
$this->availableCategoryIdsCache[$entityId] = array_unique($this->getConnection()->fetchCol($unionSelect));
390389
}
391390
return $this->availableCategoryIdsCache[$entityId];
392391
}
393392

393+
/**
394+
* Returns DB select for available categories.
395+
*
396+
* @param int $entityId
397+
* @param string $tableName
398+
* @return \Magento\Framework\DB\Select
399+
*/
400+
private function getAvailableInCategoriesSelect($entityId, $tableName)
401+
{
402+
return $this->getConnection()->select()->distinct()->from(
403+
$tableName,
404+
['category_id']
405+
)->where(
406+
'product_id = ? AND is_parent = 1',
407+
$entityId
408+
)->where(
409+
'visibility != ?',
410+
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE
411+
);
412+
}
413+
394414
/**
395415
* Get default attribute source model
396416
*

0 commit comments

Comments
 (0)