/**
  * 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;
 }
 /**
  * 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');
 }
예제 #3
0
 /**
  * @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');
     $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'));
 }
 /**
  * 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'));
 }
예제 #6
0
 /**
  * @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');
 }