File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed
app/code/Magento/Catalog/Model/ResourceModel/Product Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change 1313
1414/**
1515 * Catalog Product Relations Resource model
16- *
1716 */
1817class 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}
You can’t perform that action at this time.
0 commit comments