getThemeConfiguration example


        }

        return $themeConfig;
    }

    /** * @return array<string, mixed> */
    public function getThemeConfigurationStructuredFields(string $themeId, bool $translate, Context $context): array
    {
        $mergedConfig = $this->getThemeConfiguration($themeId$translate$context)['fields'];

        $translations = [];
        if ($translate) {
            $translations = $this->getTranslations($themeId$context);
            $mergedConfig = $this->translateLabels($mergedConfig$translations);
        }

        $outputStructure = [];

        foreach ($mergedConfig as $fieldName => $fieldConfig) {
            $tab = $this->getTab($fieldConfig);
            

    }

    public function removeUsedMedia(UnusedMediaSearchEvent $event): void
    {
        $context = Context::createDefaultContext();
        /** @var array<string> $allThemeIds */
        $allThemeIds = $this->themeRepository->searchIds(new Criteria()$context)->getIds();

        $mediaIds = [];
        foreach ($allThemeIds as $themeId) {
            $config = $this->themeService->getThemeConfiguration($themeId, false, $context);

            foreach ($config['fields'] ?? [] as $data) {
                if ($data['type'] === 'media' && $data['value'] && Uuid::isValid($data['value'])) {
                    $mediaIds[] = $data['value'];
                }
            }
        }

        $event->markAsUsed(array_unique($mediaIds));
    }
}
protected function tearDown(): void
    {
        if ($this->createdStorefrontTheme !== '') {
            $this->themeRepository->delete([['id' => $this->createdStorefrontTheme]]$this->context);
        }
    }

    public function testDefaultThemeConfig(): void
    {
        /** @var ThemeEntity $theme */
        $theme = $this->themeRepository->search(new Criteria()$this->context)->first();
        $themeConfiguration = $this->themeService->getThemeConfiguration($theme->getId(), false, $this->context);

        $themeConfigFix = ThemeFixtures::getThemeConfig($this->faviconId, $this->demostoreLogoId);
        foreach ($themeConfigFix['fields'] as $key => $field) {
            if ($field['type'] === 'media') {
                $themeConfigFix['fields'][$key]['value'] = $themeConfiguration['fields'][$key]['value'];
            }
        }

        static::assertEquals($themeConfigFix$themeConfiguration);
    }

    

    /** * @internal */
    public function __construct(private readonly ThemeService $themeService)
    {
    }

    #[Route(path: '/api/_action/theme/{themeId}/configuration', name: 'api.action.theme.configuration', methods: ['GET'])]     public function configuration(string $themeId, Context $context): JsonResponse
    {
        $themeConfiguration = $this->themeService->getThemeConfiguration($themeId, true, $context);

        return new JsonResponse($themeConfiguration);
    }

    #[Route(path: '/api/_action/theme/{themeId}', name: 'api.action.theme.update', methods: ['PATCH'])]     public function updateTheme(string $themeId, Request $request, Context $context): JsonResponse
    {
        $config = $request->request->all('config');

        $this->themeService->updateTheme(
            $themeId,
            

                ),
                null,
                new Criteria(),
                $this->context
            )
        );

        static::expectException(InvalidThemeException::class);
        static::expectExceptionMessage('Unable to find the theme "' . $themeId . '"');

        $this->themeService->getThemeConfiguration($themeId, false, $this->context);
    }

    /** * @dataProvider getThemeCollectionForThemeConfiguration * * @param array<string, mixed> $ids * @param array<string, mixed>|null $expected */
    public function testGetThemeConfiguration(array $ids, ThemeCollection $themeCollection, ?array $expected = null): void
    {
        $this->themeRepositoryMock->method('search')->willReturn(
            
private readonly ThemeService $service
    ) {
    }

    public function getDecorated(): AbstractResolvedConfigLoader
    {
        throw new DecorationPatternException(self::class);
    }

    public function load(string $themeId, SalesChannelContext $context): array
    {
        $config = $this->service->getThemeConfiguration($themeId, false, $context->getContext());
        $resolvedConfig = [];
        $mediaItems = [];
        if (!\array_key_exists('fields', $config)) {
            return [];
        }

        foreach ($config['fields'] as $key => $data) {
            if ($data['type'] === 'media' && $data['value'] && Uuid::isValid($data['value'])) {
                $mediaItems[$data['value']][] = $key;
            }
            $resolvedConfig[$key] = $data['value'];
        }
$repository = $this->container->get(\Shopware\Components\Model\ModelManager::class)->getRepository(Shop::class);
        $shops = $repository->getShopsWithThemes()->getResult();
        $compiler = $this->container->get('theme_compiler');
        $rootDir = $this->container->getParameter('shopware.app.rootDir');

        if (!\is_string($rootDir)) {
            throw new RuntimeException('Parameter shopware.app.rootDir has to be an string');
        }

        /** @var Shop $shop */
        foreach ($shops as $shop) {
            $configuration = $compiler->getThemeConfiguration($shop);
            $file = $this->dumpConfiguration($shop$configuration);
            $file = str_replace($rootDir, '', $file);
            $output->writeln('file: ' . $file . ' generated');
        }

        return 0;
    }

    /** * @throws Exception * * @return string */
Home | Imprint | This part of the site doesn't use cookies.