fromHexToBytes example

static::assertTrue($changeSet->hasChanged('id'));
        static::assertTrue($changeSet->hasChanged('product_number'));
        static::assertTrue($changeSet->hasChanged('price'));

        static::assertNull($changeSet->getAfter('id'));
        static::assertNull($changeSet->getAfter('product_number'));
        static::assertNull($changeSet->getAfter('price'));

        $changeSet = $this->getChangeSet(ProductCategoryDefinition::ENTITY_NAME, $result);

        static::assertTrue($changeSet->hasChanged('product_id'));
        static::assertEquals(Uuid::fromHexToBytes($id)$changeSet->getBefore('product_id'));
        static::assertNull($changeSet->getAfter('product_id'));
    }

    public function testChangeSetWithTranslations(): void
    {
        $id = $this->ids->get('product');

        $update = ['id' => $id, 'name' => 'updated'];

        $this->getContainer()->get('event_dispatcher')
            ->addListener(PreWriteValidationEvent::classfunction DPreWriteValidationEvent $event): void {
                
$versionId ??= $writeContext->getContext()->getVersionId();
        if ($versionId === Defaults::LIVE_VERSION) {
            return;
        }

        $commitId = Uuid::randomBytes();

        $date = (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT);

        $source = $writeContext->getContext()->getSource();
        $userId = $source instanceof AdminApiSource && $source->getUserId()
            ? Uuid::fromHexToBytes($source->getUserId())
            : null;

        $insert = new InsertCommand(
            $this->versionCommitDefinition,
            [
                'id' => $commitId,
                'user_id' => $userId,
                'version_id' => Uuid::fromHexToBytes($versionId),
                'created_at' => $date,
            ],
            ['id' => $commitId],
            

        ];

        $salesChannelRepository->update([$data]$this->salesChannelContext->getContext());
    }

    private function cleanDefaultSalesChannelDomain(): void
    {
        $connection = $this->getContainer()->get(Connection::class);

        $connection->delete(SalesChannelDomainDefinition::ENTITY_NAME, [
            'sales_channel_id' => Uuid::fromHexToBytes(TestDefaults::SALES_CHANNEL),
        ]);
    }
}
$userConfigsGroupByKey = [];

        /** @var UserConfigEntity $userConfig */
        foreach ($userConfigs as $userConfig) {
            $userConfigsGroupByKey[$userConfig->getKey()] = $userConfig->getId();
        }

        $queue = new MultiInsertQueryQueue($this->connection, 250, false, true);
        foreach ($postUpdateConfigs as $key => $value) {
            $data = [
                'value' => Json::encode($value),
                'user_id' => Uuid::fromHexToBytes($userId),
                'key' => $key,
                'id' => Uuid::randomBytes(),
                'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            ];
            if (\array_key_exists($key$userConfigsGroupByKey)) {
                $data['id'] = Uuid::fromHexToBytes($userConfigsGroupByKey[$key]);
            }

            $queue->addInsert(UserConfigDefinition::ENTITY_NAME, $data);
        }

        
/** * Prepare a defined number of test data. */
    protected function prepareImportExportActionControllerTestData(int $num = 1): array
    {
        $data = [];
        for ($i = 1; $i <= $num; ++$i) {
            $uuid = Uuid::randomHex();

            $mimetypes = $this->getValidMimeTypes();

            $data[Uuid::fromHexToBytes($uuid)] = [
                'id' => $uuid,
                'name' => 'Foobar' . $i,
                'label' => 'Foobar' . $i,
                'systemDefault' => ($i % 2 === 0),
                'sourceEntity' => 'product',
                'fileType' => $mimetypes[$i % \count($mimetypes)],
                'delimiter' => ';',
                'enclosure' => '"',
                'createdAt' => date('Y-m-d H:i:s'),
                'mapping' => [
                    [
                        


    /** * Prepare a defined number of test data. */
    protected function prepareImportExportFileTestData(int $num = 1, string $add = ''): array
    {
        $data = [];
        for ($i = 1; $i <= $num; ++$i) {
            $uuid = Uuid::randomHex();

            $data[Uuid::fromHexToBytes($uuid)] = [
                'id' => $uuid,
                'originalName' => sprintf('file%d.xml', $i),
                'path' => sprintf('/test/%d/%s', $i$add),
                'expireDate' => sprintf('2011-01-01T15:03:%02d', $i),
                'size' => $i * 51,
                'accessToken' => Random::getBase64UrlString(32),
            ];
        }

        return $data;
    }

    
$this->connection->executeStatement(
            ' UPDATE `customer` SET `salutation_id` = ( SELECT `id` FROM `salutation` WHERE `salutation_key` = :notSpecified LIMIT 1 ) WHERE `id` = :id AND `salutation_id` is NULL ',
            ['id' => Uuid::fromHexToBytes($id), 'notSpecified' => SalutationDefinition::NOT_SPECIFIED]
        );
    }
}
$query = $this->connection->createQueryBuilder();
        $query->addSelect([
            'seo_path_info',
            'path_info',
        ]);
        $query->from('seo_url');
        $query->andWhere('foreign_key IN (:ids)');
        $query->andWhere('route_name = :routeName');
        $query->andWhere('language_id = :language');
        if ($salesChannelId) {
            $query->andWhere('sales_channel_id = :salesChannel');
            $query->setParameter('salesChannel', Uuid::fromHexToBytes($salesChannelId));
        }

        $query->setParameter('ids', Uuid::fromHexToBytesList(array_values($ids)), ArrayParameterType::STRING);
        $query->setParameter('routeName', NavigationPageSeoUrlRoute::ROUTE_NAME);
        $query->setParameter('language', Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM));

        $urls = $query->executeQuery()->fetchAllAssociative();

        return FetchModeHelper::keyPair($urls);
    }
}
SQL;

        /** @var array<string, array{id: string, quantity: int, referenced_id: string}> $result */
        $result = $this->connection->fetchAllAssociativeIndexed(
            $sql,
            ['ids' => $ids, 'version' => Uuid::fromHexToBytes(Defaults::LIVE_VERSION), 'type' => LineItem::PRODUCT_LINE_ITEM_TYPE, 'cancelled_state' => OrderStates::STATE_CANCELLED],
            ['ids' => ArrayParameterType::STRING]
        );

        return $result;
    }

    /** * @return list<array{id: string, product_id: string, quantity: int}> */
    private function fetchOrderLineItemsForOrder(string $orderId): array
    {
        

        $connection->insert(
            'mail_template_type',
            [
                'id' => $templateTypeId,
                'technical_name' => 'guest_order.double_opt_in',
                'available_entities' => $this->getAvailableEntities(),
                'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            ]
        );

        $defaultLanguageId = Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM);

        $englishLanguageId = $this->fetchLanguageIdByName(self::ENGLISH_LANGUAGE_NAME, $connection);
        $germanLanguageId = $this->fetchLanguageIdByName(self::GERMAN_LANGUAGE_NAME, $connection);

        if (!\in_array($defaultLanguageId[$englishLanguageId$germanLanguageId], true)) {
            $connection->insert(
                'mail_template_type_translation',
                [
                    'mail_template_type_id' => $templateTypeId,
                    'language_id' => $defaultLanguageId,
                    'name' => 'Double opt in guest order',
                    
$token = Uuid::randomHex();

        $context = $this->getContainer()->get(SalesChannelContextFactory::class)->create($token, TestDefaults::SALES_CHANNEL);

        $this->getContainer()->get(Connection::class)->update(
            'customer_recovery',
            [
                'created_at' => (new \DateTime())->sub(new \DateInterval('PT3H'))->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            ],
            [
                'id' => Uuid::fromHexToBytes($this->hashId),
            ]
        );

        $customerRecoveryResponse = $customerRecoveryRoute->load(new RequestDataBag(['hash' => $this->hash])$context);

        static::assertTrue($customerRecoveryResponse->isExpired());
    }
}
$userIds = array_column($users, 'id');
            $files = $this->prepareFiles(2);
            $fileIds = array_column($files, 'id');
            $profiles = $this->prepareProfiles(2);
            $profileIds = array_column($profiles, 'id');
            $activities = ['import', 'export'];
        }

        for ($i = 1; $i <= $num; ++$i) {
            $uuid = Uuid::randomHex();

            $profile = $profiles[Uuid::fromHexToBytes($profileIds[$i % 2])];

            $data[Uuid::fromHexToBytes($uuid)] = [
                'id' => $uuid,
                'activity' => ($activities[$i % 2] ?? '') . $add,
                'state' => sprintf('state %d', $i),
                'userId' => $userIds[$i % 2],
                'profileId' => $profileIds[$i % 2],
                'fileId' => $fileIds[$i % 2],
                'username' => $users[Uuid::fromHexToBytes($userIds[$i % 2])]['username'] . $add,
                'profileName' => $profile['label'] . $add,
                'records' => 10 * $i,
                
return $customerId;
    }

    private function setVatIdOfTheCountryToValidateFormat(): void
    {
        $this->getContainer()->get(Connection::class)
            ->executeStatement(
                'UPDATE `country` SET `check_vat_id_pattern` = 1, `vat_id_pattern` = "(DE)?[0-9]{9}" WHERE id = :id',
                [
                    'id' => Uuid::fromHexToBytes($this->getValidCountryId($this->ids->create('sales-channel'))),
                ]
            );
    }

    private function setVatIdOfTheCountryToBeRequired(): void
    {
        $this->getContainer()->get(Connection::class)
            ->executeStatement(
                'UPDATE `country` SET `vat_id_required` = 1 WHERE id = :id',
                [
                    
private function fetchStoreToken(Context $context): ?string
    {
        $source = $context->getSource();
        static::assertInstanceOf(AdminApiSource::class$source);

        $userId = $source->getUserId();
        static::assertIsString($userId);

        $storeToken = $this->getContainer()->get(Connection::class)->executeQuery(
            'SELECT store_token FROM user WHERE `id` = :userId',
            ['userId' => Uuid::fromHexToBytes($userId)]
        )->fetchOne();

        return $storeToken ?: null;
    }
}


        // returns from all provided cms pages the ones which are default         return array_intersect($cmsPageIds$defaultIds);
    }

    private function cmsPageExists(string $cmsPageId): bool
    {
        $count = $this->connection->fetchOne(
            'SELECT count(*) FROM cms_page WHERE id = :cmsPageId AND version_id = :versionId LIMIT 1;',
            [
                'cmsPageId' => Uuid::fromHexToBytes($cmsPageId),
                'versionId' => Uuid::fromHexToBytes(Defaults::LIVE_VERSION),
            ]
        );

        return $count === '1';
    }
}
Home | Imprint | This part of the site doesn't use cookies.