Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function getConfiguratorMedia(Struct\BaseProduct $product, Struct\ShopContextInterface $context)
 {
     $subQuery = $this->connection->createQueryBuilder();
     $subQuery->select('image.media_id')->from('s_articles_img', 'image')->innerJoin('image', 's_article_img_mappings', 'mapping', 'mapping.image_id = image.id')->innerJoin('mapping', 's_article_img_mapping_rules', 'rules', 'rules.mapping_id = mapping.id')->where('image.articleID = product.id')->andWhere('rules.option_id = optionRelation.option_id')->orderBy('image.position')->setMaxResults(1);
     $query = $this->connection->createQueryBuilder();
     $query->select(['optionRelation.option_id', '(' . $subQuery->getSQL() . ') as media_id']);
     $query->from('s_articles', 'product')->innerJoin('product', 's_article_configurator_set_option_relations', 'optionRelation', 'product.configurator_set_id = optionRelation.set_id');
     $query->where('product.id = :articleId');
     $query->groupBy('optionRelation.option_id');
     $query->setParameter(':articleId', $product->getId());
     /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */
     $statement = $query->execute();
     $data = $statement->fetchAll(\PDO::FETCH_KEY_PAIR);
     $data = array_filter($data);
     $media = $this->mediaGateway->getList($data, $context);
     $result = [];
     foreach ($data as $optionId => $mediaId) {
         if (!isset($media[$mediaId])) {
             continue;
         }
         $result[$optionId] = $media[$mediaId];
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * @param $ids
  * @param Struct\ShopContextInterface $context
  * @return Struct\Media[] Indexed by the media id
  */
 public function getList($ids, Struct\ShopContextInterface $context)
 {
     return $this->mediaGateway->getList($ids, $context);
 }