示例#1
0
 /**
  * @inheritdoc
  */
 public function getAvailableNumber($number, ShopContextInterface $context, $selection = [])
 {
     $productId = $this->getProductIdByNumber($number);
     if (!$productId) {
         throw new \RuntimeException("No valid product id found");
     }
     if (!$this->isProductAvailableInShop($productId, $context->getShop())) {
         throw new \RuntimeException("Product not available in current shop");
     }
     $selected = null;
     if (!empty($selection)) {
         $selected = $this->getNumberBySelection($productId, $selection);
     }
     if ($selected) {
         return $selected;
     }
     if ($this->isNumberAvailable($number)) {
         return $number;
     }
     $selected = $this->findFallbackById($productId);
     if (!$selected) {
         throw new \RuntimeException("No active product variant found");
     }
     return $selected;
 }
示例#2
0
 private function getConfiguratorProduct($number, ShopContextInterface $context)
 {
     $product = $this->helper->getSimpleProduct($number, array_shift($context->getTaxRules()), $context->getCurrentCustomerGroup());
     $configurator = $this->helper->getConfigurator($context->getCurrentCustomerGroup(), $number, array('farbe' => array('rot', 'blau', 'grün', 'schwarz', 'weiß')));
     $product = array_merge($product, $configurator);
     $product['categories'] = [['id' => $context->getShop()->getCategory()->getId()]];
     foreach ($product['variants'] as $index => &$variant) {
         $offset = ($index + 1) * -10;
         $variant['prices'] = $this->helper->getGraduatedPrices($context->getCurrentCustomerGroup()->getKey(), $offset);
     }
     return $product;
 }
示例#3
0
 /**
  * @param $ids
  * @param $context
  */
 private function getCategoryIds($ids, ShopContextInterface $context)
 {
     $query = $this->connection->createQueryBuilder();
     $query->select(['seoCategories.article_id', 'seoCategories.category_id'])->from('s_articles_categories_seo', 'seoCategories')->andWhere('seoCategories.article_id IN (:productIds)')->andWhere('seoCategories.shop_id = :shopId')->setParameter(':shopId', $context->getShop()->getId())->setParameter(':productIds', $ids, Connection::PARAM_INT_ARRAY);
     return $query->execute()->fetchAll(\PDO::FETCH_KEY_PAIR);
 }
 /**
  * @param QueryBuilder $query
  * @param Struct\ShopContextInterface $context
  */
 private function addTranslations($query, $context)
 {
     if ($context->getShop()->isDefault()) {
         return;
     }
     $query->addSelect('attributeTranslations.objectdata as __attribute_translation')->leftJoin('product', 's_core_translations', 'attributeTranslations', 'attributeTranslations.objectkey = product.id AND attributeTranslations.objecttype = "article" AND attributeTranslations.objectlanguage = :language');
     $query->setParameter(':language', $context->getShop()->getId());
     if (!$context->getShop()->getFallbackId() || $context->getShop()->getFallbackId() === $context->getShop()->getId()) {
         return;
     }
     $query->addSelect('attributeTranslations_fallback.objectdata as __attribute_translation_fallback')->leftJoin('product', 's_core_translations', 'attributeTranslations_fallback', 'attributeTranslations_fallback.objectkey = product.id AND attributeTranslations_fallback.objecttype = "article" AND attributeTranslations_fallback.objectlanguage = :languageFallback');
     $query->setParameter(':languageFallback', $context->getShop()->getFallbackId());
 }
示例#5
0
 /**
  * @param QueryBuilder $query
  * @param ShopContextInterface $context
  */
 public function addProductStreamTranslation(QueryBuilder $query, ShopContextInterface $context)
 {
     if ($context->getShop()->isDefault()) {
         return;
     }
     $this->addProductStreamTranslationWithSuffix($query);
     $query->setParameter(':language', $context->getShop()->getId());
     if ($context->getShop()->getFallbackId() !== $context->getShop()->getId()) {
         $this->addProductStreamTranslationWithSuffix($query, 'Fallback');
         $query->setParameter(':languageFallback', $context->getShop()->getFallbackId());
     }
 }
 /**
  * @param Struct\ListProduct $product
  * @param Struct\ShopContextInterface $context
  * @param $limit
  * @return Search
  */
 protected function getSearch($product, Struct\ShopContextInterface $context, $limit)
 {
     $search = new Search();
     $search->setSize($limit);
     $search->addQuery($this->getSimilarQuery($product));
     $search->addFilter($this->getProductNumberFilter($product));
     $search->addFilter($this->getCategoryFilter($context->getShop()->getCategory()));
     $search->addFilter($this->getCustomerGroupFilter($context->getCurrentCustomerGroup()));
     return $search;
 }
示例#7
0
 /**
  * @param ShopContextInterface $shopContext
  * @param Tax[]                $taxRules
  * @param PriceGroup[]         $priceGroups
  * @return ProductContext
  */
 public static function createFromContexts(ShopContextInterface $shopContext, $taxRules, $priceGroups)
 {
     return new self($shopContext->getBaseUrl(), $shopContext->getShop(), $shopContext->getCurrency(), $shopContext->getCurrentCustomerGroup(), $shopContext->getFallbackCustomerGroup(), $taxRules, $priceGroups);
 }
 /**
  * @inheritdoc
  */
 public function getListByCategory($products, Struct\ShopContextInterface $context)
 {
     if (!$this->config->offsetExists('similarLimit') || $this->config->get('similarLimit') <= 0) {
         return [];
     }
     $ids = [];
     foreach ($products as $product) {
         $ids[] = $product->getId();
     }
     $ids = array_unique($ids);
     $categoryId = 1;
     if ($context->getShop() && $context->getShop()->getCategory()) {
         $categoryId = $context->getShop()->getCategory()->getId();
     }
     $query = $this->connection->createQueryBuilder();
     $query->select(['main.articleID', "GROUP_CONCAT(subVariant.ordernumber SEPARATOR '|') as similar"]);
     $query->from('s_articles_categories', 'main');
     $query->innerJoin('main', 's_articles_categories', 'sub', 'sub.categoryID = main.categoryID AND sub.articleID != main.articleID');
     $query->innerJoin('sub', 's_articles_details', 'subVariant', 'subVariant.articleID = sub.articleID AND subVariant.kind = 1');
     $query->innerJoin('main', 's_categories', 'category', 'category.id = sub.categoryID AND category.id = main.categoryID');
     $query->where('main.articleID IN (:ids)')->andWhere('category.path LIKE :path');
     $query->setParameter(':ids', $ids, Connection::PARAM_INT_ARRAY)->setParameter(':path', '%|' . (int) $categoryId . '|');
     $query->groupBy('main.articleID');
     $statement = $query->execute();
     $data = $statement->fetchAll(\PDO::FETCH_ASSOC);
     $limit = (int) $this->config->get('similarLimit');
     $result = [];
     foreach ($data as $row) {
         $similar = explode('|', $row['similar']);
         $result[$row['articleID']] = array_slice($similar, 0, $limit);
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function hydrate(array $elasticResult, ProductNumberSearchResult $result, Criteria $criteria, ShopContextInterface $context)
 {
     if (!isset($elasticResult['aggregations'])) {
         return;
     }
     if (!isset($elasticResult['aggregations']['agg_properties'])) {
         return;
     }
     $data = $elasticResult['aggregations']['agg_properties']['buckets'];
     $ids = array_column($data, 'key');
     if (empty($ids)) {
         return;
     }
     $groupIds = $this->getGroupIds($ids);
     $search = new Search();
     $search->addFilter(new IdsFilter($groupIds));
     $search->addFilter(new TermFilter('filterable', 1));
     $search->addSort(new FieldSort('name'));
     $index = $this->indexFactory->createShopIndex($context->getShop());
     $data = $this->client->search(['index' => $index->getName(), 'type' => PropertyMapping::TYPE, 'body' => $search->toArray()]);
     $data = $data['hits']['hits'];
     $properties = $this->hydrateProperties($data, $ids);
     $actives = $this->getFilteredValues($criteria);
     $criteriaPart = $this->createCollectionResult($properties, $actives);
     $result->addFacet($criteriaPart);
 }