$query =
$this->connection->
createQueryBuilder();
$query->
addSelect($this->fieldHelper->
getManufacturerFields());
$query->
addSelect('media.id as __manufacturer_img_id'
);
$query->
from('s_articles_supplier', 'manufacturer'
) ->
leftJoin('manufacturer', 's_articles_supplier_attributes', 'manufacturerAttribute', 'manufacturerAttribute.supplierID = manufacturer.id'
) ->
leftJoin('manufacturer', 's_media', 'media', 'media.path = manufacturer.img'
) ->
where('manufacturer.id IN (:ids)'
) ->
setParameter(':ids',
$ids, Connection::PARAM_INT_ARRAY
);
$this->fieldHelper->
addManufacturerTranslation($query,
$context);
$data =
$query->
execute()->
fetchAll(PDO::FETCH_ASSOC
);
$medias =
$this->mediaService->
getList(array_column($data, '__manufacturer_img_id'
),
$context);
$manufacturers =
[];
foreach ($data as $row) { $id =
$row['__manufacturer_id'
];
$manufacturers[$id] =
$this->manufacturerHydrator->
hydrate($row);
if (!
empty($row['__manufacturer_img'
]) && !
empty($medias[$row['__manufacturer_img_id'
]])) { $manufacturers[$id]->
setCoverMedia($medias[$row['__manufacturer_img_id'
]]);
}