Example #1
0
 /**
  * Traces the search result into the s_statistic_search
  *
  * @param Criteria $criteria
  * @param ProductNumberSearchResult $result
  * @param Shop $shop
  */
 public function logResult(Criteria $criteria, ProductNumberSearchResult $result, Shop $shop)
 {
     if (!$criteria->hasCondition('search')) {
         return;
     }
     /* @var $condition SearchTermCondition */
     $condition = $criteria->getCondition('search');
     $now = new \DateTime();
     $this->connection->insert('s_statistics_search', ['datum' => $now->format('Y-m-d H:i:s'), 'searchterm' => $condition->getTerm(), 'results' => $result->getTotalCount(), 'shop_id' => $shop->getId()]);
 }
Example #2
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'));
 }
 /**
  * @param Criteria $criteria
  * @return BooleanFacetResult
  */
 private function createFacet(Criteria $criteria)
 {
     $label = $this->snippetManager->getNamespace('frontend/listing/facet_labels')->get('immediate_delivery', 'Immediate delivery');
     if (!($fieldName = $this->queryAliasMapper->getShortAlias('immediateDelivery'))) {
         $fieldName = 'immediateDelivery';
     }
     $criteriaPart = new BooleanFacetResult('immediate_delivery', $fieldName, $criteria->hasCondition('immediate_delivery'), $label);
     return $criteriaPart;
 }
 /**
  * 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'));
 }
 /**
  * @param Criteria $criteria
  * @param float $min
  * @param float $max
  * @return RangeFacetResult
  */
 private function createFacet(Criteria $criteria, $min, $max)
 {
     $activeMin = $min;
     $activeMax = $max;
     /**@var $condition PriceCondition */
     if ($condition = $criteria->getCondition('price')) {
         $activeMin = $condition->getMinPrice();
         $activeMax = $condition->getMaxPrice();
     }
     $label = $this->snippetManager->getNamespace('frontend/listing/facet_labels')->get('price', 'Price');
     if (!($minFieldName = $this->queryAliasMapper->getShortAlias('priceMin'))) {
         $minFieldName = 'priceMin';
     }
     if (!($maxFieldName = $this->queryAliasMapper->getShortAlias('priceMax'))) {
         $maxFieldName = 'priceMax';
     }
     return new RangeFacetResult('price', $criteria->hasCondition('price'), $label, (double) $min, (double) $max, (double) $activeMin, (double) $activeMax, $minFieldName, $maxFieldName, [], 'frontend/listing/filter/facet-currency-range.tpl');
 }
 /**
  * @param Criteria $criteria
  * @param $items
  * @return ValueListFacetResult
  */
 private function createFacet(Criteria $criteria, $items)
 {
     if (!($fieldName = $this->queryAliasMapper->getShortAlias('sSupplier'))) {
         $fieldName = 'sSupplier';
     }
     $label = $this->snippetManager->getNamespace('frontend/listing/facet_labels')->get('manufacturer', 'Manufacturer');
     return new ValueListFacetResult('manufacturer', $criteria->hasCondition('manufacturer'), $label, $items, $fieldName);
 }
 /**
  * @param QueryBuilder $query
  * @param ProductAttributeFacet $facet
  * @param Criteria $criteria
  * @return null|BooleanFacetResult
  */
 private function createBooleanFacetResult(QueryBuilder $query, ProductAttributeFacet $facet, Criteria $criteria)
 {
     $sqlField = 'productAttribute.' . $facet->getField();
     $query->select('COUNT(' . $sqlField . ')');
     /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */
     $statement = $query->execute();
     $result = $statement->fetch(\PDO::FETCH_COLUMN);
     if (empty($result)) {
         return null;
     }
     return new BooleanFacetResult($facet->getName(), $facet->getFormFieldName(), $criteria->hasCondition($facet->getName()), $facet->getLabel());
 }
 /**
  * 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'));
 }
 /**
  * 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');
 }
Example #10
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');
 }
 /**
  * @param Criteria $criteria
  * @return int[]
  */
 private function getActiveIds($criteria)
 {
     if (!$criteria->hasCondition('manufacturer')) {
         return [];
     }
     /**@var $condition Condition\ManufacturerCondition*/
     $condition = $criteria->getCondition('manufacturer');
     return $condition->getManufacturerIds();
 }
 /**
  * @param ProductAttributeFacet $criteriaPart
  * @param $data
  * @param Criteria $criteria
  * @return RangeFacetResult
  */
 private function createRangeResult(ProductAttributeFacet $criteriaPart, $data, Criteria $criteria)
 {
     $values = array_column($data['buckets'], 'key');
     $min = min($values);
     $max = max($values);
     $template = $criteriaPart->getTemplate();
     if (!$template) {
         $template = 'frontend/listing/filter/facet-range.tpl';
     }
     $activeMin = $min;
     $activeMax = $max;
     /**@var $condition ProductAttributeCondition*/
     if ($condition = $criteria->getCondition($criteriaPart->getName())) {
         $data = $condition->getValue();
         $activeMin = $data['min'];
         $activeMax = $data['max'];
     }
     return new RangeFacetResult($criteriaPart->getName(), $criteria->hasCondition($criteriaPart->getName()), $criteriaPart->getLabel(), $min, $max, $activeMin, $activeMax, 'min' . $criteriaPart->getFormFieldName(), 'max' . $criteriaPart->getFormFieldName(), [], $template);
 }
 /**
  * @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;
 }
 /**
  * @param Criteria $criteria
  * @return RadioFacetResult
  */
 private function createFacet(Criteria $criteria)
 {
     $activeAverage = null;
     if ($criteria->hasCondition('vote_average')) {
         /**@var $condition VoteAverageCondition*/
         $condition = $criteria->getCondition('vote_average');
         $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)];
     $label = $this->snippetManager->getNamespace('frontend/listing/facet_labels')->get('vote_average', 'Ranking');
     if (!($fieldName = $this->queryAliasMapper->getShortAlias('rating'))) {
         $fieldName = 'rating';
     }
     return new RadioFacetResult('vote_average', $criteria->hasCondition('vote_average'), $label, $values, $fieldName, [], 'frontend/listing/filter/facet-rating.tpl');
 }
 /**
  * @param Criteria $criteria
  * @param $data
  * @return array
  */
 private function getCategoryIds(Criteria $criteria, $data)
 {
     $ids = array_column($data, 'key');
     if ($criteria->hasCondition('category')) {
         /**@var $condition CategoryCondition */
         $condition = $criteria->getCondition('category');
         $parentIds = $condition->getCategoryIds();
     } else {
         $parentIds = [1];
     }
     $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;
 }