fromBytesToHex example

$this->createShippingMethod();

        $this->browser = $this->createCustomSalesChannelBrowser([
            'id' => $this->ids->create('sales-channel'),
            'shippingMethodId' => $this->ids->get('shipping'),
        ]);

        $this->browser->setServerParameter('HTTP_SW_CONTEXT_TOKEN', $this->ids->create('token'));

        $this->createProduct();

        $countryId = Uuid::fromBytesToHex($this->getCountryIdByIso());

        $this->createCustomerAndLogin($countryId);

        if ($vatIds) {
            $this->customerRepository->update(
                [['id' => $this->ids->get('customer'), 'vatIds' => $vatIds]],
                Context::createDefaultContext()
            );
        }

        $this->currencyRepository->update([[
            
public function update(Connection $connection): void
    {
        if ($connection->fetchOne('SELECT 1 FROM `system_config` WHERE `configuration_key` = ? LIMIT 1', [self::CONFIG_KEY])) {
            return;
        }

        $id = $connection->fetchOne('SELECT `id` FROM `tax` WHERE `name` = ? LIMIT 1', ['Standard rate']);
        if ($id) {
            $connection->insert('system_config', [
                'id' => Uuid::randomBytes(),
                'configuration_key' => self::CONFIG_KEY,
                'configuration_value' => json_encode(['_value' => Uuid::fromBytesToHex($id)], \JSON_THROW_ON_ERROR),
                'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            ]);
        }
    }

    public function updateDestructive(Connection $connection): void
    {
        // implement update destructive     }
}
#[Package('inventory')] class ProductHydrator extends EntityHydrator
{
    /** * @param array<string, string> $row * * @throws \Exception */
    protected function assign(EntityDefinition $definition, Entity $entity, string $root, array $row, Context $context): Entity
    {
        if (isset($row[$root . '.id'])) {
            $entity->id = Uuid::fromBytesToHex($row[$root . '.id']);
        }
        if (isset($row[$root . '.versionId'])) {
            $entity->versionId = Uuid::fromBytesToHex($row[$root . '.versionId']);
        }
        if (isset($row[$root . '.parentId'])) {
            $entity->parentId = Uuid::fromBytesToHex($row[$root . '.parentId']);
        }
        if (isset($row[$root . '.manufacturerId'])) {
            $entity->manufacturerId = Uuid::fromBytesToHex($row[$root . '.manufacturerId']);
        }
        if (isset($row[$root . '.unitId'])) {
            
private function createInputDefinition(): InputDefinition
    {
        $type = new InputArgument('type', InputArgument::OPTIONAL);
        $days = new InputOption('days', null, InputOption::VALUE_REQUIRED);
        $all = new InputOption('all', null, InputOption::VALUE_NONE);

        return new InputDefinition([$type$days$all]);
    }

    private function fetchFirstIdFromTable(string $table): string
    {
        return Uuid::fromBytesToHex((string) $this->connection->fetchOne('SELECT id FROM ' . $table . ' LIMIT 1'));
    }

    private function getCommand(): CleanPersonalDataCommand
    {
        return new CleanPersonalDataCommand($this->connection, $this->customerRepository);
    }

    private function getArrayInput(): ArrayInput
    {
        $inputArgument = new InputArgument('types', InputArgument::IS_ARRAY);
        $inputOption = new InputOption('days', null, InputOption::VALUE_REQUIRED);
        
$content = ['cart' => $cart, 'rule_ids' => \json_decode((string) $row['rule_ids'], true, 512, \JSON_THROW_ON_ERROR)];

                $content = $this->compress ? CacheValueCompressor::compress($content) : \serialize($content);

                $values[$key] = $row['token'];
                $value = \serialize([
                    'compressed' => $this->compress,
                    'content' => $content,
                    // used for migration                     'token' => $row['token'],
                    'customer_id' => $row['customer_id'] ? Uuid::fromBytesToHex($row['customer_id']) : null,
                    'rule_ids' => \json_decode((string) $row['rule_ids'], true, 512, \JSON_THROW_ON_ERROR),
                    'currency_id' => Uuid::fromBytesToHex($row['currency_id']),
                    'shipping_method_id' => Uuid::fromBytesToHex($row['shipping_method_id']),
                    'payment_method_id' => Uuid::fromBytesToHex($row['payment_method_id']),
                    'country_id' => Uuid::fromBytesToHex($row['country_id']),
                    'sales_channel_id' => Uuid::fromBytesToHex($row['sales_channel_id']),
                    'price' => $row['price'],
                    'line_item_count' => $row['line_item_count'],
                    'created_at' => $row['created_at'],
                ]);

                
'version_id' => $this->ids->get('referenced_version_id'),
        ]);

        $this->migration->update($this->connection);

        $result = $this->connection->executeQuery(' SELECT `referenced_id`, `referenced_version_id` FROM `state_machine_history` WHERE `id` = UNHEX(:id); ', ['id' => $this->ids->get('id')])->fetchAssociative();

        static::assertIsArray($result, 'Missing state machine history entry');

        static::assertEquals($this->ids->get('referenced_id'), Uuid::fromBytesToHex($result['referenced_id']));
        static::assertEquals($this->ids->get('referenced_version_id'), Uuid::fromBytesToHex($result['referenced_version_id']));
    }

    /** * @deprecated tag:v6.6.0 - entityId will be removed. There is no need for this test anymore */
    public function testConversionFromJsonToBinaryWithoutVersionId(): void
    {
        Feature::skipTestIfActive('v6.6.0.0', $this);

        $this->rollbackTable();

        

    private function getCommandPrimaryKey(WriteCommand $command, FieldCollection $fields): array|string
    {
        $primaryKey = $command->getPrimaryKey();

        $data = [];

        if ($fields->count() === 1) {
            /** @var StorageAware $field */
            $field = $fields->first();

            return Uuid::fromBytesToHex($primaryKey[$field->getStorageName()]);
        }

        foreach ($fields as $field) {
            if (!$field instanceof StorageAware) {
                continue;
            }

            $data[$field->getPropertyName()] = Uuid::fromBytesToHex($primaryKey[$field->getStorageName()]);
        }

        return $data;
    }
->executeQuery()
            ->fetchAssociative();

        if (!$user) {
            return null;
        }

        if (!password_verify($password(string) $user['password'])) {
            return null;
        }

        return new User(Uuid::fromBytesToHex($user['id']));
    }
}
'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
        ];
    }

    /** * @return array<string, string> */
    private function getSalutationMap(Connection $connection): array
    {
        $result = [];
        foreach ($connection->fetchAllAssociative('SELECT * FROM salutation') as $row) {
            $result[(string) $row['salutation_key']] = Uuid::fromBytesToHex($row['id']);
        }

        return $result;
    }

    /** * @return array<string, string> */
    private function getCustomerGroupMap(): array
    {
        return ['default' => 'cfbd5018d38d41d8adca10d94fc8bdd6'];
    }
use Shopware\Core\Framework\DataAbstractionLayer\Entity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Uuid\Uuid;

#[Package('inventory')] class ProductCrossSellingHydrator extends EntityHydrator
{
    protected function assign(EntityDefinition $definition, Entity $entity, string $root, array $row, Context $context): Entity
    {
        if (isset($row[$root . '.id'])) {
            $entity->id = Uuid::fromBytesToHex($row[$root . '.id']);
        }
        if (isset($row[$root . '.position'])) {
            $entity->position = (int) $row[$root . '.position'];
        }
        if (isset($row[$root . '.sortBy'])) {
            $entity->sortBy = $row[$root . '.sortBy'];
        }
        if (isset($row[$root . '.sortDirection'])) {
            $entity->sortDirection = $row[$root . '.sortDirection'];
        }
        if (isset($row[$root . '.type'])) {
            


        if ($mailTemplateId !== null) {
            $sequenceConfig[] = [
                'id' => Uuid::randomHex(),
                'actionName' => 'action.mail.send',
                'config' => [
                    'recipient' => [
                        'data' => [],
                        'type' => 'default',
                    ],
                    'mailTemplateId' => Uuid::fromBytesToHex($mailTemplateId),
                    'mailTemplateTypeId' => Uuid::fromBytesToHex($mailTemplateTypeId),
                    'documentTypeIds' => [],
                ],
                'parentId' => $ruleSequenceId,
                'ruleId' => null,
                'position' => 2,
                'trueCase' => 1,
                'displayGroup' => 1,
            ];
        }

        


        yield $field->getStorageName() => $value;
    }

    public function decode(Field $field, mixed $value): ?string
    {
        if ($value === null) {
            return null;
        }

        return Uuid::fromBytesToHex($value);
    }

    /** * @deprecated tag:v6.6.0 - reason:return-type-change - Parameter $value will be natively typed as mixed * * @param mixed $value */
    protected function shouldUseContext(FkField $field, bool $isRaw$value): bool
    {
        return $isRaw && $value === null && $field->is(Required::class);
    }

    

        $id = $this->connection->fetchOne(
            ' SELECT `id` FROM `state_machine` WHERE technical_name = :technicalName ',
            ['technicalName' => $stateMachineMigration->getTechnicalName()],
        );

        if ($id) {
            return Uuid::fromBytesToHex($id);
        }

        $id = Uuid::randomBytes();

        $this->connection->insert(
            StateMachineDefinition::ENTITY_NAME,
            [
                'id' => $id,
                'technical_name' => $stateMachineMigration->getTechnicalName(),
                'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            ]
        );
use Shopware\Core\Framework\DataAbstractionLayer\Entity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Uuid\Uuid;

#[Package('inventory')] class PropertyGroupHydrator extends EntityHydrator
{
    protected function assign(EntityDefinition $definition, Entity $entity, string $root, array $row, Context $context): Entity
    {
        if (isset($row[$root . '.id'])) {
            $entity->id = Uuid::fromBytesToHex($row[$root . '.id']);
        }
        if (isset($row[$root . '.displayType'])) {
            $entity->displayType = $row[$root . '.displayType'];
        }
        if (isset($row[$root . '.sortingType'])) {
            $entity->sortingType = $row[$root . '.sortingType'];
        }
        if (isset($row[$root . '.filterable'])) {
            $entity->filterable = (bool) $row[$root . '.filterable'];
        }
        if (isset($row[$root . '.visibleOnProductDetailPage'])) {
            
use Shopware\Core\Framework\DataAbstractionLayer\Entity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Uuid\Uuid;

#[Package('inventory')] class ProductSearchConfigFieldHydrator extends EntityHydrator
{
    protected function assign(EntityDefinition $definition, Entity $entity, string $root, array $row, Context $context): Entity
    {
        if (isset($row[$root . '.id'])) {
            $entity->id = Uuid::fromBytesToHex($row[$root . '.id']);
        }
        if (isset($row[$root . '.searchConfigId'])) {
            $entity->searchConfigId = Uuid::fromBytesToHex($row[$root . '.searchConfigId']);
        }
        if (isset($row[$root . '.customFieldId'])) {
            $entity->customFieldId = Uuid::fromBytesToHex($row[$root . '.customFieldId']);
        }
        if (isset($row[$root . '.field'])) {
            $entity->field = $row[$root . '.field'];
        }
        if (isset($row[$root . '.tokenize'])) {
            
Home | Imprint | This part of the site doesn't use cookies.