fromStringToHex example

$options[] = [
                    'id' => $optionId,
                    'name' => $option,
                    'group' => [
                        'id' => $groupId,
                        'name' => $group,
                    ],
                ];
            }

            $variantId = Uuid::fromStringToHex(sprintf('%s.%s', $parentId$key));
            $variantProductNumber = sprintf('%s.%s', $productNumber$key);

            $payload[] = [
                'id' => $variantId,
                'parentId' => $parentId,
                'productNumber' => $variantProductNumber,
                'stock' => 0,
                'options' => $options,
            ];
        }

        
static::assertStringContainsString('size: M, L, XL, XXL | oops', $first['_error']);
        $second = $invalid[1];
        static::assertStringContainsString('size: , | color: Green, White, Black, Purple', $second['_error']);
    }

    public function testProductsWithOwnIdentifier(): void
    {
        $context = Context::createDefaultContext();
        $context->addState(EntityIndexerRegistry::DISABLE_INDEXING);

        $productIds = [
            Uuid::fromStringToHex('product1'),
            Uuid::fromStringToHex('product2'),
            Uuid::fromStringToHex('product3'),
            Uuid::fromStringToHex('product4'),
        ];

        /** @var EntityRepository $categoryRepository */
        $categoryRepository = $this->getContainer()->get(CategoryDefinition::ENTITY_NAME . '.repository');
        $category1Id = Uuid::fromStringToHex('category1');
        $category2Id = '0a600a2648b3486fbfdbc60993050103';
        $category3Id = Uuid::fromStringToHex('category3');
        $categoryRepository->upsert([
            [
protected function setUp(): void
    {
        $this->categoryRepository = $this->getContainer()->get('category.repository');
    }

    public static function provideCategoryPaths()
    {
        return [
            '2 Layer assignment' => [
                'categoriesToWrite' => [
                    [
                        'id' => Uuid::fromStringToHex('home'),
                        'name' => 'HomeCategory',
                    ],
                    [
                        'id' => Uuid::fromStringToHex('subCat'),
                        'name' => 'Sub',
                        'parentId' => Uuid::fromStringToHex('home'),
                    ],
                ],

                'record' => [
                    'categories' => [],
                ],

        $id = mb_strtolower(trim((string) $id));

        if ($id === '' || Uuid::isValid($id)) {
            return $id;
        }

        if (str_contains($id, '|')) {
            throw new InvalidIdentifierException($id);
        }

        return Uuid::fromStringToHex($id);
    }
}
string $path,
        bool $forSalesChannel,
        bool $onlyFlat = false,
        string $apiType = DefinitionService::TYPE_JSON_API
    ): array {
        $schema = [];
        $attributes = [];
        $requiredAttributes = [];
        $relationships = [];

        $schemaName = $this->snakeCaseToCamelCase($definition->getEntityName());
        $uuid = Uuid::fromStringToHex($schemaName);
        $exampleDetailPath = $path . '/' . $uuid;

        $extensions = [];
        $extensionRelationships = [];

        foreach ($definition->getFields() as $field) {
            if (!$this->shouldFieldBeIncluded($field$forSalesChannel)) {
                continue;
            }

            if ($field->is(Extension::class)) {
                
break;
                }

                if ($category !== null) {
                    $categoryId = $category->getId();
                    $this->categoryIdCache[$partialPath] = $categoryId;

                    continue;
                }

                $parentId = $categoryId;
                $categoryId = Uuid::fromStringToHex($partialPath);
                $this->categoryIdCache[$partialPath] = $categoryId;

                $newCategoriesPayload[] = [
                    'id' => $categoryId,
                    'parent' => ['id' => $parentId],
                    'name' => $categoryName,
                ];
            }

            if ($categoryId !== null) {
                $result[] = ['id' => $categoryId];
            }
$ruleScope = $this->createRuleScope($currentSalesChannel);

        $salesChannelRule = new SalesChannelRule($operator$salesChannelIds);

        static::assertSame($expected$salesChannelRule->match($ruleScope));
    }

    public static function provideTestData(): \Generator
    {
        yield 'matches with correct sales channel' => [
            Rule::OPERATOR_EQ,
            Uuid::fromStringToHex('test'),
            [Uuid::fromStringToHex('test')],
            true,
        ];

        yield 'matches with wrong sales channel' => [
            Rule::OPERATOR_EQ,
            Uuid::fromStringToHex('test'),
            [Uuid::fromStringToHex('test1')],
            false,
        ];

        
<?php declare(strict_types=1);

use Shopware\Core\Framework\Uuid\Uuid;

if (!function_exists('convertToUuid')) {
    function convertToUuid($name): string
    {
        return Uuid::fromStringToHex($name);
    }
}

$expected = [
    'id' => convertToUuid('product1'),
    'categories' => [
        [
            'id' => convertToUuid('category1'),
        ],
        [
            'id' => convertToUuid('category2'),
        ],
Home | Imprint | This part of the site doesn't use cookies.