AndFilter example

return $ids;
    }

    private function getUnusedCustomerCriteria(\DateTime $maxLifeTime): Criteria
    {
        $criteria = new Criteria();

        $criteria->addAssociation('orderCustomers');

        $criteria->addFilter(
            new AndFilter(
                [
                    new EqualsFilter('guest', true),
                    new EqualsFilter('orderCustomers.id', null),
                    new RangeFilter(
                        'createdAt',
                        [
                            RangeFilter::LTE => $maxLifeTime->format(Defaults::STORAGE_DATE_TIME_FORMAT),
                        ]
                    ),
                ]
            )
        );
protected function order(Cart $cart, SalesChannelContext $context, ?RequestDataBag $data = null): string
    {
        return $this->getContainer()->get(CartService::class)
            ->order($cart$context$data ?? new RequestDataBag());
    }

    protected function assertProductInOrder(string $orderId, string $productId): OrderLineItemEntity
    {
        $criteria = new Criteria();
        $criteria->setLimit(1);

        $criteria->addFilter(new AndFilter([
            new EqualsFilter('referencedId', $productId),
            new EqualsFilter('type', LineItem::PRODUCT_LINE_ITEM_TYPE),
            new EqualsFilter('orderId', $orderId),
        ]));

        $exists = $this->getContainer()->get('order_line_item.repository')
            ->search($criteria, Context::createDefaultContext());

        static::assertCount(1, $exists);

        $item = $exists->first();

        

        );

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


        $firstCategory = $categories->first();

        $entity = $firstCategory instanceof MainCategoryEntity ? $firstCategory->getCategory() : $firstCategory;

        return $product->getCategoryIds() !== null && \in_array($entity->getId()$product->getCategoryIds(), true) ? $entity : null;
    }

    private function getMainCategoryFilter(string $productId, SalesChannelContext $context): AndFilter
    {
        return new AndFilter([
            new EqualsFilter('mainCategories.productId', $productId),
            new EqualsFilter('mainCategories.salesChannelId', $context->getSalesChannelId()),
            $this->getSalesChannelFilter($context),
        ]);
    }
}
throw $exceptions;
        }

        $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();

        

            case 'nor':
                return new NorFilter(
                    self::parseQueries($definition$path$exception$query['queries'] ?? [])
                );
            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;
                }

        }
        $criteria->addQuery(
            new ScoreQuery(
                new ContainsFilter('product.searchKeywords.keyword', $pattern->getOriginal()->getTerm()),
                $pattern->getOriginal()->getScore(),
                'product.searchKeywords.ranking'
            )
        );

        if ($pattern->getBooleanClause() !== SearchPattern::BOOLEAN_CLAUSE_AND) {
            $criteria->addFilter(new AndFilter([
                new EqualsAnyFilter('product.searchKeywords.keyword', array_values($pattern->getAllTerms())),
                new EqualsFilter('product.searchKeywords.languageId', $context->getContext()->getLanguageId()),
            ]));

            return;
        }

        foreach ($pattern->getTokenTerms() as $terms) {
            $criteria->addFilter(new AndFilter([
                new EqualsFilter('product.searchKeywords.languageId', $context->getContext()->getLanguageId()),
                new EqualsAnyFilter('product.searchKeywords.keyword', $terms),
            ]));
$payload,
            new SearchRequestException()
        );

        static::assertEquals($expected$result);
    }

    public static function parserProvider(): \Generator
    {
        yield 'Test and filter' => [
            ['type' => 'and', 'queries' => [['type' => 'equals', 'field' => 'name', 'value' => 'foo']]],
            new AndFilter([new EqualsFilter('product.name', 'foo')]),
        ];
        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']]],
            
static::assertEquals($expected$has);
    }

    /** * @return iterable<array-key, array{0: Filter, 1: bool}> */
    public static function whenToUseNullSafeOperatorProvider()
    {
        yield 'Dont used for simple equals' => [new EqualsFilter('product.id', Uuid::randomHex()), false];
        yield 'Used for negated comparison' => [new NandFilter([new EqualsFilter('product.id', Uuid::randomHex())]), true];
        yield 'Used for negated null comparison' => [new NandFilter([new EqualsFilter('product.id', null)]), true];
        yield 'Used in nested negated comparison' => [new AndFilter([new NandFilter([new EqualsFilter('product.id', Uuid::randomHex())])]), true];
        yield 'Used for null comparison' => [new EqualsFilter('product.id', null), true];
    }

    public function testContainsFilterFindUnderscore(): void
    {
        $targetId = $this->createManufacturer(['link' => 'target_to_find']);
        $errournousId = $this->createManufacturer(['link' => 'target to find']);
        $criteria = (new Criteria())->addFilter(new ContainsFilter('link', 'target_to_find'));
        $foundIds = $this->manufacturerRepository->searchIds($criteria, Context::createDefaultContext());

        static::assertContains($targetId$foundIds->getIds());
        
$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
        );

        
static::assertTrue($result->has($ids->get('product-2')));
        static::assertTrue($result->has($ids->get('product-1')));
    }

    /** * @depends testIndexing */
    public function testOneToMany(IdsCollection $ids): void
    {
        $criteria = new Criteria($ids->prefixed('product-'));
        $criteria->addFilter(
            new AndFilter([
                new EqualsFilter('product.prices.ruleId', $ids->get('rule-1')),
                new RangeFilter('product.prices.price', [RangeFilter::GTE => 100]),
            ])
        );

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

        static::assertEquals(2, $result->getTotal());
        static::assertTrue($result->has($ids->get('product-2')));
        static::assertTrue($result->has($ids->get('product-1')));

        


        $result = $handler->create($request$context);

        $expected = new Filter(
            'properties',
            false,
            [
                new TermsAggregation('properties', 'product.properties.id'),
                new TermsAggregation('options', 'product.options.id'),
            ],
            new AndFilter(),
            [],
            false
        );

        static::assertEquals($expected$result);
    }

    /** * @param array<string> $input * @param array<array<string, string>> $mapping * * @dataProvider createProvider */
$criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('category.products.price', $greenPrice['gross']));

        $repository = $this->getContainer()->get('category.repository');
        $categories = $repository->searchIds($criteria$context);

        static::assertSame(1, $categories->getTotal());
        static::assertContains($categoryId$categories->getIds());

        $criteria = new Criteria();
        $criteria->addFilter(new AndFilter([
            new EqualsFilter('category.products.price', $parentPrice['gross']),
            new EqualsFilter('category.products.parentId', null),
        ]));

        $repository = $this->getContainer()->get('category.repository');
        $categories = $repository->searchIds($criteria$context);

        static::assertSame(1, $categories->getTotal());
        static::assertContains($categoryId$categories->getIds());
    }

    
$optionAggregation = new FilterAggregation(
                'options-filter',
                $optionAggregation,
                [new EqualsAnyFilter('product.options.groupId', $groupIds)]
            );
        }

        $aggregations = [$propertyAggregation$optionAggregation];

        if (empty($ids)) {
            return new Filter('properties', false, $aggregationsnew AndFilter([])[], false);
        }

        $grouped = $this->connection->fetchAllAssociative(
            'SELECT LOWER(HEX(property_group_id)) as property_group_id, LOWER(HEX(id)) as id FROM property_group_option WHERE id IN (:ids)',
            ['ids' => Uuid::fromHexToBytesList($ids)],
            ['ids' => ArrayParameterType::STRING]
        );

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

        


        $filters = $this->groupFilters($definition$criteria$paths);

        $this->criteriaPartResolver->resolve($filters$definition$query$context);

        $this->criteriaPartResolver->resolve($criteria->getQueries()$definition$query$context);

        $this->criteriaPartResolver->resolve($criteria->getSorting()$definition$query$context);

        // do not use grouped filters, because the grouped filters are mapped flat and the logical OR/AND are removed         $filter = new AndFilter(array_merge(
            $criteria->getFilters(),
            $criteria->getPostFilters()
        ));

        $this->addFilter($definition$filter$query$context);

        $this->addQueries($definition$criteria$query$context);

        if ($criteria->getLimit() === 1) {
            $query->removeState(EntityDefinitionQueryHelper::HAS_TO_MANY_JOIN);
        }

        
Home | Imprint | This part of the site doesn't use cookies.