diff --git a/app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php b/app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php index 5704bc4b2cbfd..d97e618dfb92d 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php +++ b/app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php @@ -431,6 +431,10 @@ protected function createAnchorSelect(\Magento\Store\Model\Store $store) ['ccp' => $this->getTable('catalog_category_product')], 'ccp.category_id = cc2.child_id', [] + )->joinLeft( + ['ccp2' => $this->getTable('catalog_category_product')], + 'ccp2.category_id = cc2.parent_id AND ccp.product_id = ccp2.product_id', + [] )->joinInner( ['cpe' => $this->getTable('catalog_product_entity')], 'ccp.product_id = cpe.entity_id', @@ -493,7 +497,7 @@ protected function createAnchorSelect(\Magento\Store\Model\Store $store) [ 'category_id' => 'cc.entity_id', 'product_id' => 'ccp.product_id', - 'position' => new \Zend_Db_Expr('ccp.position + 10000'), + 'position' => new \Zend_Db_Expr($this->connection->getIfNullSql('ccp2.position', 'ccp.position + 10000')), 'is_parent' => new \Zend_Db_Expr('0'), 'store_id' => new \Zend_Db_Expr($store->getId()), 'visibility' => new \Zend_Db_Expr($this->connection->getIfNullSql('cpvs.value', 'cpvd.value')),