/**
  * @inheritdoc
  */
 public function createBaseProducts($numbers)
 {
     $query = $this->connection->createQueryBuilder();
     $query->select(['variant.id as variantId', 'variant.ordernumber as number', 'variant.articleID as productId']);
     $query->from('s_articles_details', 'variant')->where('variant.ordernumber IN(:numbers)')->setParameter(':numbers', $numbers, Connection::PARAM_STR_ARRAY);
     /**@var $statement \PDOStatement*/
     $statement = $query->execute();
     $data = $statement->fetchAll(\PDO::FETCH_ASSOC);
     $products = [];
     foreach ($data as $row) {
         $product = new BaseProduct((int) $row['productId'], (int) $row['variantId'], $row['number']);
         $products[$product->getNumber()] = $product;
     }
     return $products;
 }
 /**
  * @inheritdoc
  */
 public function getProductCombinations(Struct\BaseProduct $product)
 {
     $query = $this->connection->createQueryBuilder();
     $query->select(['relations.option_id', "GROUP_CONCAT(DISTINCT assignedRelations.option_id, '' SEPARATOR '|') as combinations"]);
     $query->from('s_article_configurator_option_relations', 'relations');
     $query->innerJoin('relations', 's_articles_details', 'variant', 'variant.id = relations.article_id
          AND variant.articleID = :articleId
          AND variant.active = 1');
     $query->innerJoin('variant', 's_articles', 'product', 'product.id = variant.articleID AND
         (product.laststock * variant.instock) >= (product.laststock * variant.minpurchase)');
     $query->leftJoin('relations', 's_article_configurator_option_relations', 'assignedRelations', 'assignedRelations.article_id = relations.article_id
          AND assignedRelations.option_id != relations.option_id');
     $query->groupBy('relations.option_id');
     $query->setParameter(':articleId', $product->getId());
     /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */
     $statement = $query->execute();
     $data = $statement->fetchAll(\PDO::FETCH_KEY_PAIR);
     foreach ($data as &$row) {
         $row = explode('|', $row);
     }
     return $data;
 }
 /**
  * @param QueryBuilder $query
  * @return array
  */
 private function getProducts(QueryBuilder $query)
 {
     /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */
     $statement = $query->execute();
     $data = $statement->fetchAll(\PDO::FETCH_ASSOC);
     $products = [];
     foreach ($data as $row) {
         $product = new BaseProduct((int) $row['__product_id'], (int) $row['__variant_id'], $row['__variant_ordernumber']);
         $product->addAttribute('search', $this->attributeHydrator->hydrate($row));
         $products[$product->getNumber()] = $product;
     }
     return $products;
 }
 /**
  * @param Struct\BaseProduct $product
  * @return int[]
  */
 private function getProductCategories(Struct\BaseProduct $product)
 {
     $query = $this->connection->createQueryBuilder();
     return $query->select('categoryID')->from('s_articles_categories', 'category')->where('articleID = :productId')->setParameter(':productId', $product->getId())->execute()->fetchAll(\PDO::FETCH_COLUMN);
 }
 /**
  * @param $data
  * @return BaseProduct[]
  */
 private function createProducts($data)
 {
     $products = [];
     foreach ($data['hits']['hits'] as $data) {
         $source = $data['_source'];
         $product = new BaseProduct((int) $source['id'], (int) $source['variantId'], $source['number']);
         $product->addAttribute('elastic_search', new Attribute(['score' => $data['_score']]));
         $products[$product->getNumber()] = $product;
     }
     return $products;
 }