getConditionsByClass example

return $condition instanceof ImmediateDeliveryCondition;
    }

    /** * {@inheritdoc} */
    public function generateCondition(
        ConditionInterface $condition,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        $conditions = $this->criteria->getConditionsByClass(VariantCondition::class);
        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        if (!$query->hasState(self::STATE_INCLUDES_IMMEDIATE_DELIVERY_VARIANTS)) {
            if (empty($conditions)) {
                $this->variantHelper->joinVariants($query);
                $query->andWhere('allVariants.instock >= allVariants.minpurchase');
            } else {
                $query->andWhere('variant.instock >= variant.minpurchase');
            }
            

    public function rewriteLinks(
        Criteria $criteria,
        array $articles,
        ShopContextInterface $context,
        $categoryId = null
    ) {
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);
        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        $products = array_map(function Darray $product) {
            return new BaseProduct($product['articleID']$product['articleDetailsID']$product['ordernumber']);
        }$articles);

        $configurations = [];
        if (!empty($conditions)) {
            $configurations = $this->configuratorService->getProductsConfigurations($products$context);
        }
use Shopware\Bundle\SearchBundle\Condition\VariantCondition;
use Shopware\Bundle\SearchBundle\Criteria;
use Shopware\Bundle\StoreFrontBundle\Struct\ShopContextInterface;

class PriceFieldMapper
{
    public function getPriceField(Criteria $criteria, ShopContextInterface $context)
    {
        $customerGroup = $context->getCurrentCustomerGroup()->getKey();
        $currency = $context->getCurrency()->getId();

        $conditions = $criteria->getConditionsByClass(VariantCondition::class);
        $ids = array_map(function DVariantCondition $condition) {
            return $condition->getGroupId();
        }$conditions);

        if (empty($conditions)) {
            return 'calculatedPrices.' . $customerGroup . '_' . $currency . '.calculatedPrice';
        }

        $ids = array_filter($ids);
        sort($ids, SORT_NUMERIC);

        


        return new FacetResultGroup($results, null, $facet->getName());
    }

    /** * @return array<int> */
    private function getFilteredValues(Criteria $criteria): array
    {
        $values = [];
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);

        foreach ($conditions as $condition) {
            foreach ($condition->getOptionIds() as $id) {
                $values[] = $id;
            }
        }

        return $values;
    }
}
return $condition instanceof HasPseudoPriceCondition;
    }

    /** * {@inheritdoc} */
    public function generateCondition(
        ConditionInterface $condition,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        $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');
            }
 {
        $this->variantCheapestPriceGateway = $variantCheapestPriceGateway;
        $this->priceCalculationService = $priceCalculationService;
        $this->config = $config;
    }

    /** * {@inheritdoc} */
    public function updatePrices(Criteria $criteria, ProductSearchResult $result, ShopContextInterface $context)
    {
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);

        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        if (empty($conditions)) {
            return;
        }

        // executed if no price condition included in search request
        
return null;
        }

        return $this->gateway->getOptions($valueIds$context);
    }

    /** * Modifies the query reading products from the database to reflect the selected options */
    private function rebuildQuery(Criteria $criteria, QueryBuilder $query, VariantFacet $facet): void
    {
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);
        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        $variantAlias = 'variant';
        if (empty($conditions)) {
            $this->helper->joinAvailableVariant($query);
            $variantAlias = 'availableVariant';
        }

        $query->innerJoin($variantAlias, 's_article_configurator_option_relations', 'variantOptions', 'variantOptions.article_id = ' . $variantAlias . '.id');

        
$this->maxFieldName,
            [],
            null,
            2,
            'frontend/listing/filter/facet-currency-range.tpl'
        );
    }

    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');

        


    /** * @template TCondition of ConditionInterface * * @param class-string<TCondition> $class * * @return bool */
    public function hasConditionOfClass($class)
    {
        $conditions = $this->getConditionsByClass($class);

        return !empty($conditions);
    }

    /** * @template TCondition of ConditionInterface * * @param class-string<TCondition> $class * * @return array<TCondition> */
    

    private function getListing(
        ?int $categoryId,
        ShopContextInterface $context,
        Enlight_Controller_Request_Request $request,
        Criteria $criteria
    ): array {
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);
        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        if (\count($conditions) > 0) {
            $this->config->offsetSet('forceArticleMainImageInListing', 0);
            $searchResult = $this->searchService->search($criteria$context);
            $this->config->offsetSet('forceArticleMainImageInListing', 1);
        } else {
            $searchResult = $this->searchService->search($criteria$context);
        }

        
return $condition instanceof IsAvailableCondition;
    }

    /** * {@inheritdoc} */
    public function generateCondition(
        ConditionInterface $condition,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        $conditions = $this->criteria->getConditionsByClass(VariantCondition::class);

        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        if (empty($conditions)) {
            // variants will ne be splitted => only check if product has an available variant             $this->priceHelper->joinAvailableVariant($query);

            return;
        }

        

    protected function joinListingPrices(QueryBuilder $query, ShopContextInterface $context, Criteria $criteria)
    {
        if ($query->hasState(self::VARIANT_LISTING_PRICE_JOINED)) {
            return;
        }

        $variantCondition = [
            'listing_price.product_id = variant.articleId',
        ];

        $conditions = $criteria->getConditionsByClass(VariantCondition::class);
        /** @var VariantCondition $condition */
        foreach ($conditions as $condition) {
            if ($condition->expandVariants()) {
                $this->joinVariantCondition($query$condition);

                $tableKey = $condition->getName();
                $variantCondition[] = 'listing_price.' . $tableKey . '_id = ' . $tableKey . '.option_id';
            }
        }

        $priceTable = $this->createListingPriceTable($criteria$context);

        
return;
        }

        $search->addPostFilter(
            new TermQuery('hasStock', true)
        );
    }

    private function buildGroupBy(Criteria $criteria): ?string
    {
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);

        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        $groups = array_map(function DVariantCondition $condition) {
            return $condition->getGroupId();
        }$conditions);

        if (empty($conditions)) {
            return null;
        }
$this->listingPriceService->updatePrices($criteria$result$context);

        $products = $result->getProducts();
        $configurations = $this->configuratorService->getProductsConfigurations($products$context);

        $filterGroupIds = array_map(function D$variantCondition) {
            if ($variantCondition->expandVariants()) {
                return $variantCondition->getGroupId();
            }

            return null;
        }$criteria->getConditionsByClass(VariantCondition::class));

        if (!empty($filterGroupIds)) {
            foreach ($products as $product) {
                if (!\array_key_exists($product->getNumber()$configurations)) {
                    continue;
                }

                $groups = [];
                foreach ($configurations[$product->getNumber()] as $group) {
                    if (\in_array($group->getId()$filterGroupIds)) {
                        $tmpGroup = ['groupName' => $group->getName()];
                        
$search->addPostFilter(
            new TermsQuery(
                'filterConfiguration.options.id',
                $criteriaPart->getOptionIds()
            )
        );
    }

    private function buildGroupBy(Criteria $criteria): ?string
    {
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);

        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        $groups = array_map(function DVariantCondition $condition) {
            return $condition->getGroupId();
        }$conditions);

        if (empty($conditions)) {
            return null;
        }
Home | Imprint | This part of the site doesn't use cookies.