Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#14061 Fix Configurable Product Type resource model 'getChildrenIds' method return format #27246

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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',
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,21 +555,25 @@ 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]);
$product->setExtensionAttributes($extensionAttributes);

$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())
);
}

Expand Down