/** * {@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); }