custom/plugins/CogiCapskeeper/src/CogiThemeCapskeeper.php line 18

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Cogi\Theme\Capskeeper;
  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;
  8. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  9. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  10. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  11. use Shopware\Core\System\CustomField\Aggregate\CustomFieldSet\CustomFieldSetEntity;
  12. use Shopware\Core\System\CustomField\CustomFieldTypes;
  13. use Shopware\Storefront\Framework\ThemeInterface;
  14. class CogiThemeCapskeeper extends Plugin implements ThemeInterface
  15. {
  16.     public function getThemeConfigPath(): string
  17.     {
  18.         return 'theme.json';
  19.     }
  20.     /**
  21.      * @param InstallContext $installContext
  22.      */
  23.     public function install(InstallContext $installContext): void
  24.     {
  25.         parent::install($installContext);
  26.         $this->createCustomFieldSets();
  27.     }
  28.     /**
  29.      * @param UpdateContext $updateContext
  30.      */
  31.     public function update(UpdateContext $updateContext): void
  32.     {
  33.         parent::update($updateContext);
  34.         $this->createCustomFieldSets();
  35.     }
  36.     /**
  37.      * @param UninstallContext $uninstallContext
  38.      */
  39.     public function uninstall(UninstallContext $uninstallContext): void
  40.     {
  41.         /** @var EntityRepository $customFieldSetRepository */
  42.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  43.         $criteria = new Criteria();
  44.         $criteria->addFilter(new EqualsFilter('name''custom_cogi'));
  45.         /** @var CustomFieldSetEntity $customFieldSetEntity */
  46.         $customFieldSetEntity $customFieldSetRepository->search($criteria$uninstallContext->getContext())->first();
  47.         if (isset($customFieldSetEntity)) {
  48.             $customFieldSetRepository->delete([['id' => $customFieldSetEntity->getId()]], $uninstallContext->getContext());
  49.         }
  50.         parent::uninstall($uninstallContext);
  51.     }
  52.     private function createCustomFieldSets(): void {
  53.         /** @var EntityRepository $customFieldSetRepository */
  54.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  55.         try {
  56.             $customFieldSetRepository->create([
  57.                 [
  58.                     'name' => 'custom_cogi',
  59.                     'config' => [
  60.                         'label' => [
  61.                             'de-DE' => 'Zusätzliche Felder Theme',
  62.                             'en-GB' => 'Additional field Theme'
  63.                         ]
  64.                     ],
  65.                     'relations' => array_map(function ($entity) {
  66.                         return ['entityName' => $entity];
  67.                     }, ['product']),
  68.                     'customFields' => [
  69.                         [
  70.                             'name' => 'custom_cogi_description_top',
  71.                             'type' => CustomFieldTypes::HTML,
  72.                             'config' => [
  73.                                 'componentName' => 'sw-text-editor',
  74.                                 'customFieldType' => CustomFieldTypes::HTML,
  75.                                 'customFieldPosition' => 1,
  76.                                 'label' => [
  77.                                     'en-GB' => 'Zusätzliche Produktbeschreibung oben',
  78.                                     'de-DE' => 'Additional Productdescription top'
  79.                                 ],
  80.                                 'translated' => true
  81.                             ]
  82.                         ],
  83.                         [
  84.                             'name' => 'custom_cogi_description_bottom',
  85.                             'type' => CustomFieldTypes::HTML,
  86.                             'config' => [
  87.                                 'componentName' => 'sw-text-editor',
  88.                                 'customFieldType' => CustomFieldTypes::HTML,
  89.                                 'customFieldPosition' => 1,
  90.                                 'label' => [
  91.                                     'en-GB' => 'Zusätzliche Produktbeschreibung unten',
  92.                                     'de-DE' => 'Additional Productdescription bottom'
  93.                                 ],
  94.                                 'translated' => true
  95.                             ]
  96.                         ],
  97.                         [
  98.                             'name' => 'custom_cogi_delivery',
  99.                             'type' => CustomFieldTypes::HTML,
  100.                             'config' => [
  101.                                 'componentName' => 'sw-text-editor',
  102.                                 'customFieldType' => CustomFieldTypes::HTML,
  103.                                 'customFieldPosition' => 1,
  104.                                 'label' => [
  105.                                     'en-GB' => 'Zusätzliche Versandinformationen',
  106.                                     'de-DE' => 'Additional shipping information'
  107.                                 ],
  108.                                 'translated' => true
  109.                             ]
  110.                         ],
  111.                         [
  112.                             'name' => 'custom_cogi_product_listing_description',
  113.                             'type' => CustomFieldTypes::HTML,
  114.                             'config' => [
  115.                                 'componentName' => 'sw-text-editor',
  116.                                 'customFieldType' => CustomFieldTypes::HTML,
  117.                                 'customFieldPosition' => 1,
  118.                                 'label' => [
  119.                                     'en-GB' => 'Description for listing',
  120.                                     'de-DE' => 'Beschreibung, welche im listing angezeigt wird'
  121.                                 ],
  122.                                 'translated' => true
  123.                             ]
  124.                         ],
  125.                     ]
  126.                 ]
  127.             ], Context::createDefaultContext());
  128.         } catch (\Exception $e) {
  129.         }
  130.     }
  131. }