firstId example

// Change default SalesChannel ShippingMethod to another than the ordered one         $orderShippingMethodId = $orderData[0]['deliveries'][0]['shippingMethodId'];
        $criteria = new Criteria();
        $criteria->setLimit(1);
        $criteria->addFilter(
            new NotFilter(NotFilter::CONNECTION_AND, [
                new EqualsFilter('id', $orderShippingMethodId),
            ]),
            new EqualsFilter('active', true)
        );
        $differentShippingMethodId = $this->getContainer()->get('shipping_method.repository')->searchIds($criteria$context)->firstId();
        static::assertNotNull($differentShippingMethodId);
        static::assertNotSame($orderShippingMethodId$differentShippingMethodId);
        $salesChannelRepository->update([
            [
                'id' => $salesChannel->getId(),
                'shippingMethodId' => $differentShippingMethodId,
                'shippingMethods' => [
                    [
                        'id' => $differentShippingMethodId,
                    ],
                    [
                        
$io->success(sprintf('The password of user "%s" has been changed successfully.', $username));

        return self::SUCCESS;
    }

    private function getUserId(string $username, Context $context): ?string
    {
        $criteria = (new Criteria())
            ->addFilter(new EqualsFilter('username', $username));

        return $this->userRepository->searchIds($criteria$context)->firstId();
    }
}
return null;
        }

        /** @var AdminApiSource $contextSource */
        $contextSource = $context->getSource();

        $criteria = (new Criteria())->addFilter(
            new EqualsFilter('userId', $contextSource->getUserId()),
            new EqualsFilter('key', self::USER_CONFIG_KEY_FRW_USER_TOKEN)
        );

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

    /** * @param array{shopSecret?: string} $accessTokenData * @param array{token: string, expirationDate: string} $userTokenData */
    private function createAccessTokenStruct(array $accessTokenData, array $userTokenData): AccessTokenStruct
    {
        $userToken = new ShopUserTokenStruct(
            $userTokenData['token'],
            new \DateTimeImmutable($userTokenData['expirationDate'])
        );
$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->addAssociation('transactions.stateMachineState');
        
/** @var UserEntity|null $user */
        $user = $this->userRepository->search($criteria$context)->first();

        if ($user === null) {
            return $context;
        }

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('localeId', $user->getLocaleId()));
        $criteria->setLimit(1);
        $languageId = $this->languageRepository->searchIds($criteria$context)->firstId();

        if ($languageId === null) {
            return $context;
        }

        return new Context(
            $context->getSource(),
            $context->getRuleIds(),
            $context->getCurrencyId(),
            [$languageId, Defaults::LANGUAGE_SYSTEM]
        );
    }


    protected function getDefaultProfileId(string $entity): string
    {
        /** @var EntityRepository $profileRepository */
        $profileRepository = $this->getContainer()->get('import_export_profile.repository');
        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('systemDefault', true));
        $criteria->addFilter(new EqualsFilter('sourceEntity', $entity));

        /** @var string $id */
        $id = $profileRepository->searchIds($criteria, Context::createDefaultContext())->firstId();

        return $id;
    }

    protected function cloneDefaultProfile(string $entity): ImportExportProfileEntity
    {
        /** @var EntityRepository $profileRepository */
        $profileRepository = $this->getContainer()->get('import_export_profile.repository');

        $systemDefaultProfileId = $this->getDefaultProfileId($entity);
        $newId = Uuid::randomHex();
        


    private function prepareProductExportForScheduler(bool $active): void
    {
        $this->createProductStream();
        $this->clearProductExports();
        $this->createTestEntity();

        $salesChannelRepository = $this->getContainer()->get('sales_channel.repository');
        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('id', $this->getSalesChannelId()));
        $salesChannelId = $salesChannelRepository->searchIds($criteria$this->context)->firstId();

        $salesChannelRepository->update([
            [
                'id' => $salesChannelId,
                'active' => $active,
            ],
        ]$this->context);
    }

    /** * @return list<object> */
return $snippetSet;
    }

    private function getSnippetSetId(?string $isoCode = 'en-GB'): string|null
    {
        $isoCode = $isoCode ?: 'en-GB';
        $isoCode = str_replace('_', '-', $isoCode);
        $criteria = (new Criteria())
            ->setLimit(1)
            ->addFilter(new EqualsFilter('iso', $isoCode));

        return $this->snippetSetRepository->searchIds($criteria, Context::createDefaultContext())->firstId();
    }
}

        /** @var FlashBag $sessionBag */
        $sessionBag = $this->getSession()->getBag('flashes');

        return $sessionBag;
    }

    private function createProduct(string $productId, string $productNumber, bool $hasChildren = false): void
    {
        $context = Context::createDefaultContext();
        /** @var string $taxId */
        $taxId = $this->getContainer()->get('tax.repository')->searchIds(new Criteria()$context)->firstId();

        $product = [
            'id' => $productId,
            'name' => 'Test product',
            'productNumber' => $productNumber,
            'stock' => 1,
            'price' => [
                ['currencyId' => Defaults::CURRENCY, 'gross' => 15.99, 'net' => 10, 'linked' => false],
            ],
            'taxId' => $taxId,
            'categories' => [
                [
SalesChannelContextService::CUSTOMER_ID => $customerId,
            ]
        );

        $this->documentGenerator = $this->getContainer()->get(DocumentGenerator::class);

        $documentTypeRepository = $this->getContainer()->get('document_type.repository');

        $this->documentTypeId = $documentTypeRepository->searchIds(
            (new Criteria())->addFilter(new EqualsFilter('technicalName', InvoiceRenderer::TYPE)),
            Context::createDefaultContext()
        )->firstId() ?? '';

        $cart = $this->generateDemoCart(2);
        $this->orderId = $this->persistCart($cart);

        $this->documentRepository = $this->getContainer()->get('document.repository');
    }

    public function testCreateDeliveryNotePdf(): void
    {
        $operation = new DocumentGenerateOperation($this->orderId);

        

        );

        $this->documentGenerator = $this->getContainer()->get(DocumentGenerator::class);
        $this->documentRepository = $this->getContainer()->get('document.repository');
        $this->documentMerger = $this->getContainer()->get(DocumentMerger::class);

        $documentTypeRepository = $this->getContainer()->get('document_type.repository');
        $this->documentTypeId = $documentTypeRepository->searchIds(
            (new Criteria())->addFilter(new EqualsFilter('technicalName', InvoiceRenderer::TYPE)),
            Context::createDefaultContext()
        )->firstId() ?? '';

        $cart = $this->generateDemoCart(2);
        $this->orderId = $this->persistCart($cart);
    }

    public function testmergeWithoutDoc(): void
    {
        $mergeResult = $this->documentMerger->merge([Uuid::randomHex()]$this->context);

        static::assertNull($mergeResult);
    }

    
$testApp = $apps->first();

        static::assertNotNull($testApp);

        /** @var ThemeEntity|null $theme */
        $theme = $themeRepo->search(
            (new Criteria())->addFilter(new EqualsFilter('technicalName', 'TestAppTheme')),
            $this->context
        )->first();

        $defaultSalesChannelId = $this->salesChannelRepository->searchIds(new Criteria()$this->context)
            ->firstId();

        static::assertNotNull($theme);
        static::assertNotNull($defaultSalesChannelId);

        $this->salesChannelRepository->update([[
            'id' => $defaultSalesChannelId,
            'themes' => [
                ['id' => $theme->getId()],
            ],
        ]]$this->context);

        
/** @var EntityRepository $languageRepository */
        $languageRepository = $this->getContainer()->get('language.repository');
        $criteria = new Criteria();
        $criteria->addFilter(new NotFilter(
            MultiFilter::CONNECTION_AND,
            [
                new EqualsFilter('id', Defaults::LANGUAGE_SYSTEM),
            ]
        ));
        $criteria->setLimit(1);

        $id = $languageRepository->searchIds($criteria, Context::createDefaultContext())->firstId();
        static::assertIsString($id);

        return $id;
    }

    private function createCustomer(): IdsCollection
    {
        $ids = new IdsCollection();

        $data = [
            'id' => $ids->get('customer'),
            
$this->getContainer()->get('product.repository')->create([
            $product1->build(),
            $product2->build(),
            $product3->build(),
        ]$this->context->getContext());
    }

    private function installApp(string $appDir): string
    {
        $this->loadAppsFromDir($appDir);

        $appId = $this->getContainer()->get('app.repository')->searchIds(new Criteria(), Context::createDefaultContext())->firstId();
        static::assertIsString($appId);

        return $appId;
    }

    private function getExistingTaxId(): string
    {
        /** @var EntityRepository<TaxCollection> $taxRepository */
        $taxRepository = $this->getContainer()->get('tax.repository');

        $criteria = new Criteria();
        
private function getAvailablePaymentMethodId(int $offset = 0): string
    {
        /** @var EntityRepository $repository */
        $repository = $this->getContainer()->get('payment_method.repository');

        $criteria = (new Criteria())
            ->setLimit(1)
            ->setOffset($offset)
            ->addFilter(new EqualsFilter('active', true))
            ->addFilter(new EqualsFilter('availabilityRuleId', null));

        $id = $repository->searchIds($criteria, Context::createDefaultContext())->firstId();
        static::assertNotNull($id);

        return $id;
    }

    private function getTransactions(string $orderId): OrderTransactionCollection
    {
        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('orderId', $orderId));
        $criteria->addSorting(new FieldSorting('createdAt'));

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