diff --git a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Type/Configurable.php b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Type/Configurable.php index feffd22a0fb3d..c87611e24092c 100644 --- a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Type/Configurable.php @@ -17,7 +17,6 @@ use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionProvider; use Magento\Framework\App\ScopeResolverInterface; use Magento\Framework\App\ObjectManager; -use Magento\Framework\DB\Adapter\AdapterInterface; /** * Configurable product resource model. @@ -160,9 +159,11 @@ public function saveProducts($mainProduct, array $productIds) */ public function getChildrenIds($parentId, $required = true) { - $select = $this->getConnection()->select()->from( + $connection = $this->getConnection(); + + $select = $connection->select()->from( ['l' => $this->getMainTable()], - ['product_id', 'parent_id'] + ['product_id', 'p.entity_id as parent_id'] )->join( ['p' => $this->getTable('catalog_product_entity')], 'p.' . $this->optionProvider->getProductEntityLinkField() . ' = l.parent_id', @@ -176,13 +177,12 @@ public function getChildrenIds($parentId, $required = true) $parentId ); - $childrenIds = [ - 0 => array_column( - $this->getConnection()->fetchAll($select), - 'product_id', - 'product_id' - ) - ]; + $childrenIds = [0 => []]; + foreach ($connection->fetchAll($select) as $row) { + $childrenIds[$row['parent_id']][] = $row['product_id']; + // Alternative format for backward compatibility + $childrenIds[0][$row['product_id']] = $row['product_id']; + } return $childrenIds; } diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php index 0d2043434d359..913168b87ff7c 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php @@ -555,7 +555,7 @@ public function testSaveProductRelationsOneChild() self::assertNotEmpty($oldChildrenIds); self::assertNotEmpty($oneChildId); - $product = $this->productRepository->getById($this->product->getId()); + $product = $this->productRepository->getById(1); $extensionAttributes = $product->getExtensionAttributes(); $extensionAttributes->setConfigurableProductLinks([$oneChildId]); @@ -563,13 +563,17 @@ public function testSaveProductRelationsOneChild() $this->productRepository->save($product); - self::assertEquals( - [ - [ - $oneChildId => $oneChildId - ] - ], - $this->model->getChildrenIds($this->product->getId()) + // Check alternative format for backward compatibility + $expectedArray[0] = [ + $oneChildId => $oneChildId + ]; + //Check grouped array, ex + //array(group => array(ids)) + $expectedArray[$product->getId()][] = $oneChildId; + + self::assertSame( + $expectedArray, + $this->model->getChildrenIds($product->getId()) ); }