/** * 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()); }
/** * {@inheritdoc} */ public function generateCondition(ConditionInterface $condition, QueryBuilder $query, ShopContextInterface $context) { $query->innerJoin('product', 's_articles_supplier', 'manufacturer', 'manufacturer.id = product.supplierID AND product.supplierID IN (:manufacturer)'); /** @var ManufacturerCondition $condition */ $query->setParameter(':manufacturer', $condition->getManufacturerIds(), Connection::PARAM_INT_ARRAY); }
/** * {@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) { if ($this->counter++ === 0) { $suffix = ''; } else { $suffix = $this->counter; } $query->innerJoin('product', 's_articles_categories_ro', "productCategory{$suffix}", "productCategory{$suffix}.articleID = product.id\n AND productCategory{$suffix}.categoryID IN (:category{$suffix})"); /** @var CategoryCondition $condition */ $query->setParameter(":category{$suffix}", $condition->getCategoryIds(), Connection::PARAM_INT_ARRAY); }
/** * {@inheritdoc} */ public function generateCondition(ConditionInterface $condition, QueryBuilder $query, ShopContextInterface $context) { $table = ' SELECT SUM(vote.points) / COUNT(vote.id) AS average, vote.articleID AS product_id FROM s_articles_vote vote GROUP BY vote.articleID'; $query->innerJoin('product', '(' . $table . ')', 'voteAverage', 'voteAverage.product_id = product.id AND voteAverage.average >= :average'); /** @var VoteAverageCondition $condition */ $query->setParameter(':average', (double) $condition->getAverage()); $query->addSelect('voteAverage.average'); $query->addState(VoteAverageCondition::STATE_INCLUDES_VOTE_TABLE); }
/** * {@inheritdoc} */ public function generateCondition(ConditionInterface $condition, QueryBuilder $query, ShopContextInterface $context) { $ids = $condition->getProductVariantIds(); if (!$ids) { return; } $query->innerJoin('product', 's_articles_details', 'variantFilterArticleDetails', 'variantFilterArticleDetails.articleID = product.id'); foreach ($ids as $groupId => $variantOptions) { $tableAlias = 'variantFilterArticleDetails' . $groupId; $paramAlias = ':options' . $groupId; $query->innerJoin('variantFilterArticleDetails', 's_article_configurator_option_relations', $tableAlias, 'variantFilterArticleDetails.id = ' . $tableAlias . '.article_id AND ' . $tableAlias . '.option_id IN (' . $paramAlias . ')')->setParameter($paramAlias, $variantOptions, Connection::PARAM_INT_ARRAY); } }
/** * {@inheritdoc} */ public function generateCondition(ConditionInterface $condition, QueryBuilder $query, ShopContextInterface $context) { $tableKey = $condition->getName(); $where = []; /** @var PropertyCondition $condition */ foreach ($condition->getValueIds() as $valueId) { $valueKey = $tableKey . '_' . $valueId; $where[] = $tableKey . '.valueID = :' . $valueKey; $query->setParameter(':' . $valueKey, $valueId); } $where = implode(' OR ', $where); $query->innerJoin('product', 's_filter_articles', $tableKey, 'product.id = ' . $tableKey . '.articleID AND (' . $where . ')'); }
/** * {@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) { $selection = $this->priceHelper->getSelection($context); $selection = 'MIN(' . $selection . ')'; $this->priceHelper->joinPrices($query, $context); /** @var PriceCondition $condition */ if ($condition->getMaxPrice() > 0 && $condition->getMinPrice() > 0) { $query->andHaving($selection . ' BETWEEN :priceMin AND :priceMax'); $query->setParameter(':priceMin', $condition->getMinPrice()); $query->setParameter(':priceMax', $condition->getMaxPrice()); } elseif ($condition->getMaxPrice() > 0) { $query->andHaving($selection . ' <= :priceMax'); $query->setParameter(':priceMax', $condition->getMaxPrice()); } elseif ($condition->getMinPrice() > 0) { $query->andHaving($selection . ' >= :priceMin'); $query->setParameter(':priceMin', $condition->getMinPrice()); } return; }
/** * {@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) { $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) { /** @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; } }