createSalesChannel example

$this->authorizeSalesChannelBrowser($salesChannelApiBrowser$salesChannelOverride);

        return $salesChannelApiBrowser;
    }

    /** * @param array<mixed> $salesChannelOverride * @param array<mixed> $options */
    public function createSalesChannelContext(array $salesChannelOverride = [], array $options = []): SalesChannelContext
    {
        $salesChannel = $this->createSalesChannel($salesChannelOverride);

        return $this->createContext($salesChannel$options);
    }

    public function login(?KernelBrowser $browser = null): string
    {
        $email = Uuid::randomHex() . '@example.com';
        $customerId = $this->createCustomer($email);

        if (!$browser) {
            $browser = $this->getSalesChannelBrowser();
        }

                'id' => $userConfigId,
                'userId' => $admin->getUserId(),
                'key' => SalesChannelUserConfigSubscriber::CONFIG_KEY,
                'value' => [$salesChannelId1$salesChannelId2],
                'createdAt' => new \DateTime(),
            ],
        ]$context);

        static::assertCount(2, $userConfigRepository->search(new Criteria([$userConfigId])$context)->first()->getValue());

        $this->createSalesChannel(['id' => $salesChannelId1]);
        $this->createSalesChannel(['id' => $salesChannelId2]);

        $salesChannelRepository = $this->getContainer()->get('sales_channel.repository');
        $salesChannelRepository->delete([['id' => $salesChannelId1]['id' => $salesChannelId2]]$context);

        static::assertCount(0, $userConfigRepository->search(new Criteria([$userConfigId])$context)->first()->getValue());
    }
}

    use IntegrationTestBehaviour;
    use SalesChannelApiTestBehaviour;
    use StorefrontControllerTestBehaviour;

    private TestDataCollection $ids;

    protected function setUp(): void
    {
        $this->ids = new TestDataCollection();

        $this->createSalesChannel([
            'id' => $this->ids->create('sales-channel'),
            'domains' => [
                [
                    'languageId' => Defaults::LANGUAGE_SYSTEM,
                    'currencyId' => Defaults::CURRENCY,
                    'snippetSetId' => $this->getSnippetSetIdForLocale('en-GB'),
                    'url' => 'http://test.to',
                ],
            ],
        ]);
    }

    
$themeRepository = $this->getContainer()->get('theme.repository');
        $context = Context::createDefaultContext();
        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('technicalName', 'ThemeWithMultiInheritance'));
        $criteria->addAssociation('parentThemes');
        /** @var ThemeEntity $theme */
        $theme = $themeRepository->search($criteria$context)->first();
    }

    public function testHandleThemeInstallOrUpdateWillRecompileOnlyTouchedTheme(): void
    {
        $salesChannelId = $this->createSalesChannel();
        $themeId = $this->createTheme('SimpleTheme', $salesChannelId);
        $installConfig = $this->configFactory->createFromBundle(new SimpleTheme());
        $installConfig->setStyleFiles(FileCollection::createFromArray(['onlyForFile']));

        $this->themeServiceMock->expects(static::once())
            ->method('compileThemeById')
            ->with(
                $themeId,
                static::isInstanceOf(Context::class),
                static::callback(fn (StorefrontPluginConfigurationCollection $configs): bool => $configs->count() === 2)
            );

        
yield 'With rule b+a' => ['min' => 60, 'max' => 220, 'rules' => ['rule-b', 'rule-a']];
    }

    private function createData(): void
    {
        $secondLanguage = $this->createLanguage();
        $this->ids->set('language-1', $secondLanguage);
        $thirdLanguage = $this->createLanguage($secondLanguage);
        $this->ids->set('language-2', $thirdLanguage);
        $fourthLanguage = $this->createLanguage();
        $this->ids->set('language-3', $fourthLanguage);
        $this->createSalesChannel(['id' => Defaults::SALES_CHANNEL_TYPE_STOREFRONT]);

        $this->getContainer()->get(Connection::class)->executeStatement('DELETE FROM custom_field');

        $customFieldRepository = $this->getContainer()->get('custom_field_set.repository');

        $customFields = [
            [
                'name' => 'a',
                'type' => CustomFieldTypes::TEXT,
            ],
            [
                
protected function setUp(): void
    {
        $this->seoUrlRepository = $this->getContainer()->get('seo_url.repository');
        $this->seoUrlPersister = $this->getContainer()->get(SeoUrlPersister::class);
        $this->categoryRepository = $this->getContainer()->get('category.repository');
        $this->seoUrlGenerator = $this->getContainer()->get(SeoUrlGenerator::class);

        $connection = $this->getContainer()->get(Connection::class);
        $connection->executeStatement('DELETE FROM `sales_channel`');
        $connection->executeStatement('DELETE FROM `seo_url`');

        $id = $this->createSalesChannel()['id'];
        $this->salesChannel = $this->getContainer()->get('sales_channel.repository')->search(new Criteria([$id]), Context::createDefaultContext())->first();
    }

    public function testUpdateSeoUrlsDefault(): void
    {
        $context = Context::createDefaultContext();

        $fk = Uuid::randomHex();
        $seoUrlUpdates = [
            [
                'foreignKey' => $fk,
                

    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $id = $input->getOption('id');
        $typeId = $input->getOption('typeId');

        $io = new ShopwareStyle($input$output);

        try {
            $accessKey = $this->salesChannelCreator->createSalesChannel(
                $id,
                $input->getOption('name') ?? 'Headless',
                $typeId ?? $this->getTypeId(),
                $input->getOption('languageId'),
                $input->getOption('currencyId'),
                $input->getOption('paymentMethodId'),
                $input->getOption('shippingMethodId'),
                $input->getOption('countryId'),
                $input->getOption('customerGroupId'),
                $input->getOption('navigationCategoryId'),
                null,
                
$this->themeRepository = $this->getContainer()->get('theme.repository');
    }

    public function testThemeChangeCommandAllSalesChannels(): void
    {
        $context = Context::createDefaultContext();

        $salesChannels = $this->getSalesChannelData();
        $themes = $this->getThemeData();

        foreach ($salesChannels as $salesChannel) {
            $this->createSalesChannel($salesChannel);
        }

        $this->themeRepository->create($themes$context);

        $this->pluginRegistry = $this->getPluginRegistryMock();
        $salesChannels = $this->salesChannelRepository->search(
            new Criteria(),
            Context::createDefaultContext()
        )->getEntities();

        $arguments = [];

        
$ids = new TestDataCollection();

        $categories = [
            ['id' => $ids->create('root'), 'name' => 'root'],
        ];

        $this->categoryRepository->create($categories, Context::createDefaultContext());

        $urls = $this->getSeoUrls($ids->getList(['root']), null);
        static::assertEmpty($urls);

        $this->createSalesChannel($ids->create('sales-channel')$ids->get('root'));

        $categories = [
            ['id' => $ids->create('a'), 'name' => 'a', 'parentId' => $ids->get('root')],
            ['id' => $ids->create('b'), 'name' => 'b', 'parentId' => $ids->get('a')],
        ];

        $this->categoryRepository->create($categories, Context::createDefaultContext());

        $urls = $this->getSeoUrls($ids->getList(['a', 'b'])$ids->get('sales-channel'));

        static::assertCount(2, $urls);
        


    public function testOnlyIncludesAffectedDeleteRestrictionsWithDirectRelation(): void
    {
        $ids = new IdsCollection();
        $context = Context::createDefaultContext();

        $ruleDefinition = $this->getContainer()->get(RuleDefinition::class);

        $this->createRule($ids);
        $this->createShippingMethod($ids);
        $this->createSalesChannel($ids);

        $deleteIds = [
            'id' => $ids->get('rule'),
        ];

        $affected = $this->getContainer()->get(EntityForeignKeyResolver::class)
            ->getAffectedDeleteRestrictions($ruleDefinition$deleteIds$context, true);

        static::assertCount(1, $affected);
        static::assertArrayHasKey('shipping_method', $affected);
        static::assertContains($ids->get('shipping-method')$affected['shipping_method']);
        
 \JSON_THROW_ON_ERROR) ?: ''
            );

        $response = json_decode((string) $this->browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        static::assertArrayHasKey('technicalName', $response);
        static::assertEquals('cancelled', $response['technicalName']);
    }

    public function testOrderSalesChannelRestriction(): void
    {
        $testChannel = $this->createSalesChannel([
            'domains' => [
                [
                    'languageId' => Defaults::LANGUAGE_SYSTEM,
                    'currencyId' => Defaults::CURRENCY,
                    'snippetSetId' => $this->getSnippetSetIdForLocale('en-GB'),
                    'url' => 'http://foo.de',
                ],
            ],
        ]);

        $orderId = Uuid::randomHex();
        
private EntityRepository $productRepository;

    private TestDataCollection $ids;

    protected function setUp(): void
    {
        $this->productRepository = $this->getContainer()->get('product.repository');
        $this->loader = $this->getContainer()->get(AvailableCombinationLoader::class);
        $this->ids = new TestDataCollection();

        $this->createSalesChannel([
            'id' => $this->ids->get('sales-channel'),
            'domains' => [
                [
                    'languageId' => Defaults::LANGUAGE_SYSTEM,
                    'currencyId' => Defaults::CURRENCY,
                    'snippetSetId' => $this->getSnippetSetIdForLocale('en-GB'),
                    'url' => 'http://test.to',
                ],
            ],
        ]);
    }

    
$this->serializer = new CustomerSerializer(
            $this->customerGroupRepository,
            $this->paymentMethodRepository,
            $this->salesChannelRepository
        );
        $this->serializer->setRegistry($serializerRegistry);
    }

    public function testSimple(): void
    {
        $salesChannel = $this->createSalesChannel();
        $this->createCustomerGroup();
        $this->createPaymentMethod();

        $config = new Config([][][]);
        $customer = [
            'group' => [
                'translations' => [
                    'DEFAULT' => [
                        'name' => 'test customer group',
                    ],
                ],
            ],
'name' => 'Test',
            ],
        ], Context::createDefaultContext());

        $urls = $this->getSeoUrlsById($id);

        static::assertCount(0, $urls);
    }

    public function testUrlsAreWrittenToOnlyAssignedSalesChannel(): void
    {
        $s1 = $this->createSalesChannel()['id'];

        $id = Uuid::randomHex();

        $this->customerGroupRepository->create([
            [
                'id' => $id,
                'name' => 'Test',
                'registrationActive' => true,
                'registrationTitle' => 'test',
                'registrationSalesChannels' => [['id' => $s1]],
            ],
        ],
$this->getContainer()->get(SalesChannelContextFactory::class),
            $this->createMock(EventDispatcher::class)
        );
    }

    public function testSkipNonStorefrontSalesChannels(): void
    {
        $connection = $this->getContainer()->get(Connection::class);
        $connection->executeStatement('DELETE FROM sales_channel');

        $storefrontId = Uuid::randomHex();
        $this->createSalesChannel([
            'id' => $storefrontId,
            'name' => 'storefront',
            'typeId' => Defaults::SALES_CHANNEL_TYPE_STOREFRONT,
            'domains' => [[
                'languageId' => Defaults::LANGUAGE_SYSTEM,
                'currencyId' => Defaults::CURRENCY,
                'snippetSetId' => $this->getSnippetSetIdForLocale('en-GB'),
                'url' => 'http://valid.test',
            ]],
        ]);
        $this->createSalesChannel([
            
Home | Imprint | This part of the site doesn't use cookies.