/** * Handles the passed condition object. * Extends the provided query builder with the specify conditions. * Should use the andWhere function, otherwise other conditions would be overwritten. * * @param MinStockCondition $condition * @param QueryBuilder $query * @param ShopContextInterface $context * @return void */ public function generateCondition(ConditionInterface $condition, QueryBuilder $query, ShopContextInterface $context) { if (!$condition->hasMinStock()) { return; } $query->andWhere('variantFilterArticleDetails.instock >= :minStock')->setParameter(':minStock', $condition->getMinStock()); }
/** * @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 generateCondition(ConditionInterface $condition, QueryBuilder $query, ShopContextInterface $context) { /**@var CreateDateCondition $condition */ $date = new \DateTime(); $intervalSpec = 'P' . $condition->getDays() . 'D'; $interval = new \DateInterval($intervalSpec); $date->sub($interval); $query->andWhere('product.datum >= :createDateFrom')->setParameter(':createDateFrom', $date->format('Y-m-d')); }
/** * {@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()); }
/** * {@inheritdoc} */ public function generateCondition(ConditionInterface $condition, QueryBuilder $query, ShopContextInterface $context) { $date = new \DateTime(); /** @var ReleaseDateCondition $condition */ $intervalSpec = 'P' . $condition->getDays() . 'D'; $interval = new \DateInterval($intervalSpec); $dateNow = new \DateTime(); switch ($condition->getDirection()) { case ReleaseDateCondition::DIRECTION_FUTURE: $date->add($interval); $query->andWhere('variant.releasedate <= :releaseDateFrom'); $query->andWhere('variant.releasedate > :dateNow'); $query->setParameter(':releaseDateFrom', $date->format('Y-m-d')); $query->setParameter(':dateNow', $dateNow->format('Y-m-d')); break; case ReleaseDateCondition::DIRECTION_PAST: $date->sub($interval); $query->andWhere('variant.releasedate >= :releaseDateTo'); $query->andWhere('variant.releasedate <= :dateNow'); $query->setParameter(':releaseDateTo', $date->format('Y-m-d')); $query->setParameter(':dateNow', $dateNow->format('Y-m-d')); break; } }
/** * {@inheritdoc} */ public function generateCondition(ConditionInterface $condition, QueryBuilder $query, ShopContextInterface $context) { /** @var SearchTermCondition $condition */ $searchQuery = $this->searchTermQueryBuilder->buildQuery($condition->getTerm()); //no matching products found by the search query builder. //add condition that the result contains no product. if ($searchQuery == null) { $query->andWhere('0 = 1'); return; } $queryString = $searchQuery->getSQL(); $query->addSelect('searchTable.*'); $query->addState(self::STATE_INCLUDES_RANKING); $query->innerJoin('product', '(' . $queryString . ')', 'searchTable', 'searchTable.product_id = product.id'); }
/** * {@inheritdoc} */ public function generateCondition(ConditionInterface $condition, QueryBuilder $query, ShopContextInterface $context) { /** @var ProductAttributeCondition $condition */ if (!$condition->getField()) { throw new \Exception('ProductAttributeCondition class requires a defined attribute field!'); } if (!$condition->getOperator()) { throw new \Exception('ProductAttributeCondition class requires a defined operator!'); } $placeholder = ':' . $condition->getField(); $field = 'productAttribute.' . $condition->getField(); switch (true) { case $condition->getValue() === null: if ($condition->getOperator() === ProductAttributeCondition::OPERATOR_EQ) { $query->andWhere($field . ' IS NULL'); } else { $query->andWhere($field . ' IS NOT NULL'); } break; case $condition->getOperator() === ProductAttributeCondition::OPERATOR_IN: $query->andWhere($field . ' IN (' . $placeholder . ')'); $query->setParameter($placeholder, $condition->getValue(), Connection::PARAM_STR_ARRAY); break; case $condition->getOperator() === ProductAttributeCondition::OPERATOR_CONTAINS: $query->andWhere($field . ' LIKE ' . $placeholder); $query->setParameter($placeholder, '%' . $condition->getValue() . '%'); break; case $condition->getOperator() === ProductAttributeCondition::OPERATOR_BETWEEN: $value = $condition->getValue(); if (isset($value['min'])) { $query->andWhere($field . ' >= ' . $placeholder . 'Min')->setParameter($placeholder . 'Min', $value['min']); } if (isset($value['max'])) { $query->andWhere($field . ' <= ' . $placeholder . 'Max')->setParameter($placeholder . 'Max', $value['max']); } break; case $condition->getOperator() === ProductAttributeCondition::OPERATOR_STARTS_WITH: $query->andWhere($field . ' LIKE ' . $placeholder); $query->setParameter($placeholder, $condition->getValue() . '%'); break; case $condition->getOperator() === ProductAttributeCondition::OPERATOR_ENDS_WITH: $query->andWhere($field . ' LIKE ' . $placeholder); $query->setParameter($placeholder, '%' . $condition->getValue()); break; default: $query->andWhere($field . ' ' . $condition->getOperator() . ' ' . $placeholder); $query->setParameter($placeholder, $condition->getValue()); break; } }
/** * {@inheritdoc} */ public function generateCondition(ConditionInterface $condition, QueryBuilder $query, ShopContextInterface $context) { $query->andWhere('variant.shippingfree = 1'); }
/** * {@inheritdoc} */ public function generateCondition(ConditionInterface $condition, QueryBuilder $query, ShopContextInterface $context) { $query->andWhere('variant.ordernumber IN (:ordernumbers)'); /** @var OrdernumberCondition $condition */ $query->setParameter(':ordernumbers', $condition->getOrdernumbers(), Connection::PARAM_STR_ARRAY); }
/** * {@inheritdoc} */ public function generateCondition(ConditionInterface $condition, QueryBuilder $query, ShopContextInterface $context) { $query->andWhere('product.laststock = 1'); }