Context: How to get the parents (configurable) products for a child (simple) one?
Implementation
/**
* Retrieve parent ids array by required child
*
* @param int|array $childId
* @return string[]
*/
public function getParentIdsByChild($childId)
{
$parentIds = [];
$select = $this->getConnection()
->select()
->from(['l' => $this->getMainTable()], [])
->join(
['e' => $this->getTable('catalog_product_entity')],
'e.' . $this->getProductEntityLinkField() . ' = l.parent_id',
['e.entity_id']
)->where('l.product_id IN(?)', $childId);
foreach ($this->getConnection()->fetchAll($select) as $row) {
$parentIds[] = $row['entity_id'];
}
return $parentIds;
}