searchIds example

'acl_role_id' => Uuid::fromHexToBytes($ids->get('acl_role')),
        ]);

        $this->resetBrowser();
        $browser = $this->getBrowser();
        $browser->followRedirects();
        $browser->setServerParameter('HTTP_' . PlatformRequest::HEADER_APP_INTEGRATION_ID, $ids->get('integration'));

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('email', 'admin@example.com'));
        $userRepository = $this->getContainer()->get('user.repository');
        $adminUserId = $userRepository->searchIds($criteria, Context::createDefaultContext())->firstId();
        static::assertNotNull($adminUserId(string) $adminUserId);

        $userRepository->update([
            [
                'id' => $adminUserId,
                'admin' => false,
            ],
        ], Context::createDefaultContext());

        $browser->request('POST', '/api/search/currency', [
            'limit' => 2,
        ]);
$criteria = new Criteria();
        $criteria->addFilter(
            new NotFilter(
                NotFilter::CONNECTION_AND,
                [
                    new EqualsFilter('id', Defaults::LANGUAGE_SYSTEM),
                ]
            )
        );

        $languageId = $languageRepository->searchIds($criteria$this->salesChannelContext->getContext())->firstId();
        static::assertNotNull($languageId);
        $secondDomain = 'http://shopware.second-domain';
        $this->setDomainForSalesChannel($secondDomain$languageId);

        /** @var EventDispatcher $dispatcher */
        $dispatcher = $this->getContainer()->get('event_dispatcher');

        $phpunit = $this;
        $eventDidRun = false;
        $listenerClosure = function DMailSentEvent $event) use (&$eventDidRun$phpunit$firstDomain$secondDomain): void {
            $phpunit->assertStringContainsString($firstDomain$event->getContents()['text/html']);
            

        return $entity === ProductCrossSellingDefinition::ENTITY_NAME;
    }

    private function findAssignedProductsIds(array $assignedProducts): array
    {
        foreach ($assignedProducts as $i => $assignedProduct) {
            $criteria = new Criteria();
            $criteria->addFilter(new EqualsFilter('crossSellingId', $assignedProduct['crossSellingId']));
            $criteria->addFilter(new EqualsFilter('productId', $assignedProduct['productId']));

            $id = $this->assignedProductsRepository->searchIds($criteria, Context::createDefaultContext())->firstId();

            if ($id) {
                $assignedProduct['id'] = $id;
            }

            $assignedProducts[$i] = $assignedProduct;
        }

        return $assignedProducts;
    }
}
$context = Context::createDefaultContext();
        $builder = $this->getContainer()->get(EntityScoreQueryBuilder::class);
        $pattern = $this->getContainer()->get(SearchTermInterpreter::class)->interpret('match');
        $queries = $builder->buildScoreQueries(
            $pattern,
            $this->repository->getDefinition(),
            $this->repository->getDefinition()->getEntityName(),
            $context
        );
        $criteria->addQuery(...$queries);

        $result = $this->repository->searchIds($criteria, Context::createDefaultContext());

        static::assertCount(2, $result->getIds());

        static::assertEquals(
            [$recordA$recordB],
            $result->getIds()
        );

        static::assertGreaterThan(
            $result->getDataFieldOfId($recordB, '_score'),
            $result->getDataFieldOfId($recordA, '_score')
        );
static::assertNotEmpty($foreignKeyInfoUpdated);
        static::assertEquals($foreignKeyInfoUpdated['CONSTRAINT_NAME'], 'fk.document_base_config.logo_id');
        static::assertEquals($foreignKeyInfoUpdated['DELETE_RULE'], 'SET NULL');
    }

    public function testDeleteDocumentBaseConfigLogoShouldNotDeleteDocumentBaseConfig(): void
    {
        $context = Context::createDefaultContext();

        /** @var EntityRepository $documentTypeRepository */
        $documentTypeRepository = $this->getContainer()->get('document_type.repository');
        $documentTypeId = $documentTypeRepository->searchIds(new Criteria()$context)->firstId();
        $documentConfigId = Uuid::randomHex();

        /** @var EntityRepository $documentBaseConfigRepository */
        $documentBaseConfigRepository = $this->getContainer()->get('document_base_config.repository');

        $mediaId = Uuid::randomHex();

        /** @var EntityRepository $mediaRepository */
        $mediaRepository = $this->getContainer()->get('media.repository');

        $mediaRepository->create([
            [
$config = $seoUrlRoute->getConfig();
        $config->setSkipInvalid(false);
        $repository = $this->getRepository($config);

        $criteria = new Criteria();
        if ($previewCriteria !== null) {
            $criteria = $previewCriteria;
        }
        $criteria->setLimit(10);

        $ids = $repository->searchIds($criteria$context)->getIds();

        if (empty($ids)) {
            throw SeoException::noEntitiesForPreview($repository->getDefinition()->getEntityName()$seoUrlTemplate['routeName']);
        }

        $salesChannelId = $seoUrlTemplate['salesChannelId'] ?? null;
        $template = $seoUrlTemplate['template'] ?? '';

        if (\is_string($salesChannelId)) {
            /** @var SalesChannelEntity|null $salesChannel */
            $salesChannel = $this->salesChannelRepository->search((new Criteria([$salesChannelId]))->setLimit(1)$context)->get($salesChannelId);

            
->price(181)
                            ->stock(2)
                            ->build()
                    )
                    ->build(),
            ];

            $this->getContainer()->get('product.repository')
                ->create($products, Context::createDefaultContext());
            $criteria = new Criteria($ids->all());
            $result = $this->getContainer()->get('product.repository')
                ->searchIds($criteria, Context::createDefaultContext());
            static::assertNotNull($result);

            return $ids;
        } catch (\Exception $e) {
            static::tearDown();

            throw $e;
        }
    }

    /** * @depends testIndexing */


        if (\count($ids) === 0) {
            return;
        }

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsAnyFilter('foreignKey', $ids));
        $criteria->addFilter(new EqualsFilter('routeName', self::ROUTE_NAME));

        /** @var array<string> $ids */
        $ids = array_values($this->seoUrlRepository->searchIds($criteria$event->getContext())->getIds());

        if (\count($ids) === 0) {
            return;
        }

        $this->seoUrlRepository->delete(array_map(fn (string $id) => ['id' => $id]$ids)$event->getContext());
    }

    /** * @param list<string> $ids */
    
$this->appRepo = $this->getContainer()->get('app.repository');
        $this->templateStateService = $this->getContainer()->get(TemplateStateService::class);
    }

    public function testActivateApp(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/../../Theme/fixtures/Apps/theme', false);

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('name', 'SwagTheme'));

        $appId = $this->appRepo->searchIds($criteria, Context::createDefaultContext())->firstId();
        static::assertNotNull($appId);

        $this->templateStateService->activateAppTemplates($appId, Context::createDefaultContext());

        $activeTemplates = $this->fetchActiveTemplates($appId);
        static::assertCount(2, $activeTemplates);
    }

    public function testDeactivateApp(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/../../Theme/fixtures/Apps/theme');

        
$orderId = Uuid::randomHex();
        $defaultContext = Context::createDefaultContext();
        $orderData = $this->getOrderData($orderId$defaultContext);

        unset($orderData[0]['orderCustomer']['customer']);

        $this->orderRepository->create($orderData$defaultContext);

        $this->orderRepository->delete([['id' => $orderId]]$defaultContext);

        $criteria = new Criteria([$orderId]);
        $order = $this->orderRepository->searchIds($criteria$defaultContext);

        static::assertEmpty($order->getIds());
    }

    public function testDeleteOrder(): void
    {
        $token = Uuid::randomHex();
        $cart = new Cart($token);

        $id = Uuid::randomHex();

        
private function findVisibilityIds(array $visibilities): array
    {
        foreach ($visibilities as $i => $visibility) {
            if (!isset($visibility['productId'])) {
                continue;
            }

            $criteria = new Criteria();
            $criteria->addFilter(new EqualsFilter('productId', $visibility['productId']));
            $criteria->addFilter(new EqualsFilter('salesChannelId', $visibility['salesChannelId']));

            $id = $this->visibilityRepository->searchIds($criteria, Context::createDefaultContext())->firstId();

            if ($id) {
                $visibility['id'] = $id;
            }

            $visibilities[$i] = $visibility;
        }

        return $visibilities;
    }

    
$criteria = new Criteria();
        $criteria->setLimit(1);

        $context = Context::createDefaultContext();

        $customerId = $this->createCustomer($context);
        $orderId = $this->createOrder($customerId$context);

        $mailTemplateId = $this->getContainer()
            ->get('mail_template.repository')
            ->searchIds($criteria$context)
            ->firstId();

        static::assertNotNull($mailTemplateId);

        $config = array_filter([
            'mailTemplateId' => $mailTemplateId,
            'recipient' => $recipients,
            'documentTypeIds' => $documentTypeIds,
        ]);

        $criteria = new Criteria([$orderId]);
        

        $criteria = new Criteria();
        $criteria->addFilter(
            new MultiFilter(MultiFilter::CONNECTION_AND, [
                new EqualsFilter('email', $email),
                new EqualsFilter('salesChannelId', $context->getSalesChannel()->getId()),
            ]),
        );
        $criteria->setLimit(1);

        return $this->newsletterRecipientRepository
            ->searchIds($criteria$context->getContext())
            ->firstId();
    }

    /** * @return array<string, string> */
    private function getOptionSelection(SalesChannelContext $context): array
    {
        return [
            self::OPTION_DIRECT => $this->isNewsletterDoi($context) ? self::STATUS_NOT_SET : self::STATUS_DIRECT,
            self::OPTION_SUBSCRIBE => $this->isNewsletterDoi($context) ? self::STATUS_NOT_SET : self::STATUS_DIRECT,
            
public function testNotFoundAppThrowsOnDeactivate(): void
    {
        static::expectException(AppNotFoundException::class);
        $this->appStateService->deactivateApp(Uuid::randomHex(), Context::createDefaultContext());
    }

    public function testActivate(): void
    {
        $manifest = Manifest::createFromXmlFile(__DIR__ . '/Manifest/_fixtures/test/manifest.xml');
        $this->appLifecycle->install($manifest, false, $this->context);
        $appId = $this->appRepository->searchIds(new Criteria()$this->context)->firstId();
        static::assertNotNull($appId);
        $this->assertAppState($appId, false);

        $eventWasReceived = false;
        $onAppInstalled = function DAppActivatedEvent $event) use ($appId, &$eventWasReceived): void {
            $eventWasReceived = true;
            static::assertSame($appId$event->getApp()->getId());
        };
        $this->eventDispatcher->addListener(AppActivatedEvent::class$onAppInstalled);
        $this->appStateService->activateApp($appId$this->context);

        
if ($field = $definition->getField($updateByField)) {
            // deserialize for bool, date, int fields...             $updateByValue = $this->fieldSerializer->deserialize($config$field$updateByValue);
        }

        $criteria->addFilter(new EqualsFilter(
            $updateByField,
            $updateByValue
        ));

        $repository = $this->definitionInstanceRegistry->getRepository($definition->getEntityName());
        $id = $repository->searchIds($criteria, Context::createDefaultContext())->firstId();

        if ($id) {
            $record[$primaryKeyProperty] = $id;
        }

        return $record;
    }

    /** * @return mixed|null */
    
Home | Imprint | This part of the site doesn't use cookies.