Skip to content

Commit 7fdf85b

Browse files
committed
ACP2E-4233: Grouped product incorrectly shows as Out of Stock on PDP after import from CSV when child is assigned to custom source/stock (fixed after manual reindex)
1 parent e885088 commit 7fdf85b

File tree

1 file changed

+29
-1
lines changed
  • app/code/Magento/Catalog/Model/ResourceModel/Product

1 file changed

+29
-1
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
/**
1515
* Catalog Product Relations Resource model
16-
*
1716
*/
1817
class Relation extends AbstractDb
1918
{
@@ -163,4 +162,33 @@ public function getRelationsByChildren(array $childrenIds): array
163162

164163
return $parentIdsOfChildIds;
165164
}
165+
166+
/**
167+
* Finds children relations by given parent ids.
168+
*
169+
* @param int[] $parentIds Parent products entity ids.
170+
* @return array<int, int[]> Child products entity ids.
171+
*/
172+
public function getRelationsByParent(array $parentIds): array
173+
{
174+
$connection = $this->getConnection();
175+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
176+
$select = $connection->select()
177+
->from(
178+
['cpe' => $this->getTable('catalog_product_entity')],
179+
['cpe.entity_id']
180+
)->joinInner(
181+
['relation' => $this->getMainTable()],
182+
'relation.parent_id = cpe.' . $linkField,
183+
['relation.child_id']
184+
)->where('cpe.entity_id IN (?)', $parentIds);
185+
$result = $connection->fetchAll($select);
186+
187+
$childIdsOfParentIds = [];
188+
foreach ($result as $row) {
189+
$childIdsOfParentIds[$row['entity_id']][] = $row['child_id'];
190+
}
191+
192+
return $childIdsOfParentIds;
193+
}
166194
}

0 commit comments

Comments
 (0)