custom/plugins/TcinnThemeWareModern/src/TcinnThemeWareModern.php line 12

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace TcinnThemeWareModern;
  3. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  6. use Shopware\Core\Framework\Plugin;
  7. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  8. use Shopware\Storefront\Framework\ThemeInterface;
  9. class TcinnThemeWareModern extends Plugin implements ThemeInterface
  10. {
  11.     public function getThemeConfigPath(): string
  12.     {
  13.         return 'theme.json';
  14.     }
  15.     /**
  16.      * Skip rebuild container on activate/deactivate process
  17.      * to speedup Shopware Cloud bundle integration.
  18.      *
  19.      * @return bool
  20.      */
  21.     public function rebuildContainer(): bool
  22.     {
  23.         return false;
  24.     }
  25.     /**
  26.      * Copy base_config from main theme to child themes to
  27.      * ensure that child themes get new features from updates.
  28.      *
  29.      * @param UpdateContext $updateContext
  30.      */
  31.     public function postUpdate(UpdateContext $updateContext): void
  32.     {
  33.         /** @var EntityRepository $themeRepository */
  34.         $themeRepository $this->container->get('theme.repository');
  35.         $parentThemeCollection $themeRepository->search(
  36.             (new Criteria())->addFilter(new EqualsFilter('technicalName''TcinnThemeWareModern')),
  37.             \Shopware\Core\Framework\Context::createDefaultContext()
  38.         );
  39.         if(!$parentThemeCollection) {
  40.             return;
  41.         }
  42.         $parentTheme $parentThemeCollection->first();
  43.         $childThemesCollection $themeRepository->search(
  44.             (new Criteria())->addFilter(new EqualsFilter('parentThemeId'$parentTheme->get('id'))),
  45.             \Shopware\Core\Framework\Context::createDefaultContext()
  46.         );
  47.         if(!$childThemesCollection) {
  48.             return;
  49.         }
  50.         foreach ($childThemesCollection->getElements() as $childTheme) {
  51.             if(!$childTheme->get('previewMediaId')) {
  52.                 $data = [
  53.                     [
  54.                         'id' => $childTheme->get('id'),
  55.                         'previewMediaId' => $parentTheme->get('previewMediaId'),
  56.                         'baseConfig' => $parentTheme->get('baseConfig')
  57.                     ]
  58.                 ];
  59.             } else {
  60.                 $data = [
  61.                     [
  62.                         'id' => $childTheme->get('id'),
  63.                         'baseConfig' => $parentTheme->get('baseConfig')
  64.                     ]
  65.                 ];
  66.             }
  67.             $themeRepository->update($data, \Shopware\Core\Framework\Context::createDefaultContext());
  68.         }
  69.     }
  70. }