/** * @param SortingInterface $sorting * @param QueryBuilder $query * @param ShopContextInterface $context * @throws \Exception */ public function generateSorting(SortingInterface $sorting, QueryBuilder $query, ShopContextInterface $context) { /** @var Listing $categoryComponent */ $categoryComponent = Shopware()->Container()->get('swagcustomsort.listing_component'); $categoryId = Shopware()->Front()->Request()->getParam('sCategory'); $linkedCategoryId = $categoryComponent->getLinkedCategoryId($categoryId); $hasCustomSort = $categoryComponent->hasCustomSort($categoryId); $baseSort = $categoryComponent->getCategoryBaseSort($categoryId); if ($hasCustomSort || $baseSort > 0) { $baseSorting = $categoryComponent->getCategoryBaseSort($categoryId); } else { $baseSorting = Shopware()->Config()->get('defaultListingSorting'); } //apply 'plugin' order if ($linkedCategoryId) { $query->leftJoin('productCategory', 's_articles_sort', 'customSort', 'customSort.articleId = productCategory.articleID AND (customSort.categoryId = :sortCategoryId OR customSort.categoryId IS NULL)'); $query->setParameter('sortCategoryId', $linkedCategoryId); } else { $query->leftJoin('productCategory', 's_articles_sort', 'customSort', 'customSort.articleId = productCategory.articleID AND (customSort.categoryId = productCategory.categoryID OR customSort.categoryId IS NULL)'); } //exclude passed products ids from result $sortedProductsIds = $this->sortingComponent->getSortedProductsIds(); if ($sortedProductsIds) { $query->andWhere($query->expr()->notIn("product.id", $sortedProductsIds)); } //for records with no 'plugin' order data use the default shopware order $handlerData = $this->getDefaultData($baseSorting); if ($handlerData) { $sorting->setDirection($handlerData['direction']); $handlerData['handler']->generateSorting($sorting, $query, $context); } }
/** * {@inheritdoc} */ public function generateCondition(ConditionInterface $condition, QueryBuilder $query, ShopContextInterface $context) { $query->leftJoin('product', 's_articles_avoid_customergroups', 'avoidCustomerGroup', 'avoidCustomerGroup.articleID = product.id AND avoidCustomerGroup.customerGroupId IN (:customerGroupIds)'); /** @var CustomerGroupCondition $condition */ $query->setParameter(':customerGroupIds', $condition->getCustomerGroupIds(), Connection::PARAM_INT_ARRAY); $query->andWhere('avoidCustomerGroup.articleID IS NULL'); }
/** * {@inheritdoc} */ public function generateSorting(SortingInterface $sorting, QueryBuilder $query, ShopContextInterface $context) { if (!$query->hasState(SalesConditionHandler::STATE_INCLUDES_TOPSELLER_TABLE)) { $query->leftJoin('product', 's_articles_top_seller_ro', 'topSeller', 'topSeller.article_id = product.id'); $query->addState(SalesConditionHandler::STATE_INCLUDES_TOPSELLER_TABLE); } /** @var PopularitySorting $sorting */ $query->addOrderBy('topSeller.sales', $sorting->getDirection())->addOrderBy('topSeller.article_id', $sorting->getDirection()); }
/** * Extends the query and returns the alias to bind the definitition to. * * @param QueryBuilder $queryBuilder * * @return string */ public function extendQuery(QueryBuilder $queryBuilder, AbstractSortDefinition $definition) { $alias = $this->createAlias('Variant'); if ($queryBuilder->hasState($alias)) { return $alias; } $queryBuilder->leftJoin('product', $this->getTableName(), $alias, $alias . '.articleID = product.id'); $queryBuilder->addState($alias); return $alias; }
/** * {@inheritdoc} */ public function generateCondition(ConditionInterface $condition, QueryBuilder $query, ShopContextInterface $context) { if (!$query->hasState(self::STATE_INCLUDES_TOPSELLER_TABLE)) { $query->leftJoin('product', 's_articles_top_seller_ro', 'topSeller', 'topSeller.article_id = product.id'); $query->addState(self::STATE_INCLUDES_TOPSELLER_TABLE); } $query->andWhere('topSeller.sales > :sales'); /** @var SalesCondition $condition */ $query->setParameter('sales', $condition->getMinSales()); }