/** * @inheritdoc */ public function getList($products, Struct\ShopContextInterface $context) { $ids = []; foreach ($products as $product) { $ids[] = $product->getId(); } $ids = array_unique($ids); $query = $this->connection->createQueryBuilder(); $query->select($this->fieldHelper->getDownloadFields()); $query->from('s_articles_downloads', 'download')->leftJoin('download', 's_articles_downloads_attributes', 'downloadAttribute', 'downloadAttribute.downloadID = download.id'); $query->where('download.articleID IN (:ids)')->setParameter(':ids', $ids, Connection::PARAM_INT_ARRAY); /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */ $statement = $query->execute(); $data = $statement->fetchAll(\PDO::FETCH_ASSOC); $downloads = []; foreach ($data as $row) { $key = $row['__download_articleID']; $download = $this->downloadHydrator->hydrate($row); $downloads[$key][] = $download; } $result = []; foreach ($products as $product) { if (isset($downloads[$product->getId()])) { $result[$product->getNumber()] = $downloads[$product->getId()]; } } return $result; }