# Console theme compile // Nur ein bestimmten Verkaufskanal

**URL:** <https://forum.shopware.com/t/console-theme-compile-nur-ein-bestimmten-verkaufskanal/93309>\
**Category:** Programmierung\
**Created:** [8. März 2022 um 16:13 UTC](https://forum.shopware.com/t/console-theme-compile-nur-ein-bestimmten-verkaufskanal/93309 "2022-03-08T16:13:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![padaja](https://avatars.discourse-cdn.com/v4/letter/p/9fc348/32.png) [@padaja](https://forum.shopware.com/u/padaja)\
**Post date:** [8. März 2022 um 16:13 UTC](https://forum.shopware.com/t/console-theme-compile-nur-ein-bestimmten-verkaufskanal/93309/1 "2022-03-08T16:13:49Z")

</div>

Hallo,

ich habe knapp 70 Verkaufskanäle und möchte mit dem Befehl „bin/console theme:compile“ nur einen bestimmten Verkaufskanal kompilieren und nicht immer alle.

Wie lautet der Befehl dafür? Das müsste ja sowas ähnliches sein: „bin/console theme:compile channelxy“

---

<div class="post-metadata">

**Author:** ![padaja](https://avatars.discourse-cdn.com/v4/letter/p/9fc348/32.png) [@padaja](https://forum.shopware.com/u/padaja)\
**Post date:** [15. März 2022 um 11:28 UTC](https://forum.shopware.com/t/console-theme-compile-nur-ein-bestimmten-verkaufskanal/93309/2 "2022-03-15T11:28:35Z")

</div>

Geht wohl nicht oder?

---

<div class="post-metadata">

**Author:** ![Max\_Shop](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Max\_Shop](https://forum.shopware.com/u/Max_Shop)\
**Post date:** [15. März 2022 um 12:05 UTC](https://forum.shopware.com/t/console-theme-compile-nur-ein-bestimmten-verkaufskanal/93309/3 "2022-03-15T12:05:14Z")

</div>

Einfach folgende Datei anpassen/überschreiben.  
Die foreach-Schleife ist verantwortlich, dass alle aufgerufen werden.

> <https://github.com/shopware/platform/blob/2caef6fc718698787a19862d8ec2e8451522b12c/src/Storefront/Theme/Command/ThemeCompileCommand.php>

---

<div class="post-metadata">

**Author:** ![alexkolb](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@alexkolb](https://forum.shopware.com/u/alexkolb)\
**Post date:** [17. Mai 2023 um 09:20 UTC](https://forum.shopware.com/t/console-theme-compile-nur-ein-bestimmten-verkaufskanal/93309/4 "2023-05-17T09:20:37Z")

</div>

Quick&Dirty:

```auto
class CompileThemeCommand extends Command
{
    protected static $defaultName = 'sales_channel_theme:compile';

    private ThemeService $themeService;
    private AbstractAvailableThemeProvider $themeProvider;

    private EntityRepository $salesChannelRepository;

    public function __construct(ThemeService $themeService, AbstractAvailableThemeProvider $themeProvider, EntityRepository $salesChannelRepository)
    {
        parent::__construct();
        $this->themeService = $themeService;
        $this->themeProvider = $themeProvider;
        $this->salesChannelRepository = $salesChannelRepository;
    }

    // Provides a description, printed out in bin/console
    protected function configure(): void
    {
        $this->setDescription('Compiles theme by sales channel');

        $this->addArgument(
            'salesChannelName',
            InputArgument::IS_ARRAY | InputArgument::REQUIRED,
            'Please specify the name of the sales channel.'
        );

        $this->addOption(
            'keep-assets', 'k', 
            InputOption::VALUE_NONE, 
            'Keep current assets, do not delete them'
        );
    }

    // Actual code executed in the command
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $context = Context::createDefaultContext();

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('name', $input->getArgument('salesChannelName')[0]));
        $salesChannelEntity = $this->salesChannelRepository->search($criteria, $context)->first();

        foreach ($this->themeProvider->load($context) as $salesChannelId => $themeId) {
            if($salesChannelEntity->getId() === $salesChannelId){
                $output->writeln(\sprintf('Compiling theme for sales channel for : %s', $salesChannelId));
                $start = microtime(true);
                $this->themeService->compileTheme($salesChannelId, $themeId, $context, null, !$input->getOption('keep-assets'));
                $output->writeln(sprintf('Took %f seconds', microtime(true) - $start));

                return 1;
            }
        }

        return 0;
    }
}

```

---

<div class="post-metadata">

**Author:** ![shopware28](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@shopware28](https://forum.shopware.com/u/shopware28)\
**Post date:** [6. März 2024 um 11:06 UTC](https://forum.shopware.com/t/console-theme-compile-nur-ein-bestimmten-verkaufskanal/93309/5 "2024-03-06T11:06:37Z")

</div>

Geht auch direkt über die Console:

bin/console theme:compile -o 018adff7ba1c782a931e492ebd70dd63

Parameter ist hier definiert:

> <https://github.com/shopware/shopware/blob/e2fb817705b2eb99fe1e6966f7b84d627ab21027/src/Storefront/Theme/Command/ThemeCompileCommand.php#L17>

Die ID die man angeben muss bekommt man aus dem Backend aus der Adressleiste wenn der Sales-Channel ausgewählt ist für den man ausschließlich kompilieren will.
