Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\AttributeData::loadChildrens PHP Method

loadChildrens() public method

Warning the result use children ids as a key and list of parents as value
public loadChildrens ( array $productIds ) : array
$productIds array List of parent product ids.
return array
    public function loadChildrens($productIds)
    {
        $children = [];
        foreach ($this->catalogProductType->getCompositeTypes() as $productTypeId) {
            $typeInstance = $this->getProductTypeInstance($productTypeId);
            $relation = $typeInstance->getRelationInfo();
            if ($relation->getTable() && $relation->getParentFieldName() && $relation->getChildFieldName()) {
                $relationTable = $this->getTable($relation->getTable());
                $parentFieldName = $relation->getParentFieldName();
                $childFieldName = $relation->getChildFieldName();
                $select = $this->getConnection()->select()->from(['main' => $relationTable], [$parentFieldName, $childFieldName])->where("main.{$parentFieldName} in (?)", $productIds);
                if ($relation->getWhere() !== null) {
                    $select->where($relation->getWhere());
                }
                $configurationTable = $this->getTable("catalog_product_super_attribute");
                $configurableAttrExpr = "GROUP_CONCAT(DISTINCT super_table.attribute_id SEPARATOR ',')";
                $select->joinLeft(["super_table" => $configurationTable], "super_table.product_id = main.{$parentFieldName}", ["configurable_attributes" => new \Zend_Db_Expr($configurableAttrExpr)]);
                $select->group("main.{$childFieldName}");
                $data = $this->getConnection()->fetchAll($select);
                foreach ($data as $relationRow) {
                    $parentId = (int) $relationRow[$parentFieldName];
                    $childId = (int) $relationRow[$childFieldName];
                    $configurableAttributes = array_filter(explode(',', $relationRow["configurable_attributes"]));
                    $children[$childId][] = ["parent_id" => $parentId, "configurable_attributes" => $configurableAttributes];
                }
            }
        }
        return $children;
    }