custom/plugins/theme/src/DonCarneTheme.php line 15

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace DonCarneTheme;
  3. use Shopware\Core\Framework\Plugin;
  4. use Shopware\Storefront\Framework\ThemeInterface;
  5. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  6. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  7. use Shopware\Core\System\CustomField\CustomFieldTypes;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
  10. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  11. class DonCarneTheme extends Plugin implements ThemeInterface
  12. {
  13.     public function install(InstallContext $context): void {
  14.         $customFieldSetRepository $this->container->get("custom_field_set.repository");
  15.         $customFieldSetRepository->create([
  16.             [
  17.                 'name' => 'doncarne_product_custom_fields',
  18.                 'config' => [
  19.                     'label' => [
  20.                         'de-DE' => 'Doncarne Produkt Zusatzfelder',
  21.                         'en-GB' => 'Doncarne Product Custom Fields'
  22.                     ]
  23.                 ],
  24.                 'customFields' => [
  25.                     [
  26.                         'name' => 'doncarne_product_surprise_box',
  27.                         'type' => CustomFieldTypes::SWITCH,
  28.                         'config' => [
  29.                             'label' => [
  30.                                 'en-GB' => 'Surprise Box',
  31.                                 'de-De' => 'Surprise Box'
  32.                             ],
  33.                             'componentName' => 'sw-switch-field',
  34.                             'customFieldType' => 'switch',
  35.                             'translated' => false
  36.                         ]
  37.                     ],
  38.                     [
  39.                         'name' => 'doncarne_product_usps',
  40.                         'type' => CustomFieldTypes::HTML,
  41.                         'config' => [
  42.                             'label' => 'USPs',
  43.                             'componentName' => 'sw-text-editor',
  44.                             'customFieldType' => 'textEditor',
  45.                             'translated' => true
  46.                         ]
  47.                     ],
  48.                     [
  49.                         'name' => 'doncarne_product_delivery_product_state',
  50.                         'type' => CustomFieldTypes::JSON,
  51.                         'config' => [
  52.                             'label' => [
  53.                                 'en-GB' => 'Delivery Type',
  54.                                 'de-De' => 'Lieferart'
  55.                             ],
  56.                             'componentName' => 'sw-multi-select',
  57.                             'customFieldType' => 'select',
  58.                             'customFieldPosition' => 1,
  59.                             'options' => [
  60.                                 [
  61.                                     'value' => 'frozen',
  62.                                     'label' => [
  63.                                         'de-DE' => 'Gefroren',
  64.                                         'en-GB' => 'Frozen'
  65.                                     ]
  66.                                 ],
  67.                                 [
  68.                                     'value' => 'fresh',
  69.                                     'label' => [
  70.                                         'de-DE' => 'Frischware',
  71.                                         'en-GB' => 'Fresh'
  72.                                     ]
  73.                                 ]
  74.                             ]
  75.                         ]
  76.                     ]
  77.                 ],
  78.                 'relations' => [
  79.                     [
  80.                         'entityName' => 'product'
  81.                     ]
  82.                 ]
  83.             ],
  84.             [
  85.                 'name' => 'doncarne_category_custom_fields',
  86.                 'config' => [
  87.                     'label' => [
  88.                         'de-DE' => 'Doncarne Kategorie Zusatzfelder',
  89.                         'en-GB' => 'Doncarne Category Custom Fields'
  90.                     ]
  91.                 ],
  92.                 'customFields' => [
  93.                     [
  94.                         'name' => 'doncarne_category_buy_widget_theme',
  95.                         'type' => CustomFieldTypes::JSON,
  96.                         'config' => [
  97.                             'label' => [
  98.                                 'en-GB' => 'Productdetail buy widget theme',
  99.                                 'de-De' => 'Produktseite Kaufbox Theme'
  100.                             ],
  101.                             'componentName' => 'sw-single-select',
  102.                             'customFieldType' => 'select',
  103.                             'customFieldPosition' => 1,
  104.                             'options' => [
  105.                                 [
  106.                                     'value' => 'light',
  107.                                     'label' => [
  108.                                         'de-DE' => 'Hell',
  109.                                         'en-GB' => 'Light'
  110.                                     ]
  111.                                 ],
  112.                                 [
  113.                                     'value' => 'dark',
  114.                                     'label' => [
  115.                                         'de-DE' => 'Dunkel',
  116.                                         'en-GB' => 'Dark'
  117.                                     ]
  118.                                 ]
  119.                             ]
  120.                         ]
  121.                     ],
  122.                     [
  123.                         'name' => 'doncarne_category_hide_mobile',
  124.                         'type' => CustomFieldTypes::SWITCH,
  125.                         'config' => [
  126.                             'label' => [
  127.                                 'en-GB' => 'Hide in mobile',
  128.                                 'de-De' => 'Mobil ausblenden'
  129.                             ],
  130.                             'componentName' => 'sw-switch-field',
  131.                             'customFieldType' => 'switch',
  132.                             'translated' => false
  133.                         ]
  134.                     ],
  135.                     [
  136.                         'name' => 'doncarne_category_special_menu_display',
  137.                         'type' => CustomFieldTypes::SWITCH,
  138.                         'config' => [
  139.                             'label' => 'Beliebte Themen Menu Look',
  140.                             'componentName' => 'sw-switch-field',
  141.                             'customFieldType' => 'switch',
  142.                             'translated' => false
  143.                         ]
  144.                     ]
  145.                 ],
  146.                 'relations' => [
  147.                     [
  148.                         'entityName' => 'category'
  149.                     ]
  150.                 ]
  151.             ]
  152.         ], $context->getContext());
  153.         // unclear how CustomFieldTypes::ENTITY can be created, doncarne_category_custom_fields_special_menu_extra_categories added via admin
  154.     }
  155.     public function uninstall(UninstallContext $context): void {
  156.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  157.         $criteria = new Criteria();
  158.         $criteria->addFilter(new EqualsAnyFilter('name', ['doncarne_product_custom_fields''doncarne_category_custom_fields']));
  159.         // EntitySearchResult
  160.         $result $customFieldSetRepository->search($criteria$context->getContext());
  161.         foreach ($result->getEntities() as $entity) {
  162.             $customFieldSetRepository->delete([[
  163.                 'id' => $entity->getId()
  164.             ]], $context->getContext());
  165.         }
  166.     }
  167. }