joinPrice example

 {
        $conditions = $this->criteria->getConditionsByClass(VariantCondition::class);
        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        if (!$query->hasState(self::STATE_INCLUDES_PSEUDO_PRICE_VARIANTS)) {
            if (empty($conditions)) {
                $this->variantHelper->joinVariants($query);
                $this->joinPrices($query$context);
            } else {
                $this->listingPriceSwitcher->joinPrice($query$this->criteria, $context);
                $query->andWhere('listing_price.pseudoprice > 0');
            }

            $query->addState(self::STATE_INCLUDES_PSEUDO_PRICE_VARIANTS);
        }
    }

    public function setCriteria(Criteria $criteria)
    {
        $this->criteria = $criteria;
    }

    
private function buildQuery(Criteria $reverted, Criteria $criteria, ShopContextInterface $context): QueryBuilder
    {
        $tmp = clone $reverted;
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);
        foreach ($conditions as $condition) {
            $tmp->addBaseCondition($condition);
        }

        $query = $this->queryBuilderFactory->createQuery($tmp$context);

        $this->listingPriceSwitcher->joinPrice($query$criteria$context);
        $query->select('listing_price.cheapest_price');
        $query->setFirstResult(0);
        $query->setMaxResults(1);
        $query->addGroupBy('product.id');

        return $query;
    }
}
 {
        $this->addCondition($condition$query$context);
    }

    public function setCriteria(Criteria $criteria)
    {
        $this->criteria = $criteria;
    }

    private function addCondition(PriceCondition $condition, QueryBuilder $query, ShopContextInterface $context): void
    {
        $this->priceSwitcher->joinPrice($query$this->criteria, $context);

        $suffix = md5(json_encode($condition, JSON_THROW_ON_ERROR));

        $minKey = ':priceMin' . $suffix;
        $maxKey = ':priceMax' . $suffix;

        if ($condition->getMaxPrice() > 0 && $condition->getMinPrice() > 0) {
            $query->andWhere('listing_price.cheapest_price BETWEEN ' . $minKey . ' AND ' . $maxKey);
            $query->setParameter($minKey$condition->getMinPrice());
            $query->setParameter($maxKey$condition->getMaxPrice());

            
 {
        $this->addSorting($sorting$query$context);
    }

    public function setCriteria(Criteria $criteria)
    {
        $this->criteria = $criteria;
    }

    private function addSorting(PriceSorting $sorting, QueryBuilder $query, ShopContextInterface $context): void
    {
        $this->listingPriceSwitcher->joinPrice($query$this->criteria, $context);

        $query->addOrderBy('listing_price.cheapest_price', $sorting->getDirection());
    }
}
Home | Imprint | This part of the site doesn't use cookies.