compileTheme example

$this->getContainer()->getParameter('kernel.project_dir'),
            $this->getContainer()->get(ScssPhpCompiler::class),
            new MessageBus(),
            0,
            false
        );

        $config = new StorefrontPluginConfiguration('test');
        $config->setAssetPaths(['bla']);

        try {
            $compiler->compileTheme(
                TestDefaults::SALES_CHANNEL,
                'test',
                $config,
                new StorefrontPluginConfigurationCollection(),
                true,
                Context::createDefaultContext()
            );
        } catch (\Throwable $throwable) {
            static::fail('ThemeCompiler->compile() should be executable without a database connection. But following Excpetion was thrown: ' . $throwable->getMessage());
        } finally {
            $this->resetEnvVars();
            
$themeId = Uuid::randomHex();

        $this->themeCompilerMock->expects(static::once())->method('compileTheme')->with(
            TestDefaults::SALES_CHANNEL,
            $themeId,
            static::anything(),
            static::anything(),
            true,
            $this->context
        );

        $this->themeService->compileTheme(TestDefaults::SALES_CHANNEL, $themeId$this->context);
    }

    public function testCompileThemeGivenConf(): void
    {
        $themeId = Uuid::randomHex();

        $confCollection = new StorefrontPluginConfigurationCollection();

        $this->themeCompilerMock->expects(static::once())->method('compileTheme')->with(
            TestDefaults::SALES_CHANNEL,
            $themeId,
            
/** * Only compiles a single theme/saleschannel combination. * Use `compileThemeById` to compile all dependend saleschannels */
    public function compileTheme(
        string $salesChannelId,
        string $themeId,
        Context $context,
        ?StorefrontPluginConfigurationCollection $configurationCollection = null,
        bool $withAssets = true
    ): void {
        $this->themeCompiler->compileTheme(
            $salesChannelId,
            $themeId,
            $this->configLoader->load($themeId$context),
            $configurationCollection ?? $this->extensionRegistry->getConfigurations(),
            $withAssets,
            $context
        );
    }

    /** * Compiles all dependend saleschannel/Theme combinations * * @return array<int, string> */
$config->setAssetPaths(['bla']);

        $pathBuilder = new MD5ThemePathBuilder();
        static::assertEquals('9a11a759d278b4a55cb5e2c3414733c1', $pathBuilder->assemblePath(TestDefaults::SALES_CHANNEL, 'test'));

        try {
            $pathBuilder->getDecorated();
        } catch (DecorationPatternException $e) {
            static::assertInstanceOf(DecorationPatternException::class$e);
        }

        $compiler->compileTheme(
            TestDefaults::SALES_CHANNEL,
            'test',
            $config,
            new StorefrontPluginConfigurationCollection(),
            false,
            Context::createDefaultContext()
        );

        static::assertTrue($fs->has('theme/9a11a759d278b4a55cb5e2c3414733c1'));
    }

    

                'sw-color-brand-primary' => [
                    'value' => '#b1900f',
                ],
            ],
            null,
            $this->context
        );

        $_expectedColor = '#b1900f';
        $_expectedTheme = $childTheme->getId();
        $themeService->compileTheme(TestDefaults::SALES_CHANNEL, $childTheme->getId()$this->context);
        $_expectedColor = '#0b539b';
        $_expectedTheme = $baseTheme->getId();
        $themeService->compileTheme(TestDefaults::SALES_CHANNEL, $baseTheme->getId()$this->context);
    }

    public function testThemeServiceReturnsCorrectConfigAfterEmptyingThemeMedia(): void
    {
        $name = $this->createParentlessSimpleTheme();
        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('name', $name));

        
foreach ($this->themeProvider->load($context$input->getOption('active-only')) as $salesChannelId => $themeId) {
            if ($onlySalesChannel !== null && !\in_array($salesChannelId$onlySalesChannel, true)
                || $skipSalesChannel !== null && \in_array($salesChannelId$skipSalesChannel, true)
                || $onlyThemes !== null && !\in_array($themeId$onlyThemes, true)
                || $skipThemes !== null && \in_array($themeId$skipThemes, true)) {
                continue;
            }

            $this->io->block(\sprintf('Compiling theme for sales channel for : %s', $salesChannelId));

            $start = microtime(true);
            $this->themeService->compileTheme($salesChannelId$themeId$context, null, !$input->getOption('keep-assets'));
            $this->io->note(sprintf('Took %f seconds', microtime(true) - $start));
        }

        return self::SUCCESS;
    }
}
return;
        }

        // Recompile all themes as the extension generally extends the storefront         $mappings = $this->connection->fetchAllAssociative(
            'SELECT LOWER(HEX(sales_channel_id)) as sales_channel_id, LOWER(HEX(theme_id)) as theme_id FROM theme_sales_channel'
        );

        foreach ($mappings as $mapping) {
            $this->themeService->compileTheme(
                $mapping['sales_channel_id'],
                $mapping['theme_id'],
                $context,
                $configurationCollection
            );
        }
    }

    private function getThemeDataByTechnicalName(string $technicalName): ThemeDependencies
    {
        $themeData = $this->connection->fetchAllAssociative(
            
$themeSalesChannels = $theme->getSalesChannels();
        // only run if the themes are not already initialised         if ($themeSalesChannels && $themeSalesChannels->count() > 0) {
            return;
        }

        $salesChannelCriteria = new Criteria();
        $salesChannelCriteria->addFilter(new EqualsFilter('typeId', Defaults::SALES_CHANNEL_TYPE_STOREFRONT));
        $salesChannelIds = $this->salesChannelRepository->search($salesChannelCriteria$context)->getIds();
        foreach ($salesChannelIds as $id) {
            $this->themeService->compileTheme($id$theme->getId()$context);
            $this->themeSalesChannelRepository->upsert([[
                'themeId' => $theme->getId(),
                'salesChannelId' => $id,
            ]]$context);
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.