コード例 #1
0
 /**
  * @param ShopContextInterface $context
  * @return \Doctrine\DBAL\Query\QueryBuilder
  */
 private function getQuery(ShopContextInterface $context)
 {
     $query = $this->connection->createQueryBuilder();
     $query->addSelect($this->fieldHelper->getPropertyGroupFields())->addSelect($this->fieldHelper->getPropertyOptionFields())->addSelect($this->fieldHelper->getMediaFields());
     $query->from('s_filter_options', 'propertyGroup')->innerJoin('propertyGroup', 's_filter_values', 'propertyOption', 'propertyOption.optionID = propertyGroup.id')->leftJoin('propertyOption', 's_media', 'media', 'propertyOption.media_id = media.id')->leftJoin('media', 's_media_attributes', 'mediaAttribute', 'mediaAttribute.mediaID = media.id')->leftJoin('media', 's_media_album_settings', 'mediaSettings', 'mediaSettings.albumID = media.albumID');
     $this->fieldHelper->addPropertyGroupTranslation($query, $context);
     $this->fieldHelper->addPropertyOptionTranslation($query, $context);
     $query->where('propertyGroup.id = :id');
     return $query;
 }
コード例 #2
0
 /**
  * @param ListProduct[] $products
  * @param ShopContextInterface $context
  * @return \array[]
  */
 private function getProperties($products, ShopContextInterface $context)
 {
     $ids = array_map(function (ListProduct $product) {
         return $product->getId();
     }, $products);
     $query = $this->connection->createQueryBuilder();
     $query->addSelect('filterArticles.articleID as productId')->addSelect($this->fieldHelper->getPropertyOptionFields())->addSelect($this->fieldHelper->getMediaFields())->from('s_filter_articles', 'filterArticles')->innerJoin('filterArticles', 's_filter_values', 'propertyOption', 'propertyOption.id = filterArticles.valueID')->leftJoin('propertyOption', 's_media', 'media', 'propertyOption.media_id = media.id')->leftJoin('media', 's_media_attributes', 'mediaAttribute', 'mediaAttribute.mediaID = media.id')->leftJoin('media', 's_media_album_settings', 'mediaSettings', 'mediaSettings.albumID = media.albumID')->where('filterArticles.articleID IN (:ids)')->addOrderBy('filterArticles.articleID')->addOrderBy('propertyOption.value')->addOrderBy('propertyOption.id')->setParameter(':ids', $ids, Connection::PARAM_INT_ARRAY);
     $this->fieldHelper->addPropertyOptionTranslation($query, $context);
     /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */
     $statement = $query->execute();
     $data = $statement->fetchAll(\PDO::FETCH_GROUP);
     $properties = [];
     $hydrator = $this->propertyHydrator;
     foreach ($data as $productId => $values) {
         $options = array_map(function ($row) use($hydrator) {
             return $hydrator->hydrateOption($row);
         }, $values);
         $properties[$productId] = $options;
     }
     return $properties;
 }