getLocaleId example


                'id' => Uuid::fromHexToBytes($ids->create('secondLocale')),
                'code' => 'fr-te',
                'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            ],
        ];

        $languageData = [
            [
                'id' => Uuid::fromHexToBytes($ids->create('german')),
                'name' => 'test',
                'locale_id' => $this->getLocaleId('de-DE'),
                'translation_code_id' => Uuid::fromHexToBytes($ids->get('firstLocale')),
                'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            ],
            [
                'id' => Uuid::fromHexToBytes($ids->create('en-2')),
                'name' => 'test',
                'locale_id' => $this->getLocaleId('en-GB'),
                'translation_code_id' => Uuid::fromHexToBytes($ids->get('secondLocale')),
                'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            ],
        ];

        

    }

    private function addTaxRuleTypes(Connection $connection): void
    {
        $languageIdEn = $this->getLocaleId($connection, 'en-GB');
        $languageIdDe = $this->getLocaleId($connection, 'de-DE');
        $languageSystem = Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM);

        $dataDe = [
            ZipCodeRuleTypeFilter::TECHNICAL_NAME => [
                'type_name' => 'Postleitzahl',
            ],
            ZipCodeRangeRuleTypeFilter::TECHNICAL_NAME => [
                'type_name' => 'Postleitzahl Bereich',
            ],
            IndividualStatesRuleTypeFilter::TECHNICAL_NAME => [
                
public function filterByParentId(string $id): LanguageCollection
    {
        return $this->filter(fn (LanguageEntity $language) => $language->getParentId() === $id);
    }

    /** * @return list<string> */
    public function getLocaleIds(): array
    {
        return $this->fmap(fn (LanguageEntity $language) => $language->getLocaleId());
    }

    public function filterByLocaleId(string $id): LanguageCollection
    {
        return $this->filter(fn (LanguageEntity $language) => $language->getLocaleId() === $id);
    }

    public function getLocales(): LocaleCollection
    {
        return new LocaleCollection(
            $this->fmap(fn (LanguageEntity $language) => $language->getLocale())
        );
$lastName = $context->getFaker()->format('lastName');
            $title = $this->getRandomTitle();

            $user = [
                'id' => $id,
                'title' => $title,
                'firstName' => $firstName,
                'lastName' => $lastName,
                'username' => $context->getFaker()->format('userName'),
                'email' => $id . $context->getFaker()->format('safeEmail'),
                'password' => 'shopware',
                'localeId' => $this->getLocaleId($context->getContext()),
            ];

            $payload[] = $user;

            if (\count($payload) >= 100) {
                $this->writer->upsert($this->userDefinition, $payload$writeContext);

                $context->getConsole()->progressAdvance(\count($payload));

                $payload = [];
            }
        }
$this->userRepository->update([[
            'id' => $adminUser->getId(),
            'storeToken' => 'store-token',
            'firstName' => 'John',
        ]]$this->defaultContext);

        $this->userRepository->create([[
            'id' => Uuid::randomHex(),
            'firstName' => 'Jane',
            'lastName' => 'Doe',
            'storeToken' => 'store-token-two',
            'localeId' => $adminUser->getLocaleId(),
            'username' => 'admin-two',
            'password' => 's3cr3t12345',
            'email' => 'jane.doe@shopware.com',
        ]]$this->defaultContext);

        $storeController = $this->getStoreController();
        $context = new Context(new AdminApiSource($adminUser->getId()));

        $response = $storeController->checkLogin($context)->getContent();
        static::assertIsString($response);

        
public function __construct(PDO $connection)
    {
        $this->connection = $connection;
    }

    /** * @throws RuntimeException */
    public function createAdmin(AdminUser $user)
    {
        $localeId = $this->getLocaleId($user);

        // Drop previous inserted admins         $this->connection->query('DELETE FROM s_core_auth');

        $sql = <<<'EOT' INSERT INTO s_core_auth (roleID,username,password,encoder,localeID,`name`,email,active,lockeduntil) VALUES (1,?,?,?,?,?,?,1,NOW()); EOT;

        
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
use Shopware\Core\Framework\Log\Package;

/** * @extends EntityCollection<UserEntity> */
#[Package('core')] class UserCollection extends EntityCollection
{
    public function getLocaleIds(): array
    {
        return $this->fmap(fn (UserEntity $user) => $user->getLocaleId());
    }

    public function filterByLocaleId(string $id): self
    {
        return $this->filter(fn (UserEntity $user) => $user->getLocaleId() === $id);
    }

    public function getApiAlias(): string
    {
        return 'user_collection';
    }

    
return $id;
    }

    protected function getLocaleIdOfSystemLanguage(): string
    {
        /** @var EntityRepository $repository */
        $repository = $this->getContainer()->get('language.repository');

        /** @var LanguageEntity $language */
        $language = $repository->search(new Criteria([Defaults::LANGUAGE_SYSTEM]), Context::createDefaultContext())->get(Defaults::LANGUAGE_SYSTEM);

        return $language->getLocaleId();
    }

    protected function getSnippetSetIdForLocale(string $locale): ?string
    {
        /** @var EntityRepository $repository */
        $repository = $this->getContainer()->get('snippet_set.repository');

        $criteria = (new Criteria())
            ->addFilter(new EqualsFilter('iso', $locale))
            ->setLimit(1);

        
        if (!\array_key_exists('en-GB', $snippets) && !empty($snippets)) {
            throw SnippetException::defaultLanguageNotGiven('en-GB');
        }

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsAnyFilter('code', array_keys($snippets)));
        $localeIds = $this->localeRepository->search($criteria$context)->getEntities()->getElements();
        $localeIds = array_column($localeIds, 'id', 'code');

        $existingLocales = [];
        foreach ($existingSnippets as $snippetEntity) {
            $existingLocales[$snippetEntity->getLocaleId()] = $snippetEntity->getId();
        }

        foreach ($snippets as $filename => $value) {
            if (!\array_key_exists($filename$localeIds)) {
                throw LocaleException::localeDoesNotExists($filename);
            }

            $localeId = $localeIds[$filename];
            $id = Uuid::randomHex();

            if (\array_key_exists($localeId$existingLocales)) {
                
$criteria = new Criteria([$source->getUserId()]);

        /** @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(),
            [
$systemConfigService = $this->getContainer()->get(SystemConfigService::class);
        $systemConfigService->set('core.store.shopSecret', 'shop-s3cr3t');

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

        /** @var UserEntity $adminUser */
        $adminUser = $userRepository->search(new Criteria()$context)->first();

        $userRepository->create([
            [
                'localeId' => $adminUser->getLocaleId(),
                'username' => 'admin2',
                'password' => TestDefaults::HASHED_PASSWORD,
                'firstName' => 'admin2',
                'lastName' => 'admin2',
                'email' => 'admin2@shopware.com',
                'storeToken' => null,
            ],
            [
                'localeId' => $adminUser->getLocaleId(),
                'username' => 'admin3',
                'password' => TestDefaults::HASHED_PASSWORD,
                
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
use Shopware\Core\Framework\Log\Package;

/** * @extends EntityCollection<LocaleTranslationEntity> */
#[Package('buyers-experience')] class LocaleTranslationCollection extends EntityCollection
{
    public function getLocaleIds(): array
    {
        return $this->fmap(fn (LocaleTranslationEntity $localeTranslation) => $localeTranslation->getLocaleId());
    }

    public function filterByLocaleId(string $id): self
    {
        return $this->filter(fn (LocaleTranslationEntity $localeTranslation) => $localeTranslation->getLocaleId() === $id);
    }

    public function getLanguageIds(): array
    {
        return $this->fmap(fn (LocaleTranslationEntity $localeTranslation) => $localeTranslation->getLanguageId());
    }

    


        $translations = [];
        foreach ($headers as $header) {
            $pos = strpos($header, 'value-');
            if ($pos === false) {
                continue;
            }
            $row = explode('-', $header);
            $translations[] = [
                'both' => $row[1] . '-' . $row[2],
                'localeID' => $this->getLocaleId($row[1]),
                'shopID' => $row[2],
            ];
        }

        $counter = 0;
        foreach ($snippets as $snippet) {
            foreach ($translations as $translation) {
                if (empty($snippet['value-' . $translation['both']])) {
                    continue;
                }
                $namespace = trim(ltrim($snippet['namespace'], "'"));
                
public function setDefaultLanguage(string $locale): void
    {
        $locale = str_replace('_', '-', $locale);

        $currentLocale = $this->getCurrentSystemLocale();

        if (!$currentLocale) {
            throw new ShopConfigurationException('Default language locale not found');
        }

        $currentLocaleId = $currentLocale['id'];
        $newDefaultLocaleId = $this->getLocaleId($locale);

        // locales match -> do nothing.         if ($currentLocaleId === $newDefaultLocaleId) {
            return;
        }

        $newDefaultLanguageId = $this->getLanguageId($locale);

        if (!$newDefaultLanguageId) {
            $newDefaultLanguageId = $this->createNewLanguageEntry($locale);
        }

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