NandFilter example

if ($route === null) {
            throw new \RuntimeException(sprintf('Route by name %s not found', $routeName));
        }

        $context = Context::createDefaultContext();

        $languageChains = $this->fetchLanguageChains($context);

        $criteria = new Criteria();

        if (Feature::isActive('v6.6.0.0')) {
            $criteria->addFilter(new NandFilter([new EqualsFilter('typeId', Defaults::SALES_CHANNEL_TYPE_API)]));
        }

        $salesChannels = $this->salesChannelRepository->search($criteria$context)->getEntities();

        foreach ($templates as $config) {
            $template = $config['template'];
            $salesChannel = $salesChannels->get($config['salesChannelId']);
            if ($template === '' || $salesChannel === null) {
                continue;
            }

            

    /** * @internal */
    public function __construct(private readonly EntityRepository $languageRepositoryprivate readonly EventDispatcherInterface $eventDispatcher)
    {
    }

    public function getLanguages(Context $context): LanguageCollection
    {
        $criteria = new Criteria();
        $criteria->addFilter(new NandFilter([new EqualsFilter('salesChannels.id', null)]));
        $criteria->addSorting(new FieldSorting('id'));

        $this->eventDispatcher->dispatch(new ElasticsearchIndexerLanguageCriteriaEvent($criteria$context));

        /** @var LanguageCollection $languages */
        $languages = $this->languageRepository
            ->search($criteria$context)
            ->getEntities();

        return $languages;
    }
}

        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')]),
        ];
    }

    /** * @dataProvider equalsFilterDataProvider * * @param EqualsFilterType $filter */
    public function testEqualsFilter(array $filter, bool $expectException): void
    {
        if ($expectException) {
            


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

        
if (!\array_key_exists('value', $query) || $query['value'] === '') {
                    throw DataAbstractionLayerException::invalidFilterQuery('Parameter "value" for equals filter is missing.', $path . '/value');
                }

                if (!\is_scalar($query['value']) && $query['value'] !== null) {
                    throw DataAbstractionLayerException::invalidFilterQuery('Parameter "value" for equals filter must be scalar or null.', $path . '/value');
                }

                return new EqualsFilter(self::buildFieldName($definition$query['field'])$query['value']);
            case 'nand':
                return new NandFilter(
                    self::parseQueries($definition$path$exception$query['queries'] ?? [])
                );
            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'] ?? [])
                );
            

        return $this->getContainer();
    }

    protected function runWorker(): void
    {
    }

    private function getValidLocaleId(): string
    {
        $criteria = new Criteria();
        $criteria->addFilter(new NandFilter([new EqualsFilter('id', $this->getLocaleIdOfSystemLanguage())]));
        $criteria->setLimit(1);

        $localeId = $this->getContainer()->get(\sprintf('%s.repository', LocaleDefinition::ENTITY_NAME))->searchIds($criteria, Context::createDefaultContext())->firstId();
        static::assertNotNull($localeId);

        return $localeId;
    }
}
$this->getContainer()
                ->get('currency.repository')
                ->upsert($currencies$this->context);

            $this->createData();

            $this->indexElasticSearch();

            $criteria = new Criteria();
            $criteria->addFilter(
                new NandFilter([new EqualsFilter('salesChannelDomains.id', null)])
            );

            if (Feature::isActive('ES_MULTILINGUAL_INDEX')) {
                $index = $this->helper->getIndexName($this->productDefinition);

                $exists = $this->client->indices()->exists(['index' => $index]);
                static::assertTrue($exists, 'Expected elasticsearch indices present');
            } else {
                $languages = $this->languageRepository->searchIds($criteria$context);

                foreach ($languages->getIds() as $languageId) {
                    

    private function createUrls(array $ids, Context $context): void
    {
        $criteria = new Criteria($ids);
        $criteria->addFilter(new EqualsFilter('registrationActive', true));

        $criteria->addAssociation('registrationSalesChannels.languages');
        $criteria->addAssociation('translations');

        if (Feature::isActive('v6.6.0.0')) {
            $criteria->getAssociation('registrationSalesChannels')->addFilter(
                new NandFilter([new EqualsFilter('typeId', Defaults::SALES_CHANNEL_TYPE_API)])
            );
        }

        /** @var CustomerGroupCollection $groups */
        $groups = $this->customerGroupRepository->search($criteria$context)->getEntities();
        $buildUrls = [];

        foreach ($groups as $group) {
            if ($group->getRegistrationSalesChannels() === null) {
                continue;
            }

            
return $ids;
    }

    /** * @depends testIndexing */
    public function testOneToOne(IdsCollection $ids): void
    {
        $criteria = new Criteria();
        $criteria->addFilter(
            new NandFilter([new EqualsFilter('avatarUsers.id', null)])
        );

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

        static::assertCount(1, $media->getIds());
        static::assertContains($ids->get('with-avatar')$media->getIds());
        static::assertNotContains($ids->get('without-avatar')$media->getIds());

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('avatarUsers.id', null));

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

        
/** * @param array<string> $ids */
    public function update(array $ids, Context $context): void
    {
        if (empty($ids)) {
            return;
        }

        $criteria = new Criteria();
        $criteria->addFilter(new NandFilter([new EqualsFilter('salesChannels.id', null)]));
        $languages = $this->languageRepository->search($criteria, Context::createDefaultContext())->getEntities();

        $languages = $this->sortLanguages($languages);

        $products = [];
        foreach ($languages as $language) {
            $languageContext = new Context(
                new SystemSource(),
                [],
                Defaults::CURRENCY,
                array_filter([$language->getId()$language->getParentId(), Defaults::LANGUAGE_SYSTEM]),
                
$salesChannelContext,
            new Criteria([$salesChannelContext->getSalesChannel()->getShippingMethodId()])
        )->getShippingMethods()->first();

        if ($defaultShippingMethod !== null && !\in_array($defaultShippingMethod->getName()$blockedShippingMethodNames, true)) {
            return $defaultShippingMethod;
        }

        // Default excluded take next shipping method         $criteria = new Criteria();
        $criteria->addFilter(
            new NandFilter([
                new EqualsAnyFilter('name', $blockedShippingMethodNames),
            ]),
        );

        return $this->shippingMethodRoute->load(
            $request,
            $salesChannelContext,
            $criteria
        )->getShippingMethods()->first();
    }

    
$request,
            $salesChannelContext,
            new Criteria([$salesChannelContext->getSalesChannel()->getPaymentMethodId()])
        )->getPaymentMethods()->first();

        if ($defaultPaymentMethod !== null && !\in_array($defaultPaymentMethod->getName()$blockedPaymentMethodNames, true)) {
            return $defaultPaymentMethod;
        }

        $criteria = new Criteria();
        $criteria->addFilter(
            new NandFilter([
                new EqualsAnyFilter('name', $blockedPaymentMethodNames),
            ])
        );

        return $this->paymentMethodRoute->load(
            $request,
            $salesChannelContext,
            $criteria
        )->getPaymentMethods()->first();
    }

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