/** * Generates the facet data for the passed query, criteria and context object. * * @param FacetInterface|ProductAttributeFacet $facet * @param Criteria $criteria * @param Struct\ShopContextInterface $context * @return BooleanFacetResult|ValueListFacetResult */ public function generateFacet(FacetInterface $facet, Criteria $criteria, Struct\ShopContextInterface $context) { $queryCriteria = clone $criteria; $queryCriteria->resetConditions(); $queryCriteria->resetSorting(); $query = $this->queryBuilderFactory->createQuery($queryCriteria, $context); $query->resetQueryPart('orderBy'); $query->resetQueryPart('groupBy'); $sqlField = 'productAttribute.' . $facet->getField(); $query->andWhere($sqlField . ' IS NOT NULL')->andWhere($sqlField . " != ''"); switch ($facet->getMode()) { case ProductAttributeFacet::MODE_VALUE_LIST_RESULT: case ProductAttributeFacet::MODE_RADIO_LIST_RESULT: $result = $this->createValueListFacetResult($query, $facet, $criteria, $context); break; case ProductAttributeFacet::MODE_BOOLEAN_RESULT: $result = $this->createBooleanFacetResult($query, $facet, $criteria); break; case ProductAttributeFacet::MODE_RANGE_RESULT: $result = $this->createRangeFacetResult($query, $facet, $criteria); break; default: $result = null; break; } if ($result !== null && $facet->getTemplate()) { $result->setTemplate($facet->getTemplate()); } return $result; }
/** * Creates a product search result for the passed criteria object. * The criteria object contains different core conditions and plugin conditions. * This conditions has to be handled over the different condition handlers. * * The search gateway has to implement an event which plugin can be listened to, * to add their own handler classes. * * @param SearchBundle\Criteria $criteria * @param ShopContextInterface $context * @return SearchBundle\ProductNumberSearchResult */ public function search(SearchBundle\Criteria $criteria, ShopContextInterface $context) { $query = $this->queryBuilderFactory->createProductQuery($criteria, $context); $products = $this->getProducts($query); $total = $this->getTotalCount($query); $facets = $this->createFacets($criteria, $context); $result = new SearchBundle\ProductNumberSearchResult($products, intval($total), $facets); return $result; }
/** * Generates the facet data for the passed query, criteria and context object. * * @param FacetInterface|VoteAverageFacet $facet * @param Criteria $criteria * @param Struct\ShopContextInterface $context * @return \Shopware\Bundle\SearchBundle\FacetResult\RadioFacetResult|null */ public function generateFacet(FacetInterface $facet, Criteria $criteria, Struct\ShopContextInterface $context) { $queryCriteria = clone $criteria; $queryCriteria->resetConditions(); $queryCriteria->resetSorting(); $query = $this->queryBuilderFactory->createQuery($queryCriteria, $context); $query->resetQueryPart('orderBy'); $query->resetQueryPart('groupBy'); if (!$query->hasState(VoteAverageCondition::STATE_INCLUDES_VOTE_TABLE)) { $query->innerJoin('product', 's_articles_vote', 'vote', 'vote.articleID = product.id'); } $query->select('COUNT(vote.id) as hasVotes'); /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */ $statement = $query->execute(); $data = $statement->fetch(\PDO::FETCH_COLUMN); if (!$data) { return null; } $activeAverage = null; if ($criteria->hasCondition($facet->getName())) { /**@var $condition VoteAverageCondition*/ $condition = $criteria->getCondition($facet->getName()); $activeAverage = $condition->getAverage(); } $values = [new ValueListItem(1, '', $activeAverage == 1), new ValueListItem(2, '', $activeAverage == 2), new ValueListItem(3, '', $activeAverage == 3), new ValueListItem(4, '', $activeAverage == 4), new ValueListItem(5, '', $activeAverage == 5)]; return new RadioFacetResult($facet->getName(), $criteria->hasCondition($facet->getName()), $this->snippetNamespace->get($facet->getName(), 'Ranking'), $values, $this->fieldName, [], 'frontend/listing/filter/facet-rating.tpl'); }
/** * @param FacetInterface|Facet\PriceFacet $facet * @param Criteria $criteria * @param ShopContextInterface $context * @return RangeFacetResult */ public function generateFacet(FacetInterface $facet, Criteria $criteria, ShopContextInterface $context) { $queryCriteria = clone $criteria; $queryCriteria->resetConditions(); $queryCriteria->resetSorting(); $query = $this->queryBuilderFactory->createQuery($queryCriteria, $context); $query->resetQueryPart('orderBy'); $query->resetQueryPart('groupBy'); $selection = $this->priceHelper->getSelection($context); $this->priceHelper->joinPrices($query, $context); $query->select('MIN(' . $selection . ') as cheapest_price'); /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */ $statement = $query->execute(); $min = $statement->fetch(\PDO::FETCH_COLUMN); $query->groupBy('product.id')->orderBy('cheapest_price', 'DESC')->setFirstResult(0)->setMaxResults(1); /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */ $statement = $query->execute(); $max = $statement->fetch(\PDO::FETCH_COLUMN); $activeMin = $min; $activeMax = $max; /**@var $condition PriceCondition */ if ($condition = $criteria->getCondition($facet->getName())) { $activeMin = $condition->getMinPrice(); $activeMax = $condition->getMaxPrice(); } return new RangeFacetResult($facet->getName(), $criteria->hasCondition($facet->getName()), $this->snippetNamespace->get($facet->getName(), 'Price'), (double) $min, (double) $max, (double) $activeMin, (double) $activeMax, $this->minFieldName, $this->maxFieldName, [], 'frontend/listing/filter/facet-currency-range.tpl'); }
/** * Generates the facet data for the passed query, criteria and context object. * * @param FacetInterface|Facet\ShippingFreeFacet $facet * @param Criteria $criteria * @param ShopContextInterface $context * @return BooleanFacetResult */ public function generateFacet(FacetInterface $facet, Criteria $criteria, ShopContextInterface $context) { $queryCriteria = clone $criteria; $queryCriteria->resetConditions(); $queryCriteria->resetSorting(); $query = $this->queryBuilderFactory->createQuery($queryCriteria, $context); $query->resetQueryPart('orderBy'); $query->resetQueryPart('groupBy'); $query->select('product.id')->andWhere('variant.shippingfree = 1')->setMaxResults(1); /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */ $statement = $query->execute(); $total = $statement->fetch(\PDO::FETCH_COLUMN); if ($total <= 0) { return null; } return new BooleanFacetResult($facet->getName(), $this->fieldName, $criteria->hasCondition($facet->getName()), $this->snippetNamespace->get($facet->getName(), 'Shipping free')); }
/** * Extends the query criteria query to generate enough data for the servicees * * @param FacetInterface $facet * @param Criteria $criteria * @param Struct\ShopContextInterface $context * @return null|FacetResultInterface|FacetResultInterface[] */ public function generateFacet(FacetInterface $facet, Criteria $criteria, Struct\ShopContextInterface $context) { $activeOptions = array(); $productVariantCondition = $criteria->getCondition('swag-variant-filter-product-variant'); if ($productVariantCondition && $productVariantCondition instanceof ProductVariantCondition) { $activeOptions = $productVariantCondition->getProductVariantIds(ProductVariantCondition::FORMAT_FLAT); } $queryCriteria = clone $criteria; $queryCriteria->resetConditions(); $query = $this->queryBuilderFactory->createQuery($queryCriteria, $context); $query->select('configuratorOptionRelations.option_id')->innerJoin('product', 's_articles_details', 'variantFilterDetails', 'variantFilterDetails.articleID = product.id')->innerJoin('variantFilterDetails', 's_article_configurator_option_relations', 'configuratorOptionRelations', 'configuratorOptionRelations.article_id = variantFilterDetails.id')->groupBy('configuratorOptionRelations.option_id'); $ids = (array) $query->execute()->fetchAll(\PDO::FETCH_COLUMN); $filterConditions = $this->productVariantService->getFilterConditions($ids, $activeOptions); if (!$filterConditions) { return null; } return new ProductVariantFacetResult($filterConditions, $this->snippetNamespace->get('FilterHeadlineVariants', 'Variantfilter')); }
/** * @inheritdoc */ public function generateFacet(FacetInterface $facet, Criteria $criteria, Struct\ShopContextInterface $context) { //resets all conditions of the criteria to execute a facet query without user filters. $queryCriteria = clone $criteria; $queryCriteria->resetConditions(); $queryCriteria->resetSorting(); $query = $this->queryBuilderFactory->createQuery($queryCriteria, $context); $query->innerJoin('product', 's_articles_esd', 'esd', 'esd.articleID = product.id'); $query->select('product.id')->setMaxResults(1); /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */ $statement = $query->execute(); $total = $statement->fetch(\PDO::FETCH_COLUMN); //found some esd products? if ($total <= 0) { return null; } $snippetNamespace = $this->snippetManager->getNamespace('frontend/listing/facet_labels'); return new BooleanFacetResult($facet->getName(), 'esd', $criteria->hasCondition($facet->getName()), $snippetNamespace->get('swag_search_bundle_esd_only', 'Only downloads')); }
/** * Generates the facet data for the passed query, criteria and context object. * * @param FacetInterface|Facet\ShippingFreeFacet $facet * @param Criteria $criteria * @param ShopContextInterface $context * @return BooleanFacetResult */ public function generateFacet(FacetInterface $facet, Criteria $criteria, ShopContextInterface $context) { $queryCriteria = clone $criteria; $queryCriteria->resetConditions(); $queryCriteria->resetSorting(); $query = $this->queryBuilderFactory->createQuery($queryCriteria, $context); $query->resetQueryPart('orderBy'); $query->resetQueryPart('groupBy'); if (!$query->hasState(ImmediateDeliveryConditionHandler::STATE_INCLUDES_ALL_VARIANTS)) { $query->innerJoin('product', 's_articles_details', 'allVariants', 'allVariants.articleID = product.id AND allVariants.active = 1 AND allVariants.instock >= allVariants.minpurchase'); $query->addState(ImmediateDeliveryConditionHandler::STATE_INCLUDES_ALL_VARIANTS); } $query->select('product.id')->setMaxResults(1); /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */ $statement = $query->execute(); $total = $statement->fetch(\PDO::FETCH_COLUMN); if ($total <= 0) { return null; } return new BooleanFacetResult($facet->getName(), $this->fieldName, $criteria->hasCondition($facet->getName()), $this->snippetNamespace->get($facet->getName(), 'Immediate delivery')); }
/** * @param Struct\ShopContextInterface $context * @param Criteria $queryCriteria * @return Struct\Property\Set[] */ protected function getProperties(Struct\ShopContextInterface $context, Criteria $queryCriteria) { $query = $this->queryBuilderFactory->createQuery($queryCriteria, $context); $this->rebuildQuery($query); /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */ $statement = $query->execute(); /**@var $facet Facet\PropertyFacet */ $valueIds = $statement->fetchAll(\PDO::FETCH_COLUMN); if (empty($valueIds)) { return null; } $properties = $this->propertyGateway->getList($valueIds, $context); return $properties; }
/** * @param FacetInterface|Facet\PriceFacet $facet * @param Criteria $criteria * @param ShopContextInterface $context * @return ValueListFacetResult */ public function generateFacet(FacetInterface $facet, Criteria $criteria, ShopContextInterface $context) { $queryCriteria = clone $criteria; $queryCriteria->resetConditions(); $queryCriteria->resetSorting(); $query = $this->queryBuilderFactory->createQuery($queryCriteria, $context); $query->resetQueryPart('groupBy'); $query->resetQueryPart('orderBy'); $query->groupBy('product.id'); $query->select('DISTINCT product.supplierID as id'); /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */ $statement = $query->execute(); $ids = $statement->fetchAll(\PDO::FETCH_COLUMN); $ids = array_filter($ids); if (empty($ids)) { return null; } $manufacturers = $this->manufacturerService->getList($ids, $context); $activeManufacturers = $this->getActiveIds($criteria); return $this->createFacetResult($manufacturers, $activeManufacturers); }
/** * @param Criteria $criteria * @param ShopContextInterface $context * @return array */ private function getCategoryIds(Criteria $criteria, ShopContextInterface $context) { $queryCriteria = clone $criteria; $queryCriteria->resetConditions(); $queryCriteria->resetSorting(); $queryCriteria->removeBaseCondition('category'); $queryCriteria->removeCondition('category'); $query = $this->queryBuilderFactory->createQuery($queryCriteria, $context); $query->resetQueryPart('orderBy'); $query->resetQueryPart('groupBy'); $query->select(['productCategory.categoryID']); $query->innerJoin('product', 's_articles_categories_ro', 'productCategory', 'productCategory.articleID = product.id'); $query->groupBy('productCategory.categoryID'); if ($criteria->hasCondition('category')) { /**@var $condition CategoryCondition */ $condition = $criteria->getCondition('category'); $parentIds = $condition->getCategoryIds(); } else { $parentIds = [1]; } /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */ $statement = $query->execute(); /**@var $facet Facet\CategoryFacet */ $ids = $statement->fetchAll(\PDO::FETCH_COLUMN); $query = $this->connection->createQueryBuilder(); $query->select(['category.id', 'category.path'])->from('s_categories', 'category')->where('category.parent IN (:parent) OR category.id IN (:parent)')->andWhere('category.id IN (:ids)')->andWhere('category.active = 1')->setParameter(':parent', $parentIds, Connection::PARAM_INT_ARRAY)->setParameter(':ids', $ids, Connection::PARAM_INT_ARRAY); $paths = $query->execute()->fetchAll(\PDO::FETCH_KEY_PAIR); $ids = array_keys($paths); $plain = array_values($paths); if (count($plain) > 0 && strpos($plain[0], '|') !== false) { $rootPath = explode('|', $plain[0]); $rootPath = array_filter(array_unique($rootPath)); $ids = array_merge($ids, $rootPath); return $ids; } return $ids; }