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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace zenit\PlatformGravitySet1;
  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 zenitPlatformGravitySet1 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.         $this->updateThemeDuplicates();
  24.     }
  25.     private function updateThemeDuplicates(): void
  26.     {
  27.         $this->context Context::createDefaultContext();
  28.         $criteriaTheme = new Criteria();
  29.         $criteriaTheme->addFilter(new EqualsFilter('technicalName''zenitPlatformGravitySet1'));
  30.         /** @var EntityRepository $themeRepo */
  31.         $themeRepo $this->container->get('theme.repository');
  32.         $parentTheme $themeRepo->search($criteriaTheme$this->context)->first();
  33.         if (!$parentTheme) {
  34.             return;
  35.         }
  36.         $criteriaThemeDuplicates = new Criteria();
  37.         $criteriaThemeDuplicates->addFilter(new EqualsFilter('parentThemeId'$parentTheme->get('id')));
  38.         $resultThemeDuplicates $themeRepo->search($criteriaThemeDuplicates$this->context)->getElements();
  39.         if (!$resultThemeDuplicates) {
  40.             return;
  41.         }
  42.         foreach ($resultThemeDuplicates as $themeDuplicate) {
  43.             $data = [
  44.                 'id' => $themeDuplicate->get('id'),
  45.                 'baseConfig' => $parentTheme->get('baseConfig')
  46.             ];
  47.             if (!$themeDuplicate->get('previewMediaId')) {
  48.                 $data['previewMediaId'] = $parentTheme->get('previewMediaId');
  49.             }
  50.             $themeRepo->update([$data], $this->context);
  51.         }
  52.     }
  53. }