OrFilter example

'isCanonical' => false,
                ],
                [
                    'languageId' => Defaults::LANGUAGE_SYSTEM,
                    'routeName' => 'test',
                    'pathInfo' => 'test',
                    'seoPathInfo' => 'not-active',
                    'isCanonical' => false,
                ],
            ],
            function DCriteria $criteria): void {
                $filter = new OrFilter([
                    new EqualsFilter('isCanonical', true),
                ]);
                $filter->addQuery(new EqualsFilter('seoPathInfo', 'active-query'));

                $criteria->getAssociation('seoUrls')->setLimit(20);
                $criteria->getAssociation('seoUrls')->addFilter($filter);
                $criteria->getAssociation('seoUrls')->addSorting(new FieldSorting('isCanonical', FieldSorting::ASCENDING));
            },
            [
                'active-query',
                'active',
            ],
/** * @param array{ids: array<string>, rules: array<string>} $case */
    private function assertSorting(string $message, IdsCollection $ids, SalesChannelContext $context, array $case, string $direction): void
    {
        $criteria = new Criteria(array_values($ids->all()));

        $criteria->addSorting(new FieldSorting('product.cheapestPrice', $direction));
        $criteria->addSorting(new FieldSorting('product.productNumber', $direction));

        $criteria->addFilter(new OrFilter([
            new NandFilter([new EqualsFilter('product.parentId', null)]),
            new EqualsFilter('product.childCount', 0),
        ]));

        $result = $this->getContainer()->get('sales_channel.product.repository')
            ->searchIds($criteria$context);

        $expected = $case['ids'];
        if ($direction === FieldSorting::DESCENDING) {
            $expected = array_reverse($expected);
        }

        
public static function createProvider(): \Generator
    {
        $ids = new IdsCollection();

        yield 'Test two groups and single option' => [
            // input for the request             [$ids->get('XL')$ids->get('green')],

            // expected filter             new AndFilter([
                // each "group" should be an OR filter (e.g. size OR color)                 new OrFilter([
                    new EqualsAnyFilter('product.optionIds', [$ids->get('XL')]),
                    new EqualsAnyFilter('product.propertyIds', [$ids->get('XL')]),
                ]),
                new OrFilter([
                    new EqualsAnyFilter('product.optionIds', [$ids->get('green')]),
                    new EqualsAnyFilter('product.propertyIds', [$ids->get('green')]),
                ]),
            ]),

            // mapping from the storage             [
                [
foreach ($nested->getParameters() as $key => $value) {
            $type = $nested->getParameterType($key);
            $query->setParameter($key$value$type);
        }
    }

    private function parseFilter(JoinGroup $group, EntityDefinition $definition, QueryBuilder $query, Context $context, string $alias): void
    {
        $filter = new AndFilter($group->getQueries());
        if ($group->getOperator() === MultiFilter::CONNECTION_OR) {
            $filter = new OrFilter($group->getQueries());
        }

        $parsed = $this->parser->parse($filter$definition$context);
        if (empty($parsed->getWheres())) {
            return;
        }

        foreach ($parsed->getParameters() as $key => $value) {
            $query->setParameter($key$value$parsed->getType($key));
        }

        

                        'de-DE' => [
                            'sw-color-brand-primary' => 'Primärfarbe',
                        ],
                    ],
                ],
            ]$this->context);
        }

        $criteria = new Criteria();
        $criteria->addFilter(
            new OrFilter(
                [
                    new EqualsFilter('fileName', 'demostore-logo'),
                    new EqualsFilter('fileName', 'favicon'),
                ]
            )
        );
        $medias = $this->mediaRepository->search($criteria$this->context);

        /** @var MediaEntity $media */
        foreach ($medias as $media) {
            if ($media->getFileName() === 'favicon') {
                
return null;
    }

    private function getSalesChannelFilter(SalesChannelContext $context): MultiFilter
    {
        $ids = array_filter([
            $context->getSalesChannel()->getNavigationCategoryId(),
            $context->getSalesChannel()->getServiceCategoryId(),
            $context->getSalesChannel()->getFooterCategoryId(),
        ]);

        return new OrFilter(array_map(static fn (string $id) => new ContainsFilter('path', '|' . $id . '|')$ids));
    }

    private function getMainCategory(ProductEntity $product, SalesChannelContext $context): ?CategoryEntity
    {
        $criteria = new Criteria();
        $criteria->setLimit(1);
        $criteria->setTitle('breadcrumb-builder::main-category');

        if (($product->getMainCategories() === null || $product->getMainCategories()->count() <= 0) && $product->getParentId() !== null) {
            $criteria->addFilter($this->getMainCategoryFilter($product->getParentId()$context));
        } else {
            
if (\count($filter->getQueries()) === 1) {
            $bool->add(
                $this->parseFilter($filter->getQueries()[0]$definition$root$context),
                BoolQuery::MUST_NOT
            );

            return $bool;
        }

        $multiFilter = match ($filter->getOperator()) {
            MultiFilter::CONNECTION_OR => new OrFilter(),
            MultiFilter::CONNECTION_XOR => new XOrFilter(),
            default => new AndFilter(),
        };

        foreach ($filter->getQueries() as $query) {
            $multiFilter->addQuery($query);
        }

        $bool->add(
            $this->parseFilter($multiFilter$definition$root$context),
            BoolQuery::MUST_NOT
        );
$this->adjustment->adjust($cart$result$context);
    }

    private function getTaxProviders(SalesChannelContext $context): TaxProviderCollection
    {
        $criteria = (new Criteria())
            ->addAssociations(['availabilityRule', 'app'])
            ->addFilter(
                new AndFilter([
                    new EqualsFilter('active', true),
                    new OrFilter([
                        new EqualsFilter('availabilityRuleId', null),
                        new EqualsAnyFilter('availabilityRuleId', $context->getRuleIds()),
                    ]),
                ])
            );

        /** @var TaxProviderCollection $providers */
        $providers = $this->taxProviderRepository->search($criteria$context->getContext())->getEntities();

        // we can safely sort the providers in php, as we do not expect more than a couple of providers         // otherwise we would need to sort them in the database with an index many fields to be performant
$criteria->addFilter(new EqualsFilter('avatarUsers.id', null));

        $media = $this->getContainer()->get('media.repository')
            ->searchIds($criteria, Context::createDefaultContext());

        static::assertTrue(\count($media->getIds()) > 0);
        static::assertContains($ids->get('without-avatar')$media->getIds());
        static::assertNotContains($ids->get('with-avatar')$media->getIds());

        $criteria = new Criteria();
        $criteria->addFilter(
            new OrFilter([
                new EqualsFilter('avatarUsers.id', null),
                new NandFilter([new EqualsFilter('avatarUsers.id', Uuid::randomHex())]),
            ])
        );

        $media = $this->getContainer()->get('media.repository')
            ->searchIds($criteria, Context::createDefaultContext());

        static::assertTrue(\count($media->getIds()) > 0);
        static::assertContains($ids->get('with-avatar')$media->getIds());
        static::assertContains($ids->get('without-avatar')$media->getIds());

        
$userRecovery = $this->getContainer()->get('user_recovery.repository')->search(
            $criteria,
            Context::createDefaultContext()
        )->first();

        static::assertNotNull($userRecovery);
        static::assertNotNull($dispatchedEvent);

        // excluded events and its mail events should not be logged         $originalEvent = $dispatchedEvent->getName();
        $logCriteria = new Criteria();
        $logCriteria->addFilter(new OrFilter([
            new EqualsFilter('message', $originalEvent),
            new EqualsFilter('context.additionalData.eventName', $originalEvent),
        ]));

        $logEntries = $this->getContainer()->get('log_entry.repository')->search(
            $logCriteria,
            Context::createDefaultContext()
        );

        static::assertCount(0, $logEntries);

        
$bestVariant = $searchResult->filterByProperty('parentId', $productId)->first();

        /** @var SalesChannelProductEntity|null $product */
        $product = $bestVariant ?? $searchResult->get($productId);

        return $product;
    }

    private function createBestVariantCriteria(string $productId): Criteria
    {
        $criteria = (new Criteria())
            ->addFilter(new OrFilter([
                new EqualsFilter('product.parentId', $productId),
                new EqualsFilter('id', $productId),
            ]))
            ->addGroupField(new FieldGrouping('displayGroup'));

        $criteria->setTitle('cms::product-detail-static');

        return $criteria;
    }
}

            case 'not':
                return new NotFilter(
                    $query['operator'] ?? 'AND',
                    self::parseQueries($definition$path$exception$query['queries'] ?? [])
                );
            case 'and':
                return new AndFilter(
                    self::parseQueries($definition$path$exception$query['queries'] ?? [])
                );
            case 'or':
                return new OrFilter(
                    self::parseQueries($definition$path$exception$query['queries'] ?? [])
                );
            case 'multi':
                $operator = MultiFilter::CONNECTION_AND;

                if (isset($query['operator']) && mb_strtoupper((string) $query['operator']) === MultiFilter::CONNECTION_OR) {
                    $operator = MultiFilter::CONNECTION_OR;
                }

                $queries = self::parseQueries($definition$path$exception$query['queries'] ?? []);

                

        yield 'Test null queries' => [
            ['type' => 'and', 'queries' => null],
            new AndFilter(),
        ];
        yield 'Test without queries' => [
            ['type' => 'and'],
            new AndFilter(),
        ];
        yield 'Test or filter' => [
            ['type' => 'or', 'queries' => [['type' => 'equals', 'field' => 'name', 'value' => 'foo']]],
            new OrFilter([new EqualsFilter('product.name', 'foo')]),
        ];
        yield 'Test nor filter' => [
            ['type' => 'nor', 'queries' => [['type' => 'equals', 'field' => 'name', 'value' => 'foo']]],
            new NorFilter([new EqualsFilter('product.name', 'foo')]),
        ];
        yield 'Test nand filter' => [
            ['type' => 'nand', 'queries' => [['type' => 'equals', 'field' => 'name', 'value' => 'foo']]],
            new NandFilter([new EqualsFilter('product.name', 'foo')]),
        ];
    }

    
/** * @depends testIndexing */
    public function testCheapestPriceAggregation(IdsCollection $ids): void
    {
        $context = $this->context;

        try {
            $affected = [...$ids->prefixed('p.'), ...$ids->prefixed('v.')];
            $criteria = new Criteria(array_values($affected));
            $criteria->addState(Criteria::STATE_ELASTICSEARCH_AWARE);
            $criteria->addFilter(new OrFilter([
                new NandFilter([new EqualsFilter('product.parentId', null)]),
                new EqualsFilter('product.childCount', 0),
            ]));

            $criteria->addAggregation(new StatsAggregation('price', 'product.cheapestPrice'));

            $aggregator = $this->createEntityAggregator();

            $cases = $this->providerCheapestPriceAggregation();

            foreach ($cases as $message => $case) {
                

            ['ids' => Uuid::fromHexToBytesList($ids)],
            ['ids' => ArrayParameterType::STRING]
        );

        $grouped = FetchModeHelper::group($grouped);

        $filters = [];
        foreach ($grouped as $options) {
            $options = array_column($options, 'id');

            $filters[] = new OrFilter([
                new EqualsAnyFilter('product.optionIds', $options),
                new EqualsAnyFilter('product.propertyIds', $options),
            ]);
        }

        return new Filter('properties', true, $aggregationsnew AndFilter($filters)$ids, false);
    }

    /** * @return array<int, non-falsy-string> */
    
Home | Imprint | This part of the site doesn't use cookies.