metadataPool = $metadataPool; parent::__construct( $context, $catalogProductRelation, $connectionName ); } /** * Retrieve Required children ids * Return grouped array, ex array( * group => array(ids) * ) * * @param int $parentId * @param int $typeId * @return array */ public function getChildrenIds($parentId, $typeId) { $connection = $this->getConnection(); $childrenIds = []; $bind = [':product_id' => (int)$parentId, ':link_type_id' => (int)$typeId]; $select = $connection->select()->from( ['l' => $this->getMainTable()], ['linked_product_id'] )->join( ['cpe' => $this->getTable('catalog_product_entity')], sprintf( 'cpe.%s = l.product_id', $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField() ) )->where( 'cpe.entity_id = :product_id' )->where( 'link_type_id = :link_type_id' ); $select->join( ['e' => $this->getTable('catalog_product_entity')], 'e.entity_id = l.linked_product_id AND e.required_options = 0', [] ); $childrenIds[$typeId] = []; $result = $connection->fetchAll($select, $bind); foreach ($result as $row) { $childrenIds[$typeId][$row['linked_product_id']] = $row['linked_product_id']; } return $childrenIds; } }