<?php declare(strict_types=1);
namespace TcinnThemeWareModern;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Shopware\Storefront\Framework\ThemeInterface;
class TcinnThemeWareModern extends Plugin implements ThemeInterface
{
public function getThemeConfigPath(): string
{
return 'theme.json';
}
/**
* Skip rebuild container on activate/deactivate process
* to speedup Shopware Cloud bundle integration.
*
* @return bool
*/
public function rebuildContainer(): bool
{
return false;
}
/**
* Copy base_config from main theme to child themes to
* ensure that child themes get new features from updates.
*
* @param UpdateContext $updateContext
*/
public function postUpdate(UpdateContext $updateContext): void
{
/** @var EntityRepository $themeRepository */
$themeRepository = $this->container->get('theme.repository');
$parentThemeCollection = $themeRepository->search(
(new Criteria())->addFilter(new EqualsFilter('technicalName', 'TcinnThemeWareModern')),
\Shopware\Core\Framework\Context::createDefaultContext()
);
if(!$parentThemeCollection) {
return;
}
$parentTheme = $parentThemeCollection->first();
$childThemesCollection = $themeRepository->search(
(new Criteria())->addFilter(new EqualsFilter('parentThemeId', $parentTheme->get('id'))),
\Shopware\Core\Framework\Context::createDefaultContext()
);
if(!$childThemesCollection) {
return;
}
foreach ($childThemesCollection->getElements() as $childTheme) {
if(!$childTheme->get('previewMediaId')) {
$data = [
[
'id' => $childTheme->get('id'),
'previewMediaId' => $parentTheme->get('previewMediaId'),
'baseConfig' => $parentTheme->get('baseConfig')
]
];
} else {
$data = [
[
'id' => $childTheme->get('id'),
'baseConfig' => $parentTheme->get('baseConfig')
]
];
}
$themeRepository->update($data, \Shopware\Core\Framework\Context::createDefaultContext());
}
}
}