custom/plugins/zenitPlatformStratusSet4/src/zenitPlatformStratusSet4.php line 13

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace zenit\PlatformStratusSet4;
  3. use Shopware\Core\Framework\Context;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  7. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  8. use Shopware\Storefront\Framework\ThemeInterface;
  9. use Shopware\Core\Framework\Plugin;
  10. class zenitPlatformStratusSet4 extends Plugin implements ThemeInterface
  11. {
  12.     /**
  13.      * @var Context
  14.      */
  15.     private $context;
  16.     public function getThemeConfigPath(): string
  17.     {
  18.         return 'theme.json';
  19.     }
  20.     public function postUpdate(UpdateContext $updateContext): void
  21.     {
  22.         parent::postUpdate($updateContext);
  23.         if (version_compare($updateContext->getCurrentShopwareVersion(), '6.4.8.0''<')) {
  24.             $this->updateThemeDuplicates();
  25.         }
  26.     }
  27.     private function updateThemeDuplicates(): void
  28.     {
  29.         $this->context Context::createDefaultContext();
  30.         $criteriaTheme = new Criteria();
  31.         $criteriaTheme->addFilter(new EqualsFilter('technicalName''zenitPlatformStratusSet4'));
  32.         /** @var EntityRepository $themeRepo */
  33.         $themeRepo $this->container->get('theme.repository');
  34.         $parentTheme $themeRepo->search($criteriaTheme$this->context)->first();
  35.         if (!$parentTheme) {
  36.             return;
  37.         }
  38.         $criteriaThemeDuplicates = new Criteria();
  39.         $criteriaThemeDuplicates->addFilter(new EqualsFilter('parentThemeId'$parentTheme->get('id')));
  40.         $resultThemeDuplicates $themeRepo->search($criteriaThemeDuplicates$this->context)->getElements();
  41.         if (!$resultThemeDuplicates) {
  42.             return;
  43.         }
  44.         foreach ($resultThemeDuplicates as $themeDuplicate) {
  45.             $data = [
  46.                 'id' => $themeDuplicate->get('id'),
  47.                 'baseConfig' => $parentTheme->get('baseConfig')
  48.             ];
  49.             if (!$themeDuplicate->get('previewMediaId')) {
  50.                 $data['previewMediaId'] = $parentTheme->get('previewMediaId');
  51.             }
  52.             $themeRepo->update([$data], $this->context);
  53.         }
  54.     }
  55. }