custom/plugins/GrimmTheme/src/GrimmTheme.php line 17

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace GrimmTheme;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Storefront\Framework\ThemeInterface;
  6. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  7. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  8. use Shopware\Core\System\CustomField\CustomFieldTypes;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  10. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
  11. class GrimmTheme extends Plugin implements ThemeInterface
  12. {
  13.     public const FIELDSETNAME 'grimm_customFields';
  14.     public const FIELDSETLABEL 'GRIMM Custom Fields';
  15.     public const ACCOUNT_TYPE_INSTITUTION "institution";
  16.     public function getThemeConfigPath(): string
  17.     {
  18.         return 'theme.json';
  19.     }
  20.     public function install(InstallContext $context): void
  21.     {
  22.         // Grimm fields
  23.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  24.         $customFieldSetRepository->create([[
  25.             'name' => self::FIELDSETNAME,
  26.             'config' => [
  27.                 'label' => self::FIELDSETLABEL
  28.             ],
  29.             'customFields' => [
  30.                 [
  31.                     'name' => 'grimm_customFields_short_desc',
  32.                     'type' => CustomFieldTypes::TEXT,
  33.                     'config' => [
  34.                         'label' => 'Produkt Kurzbeschreibung',
  35.                         'componentName' => 'sw-text-field',
  36.                         'customFieldType' => 'text',
  37.                         'translated' => false
  38.                     ]
  39.                 ],
  40.                 [
  41.                     'name' => 'grimm_customFields_uvp',
  42.                     'type' => CustomFieldTypes::FLOAT,
  43.                     'config' => [
  44.                         'label' => 'UVP',
  45.                         'componentName' => 'sw-number-field',
  46.                         'customFieldType' => 'number',
  47.                         'translated' => false,
  48.                         'numberType' => 'float'
  49.                     ]
  50.                 ],
  51.                 [
  52.                     'name' => 'grimm_customFields_guarantee',
  53.                     'type' => CustomFieldTypes::TEXT,
  54.                     'config' => [
  55.                         'label' => 'Garantie',
  56.                         'componentName' => 'sw-text-field',
  57.                         'customFieldType' => 'text',
  58.                         'translated' => false
  59.                     ]
  60.                 ],
  61.                 [
  62.                     'name' => 'grimm_customFields_replacement',
  63.                     'type' => CustomFieldTypes::BOOL,
  64.                     'config' => [
  65.                         'label' => 'Ersatzteile',
  66.                         'componentName' => 'sw-checkbox-field',
  67.                         'customFieldType' => 'checkbox',
  68.                         'translated' => false
  69.                     ]
  70.                 ],
  71.                 [
  72.                     'name' => 'grimm_customfields_productRequest_only',
  73.                     'type' => CustomFieldTypes::BOOL,
  74.                     'config' => [
  75.                         'label' => 'Auf Anfrage',
  76.                         'componentName' => 'sw-checkbox-field',
  77.                         'customFieldType' => 'checkbox',
  78.                         'translated' => false
  79.                         ]
  80.                 ],
  81.                 [
  82.                     'name' => 'grimm_customfields_productRequest_showUVP',
  83.                     'type' => CustomFieldTypes::BOOL,
  84.                     'config' => [
  85.                         'label' => 'UVP anzeigen wenn auf Anfrage',
  86.                         'componentName' => 'sw-checkbox-field',
  87.                         'customFieldType' => 'checkbox',
  88.                         'translated' => false
  89.                         ]
  90.                 ],
  91.                 [
  92.                     'name' => 'grimm_customFields_additionalDeliveryInfo',
  93.                     'type' => CustomFieldTypes::HTML,
  94.                     'config' => [
  95.                         'label' => 'Zusatzinfo Lieferung',
  96.                         'componentName' => 'sw-text-editor',
  97.                         'customFieldType' => 'textEditor',
  98.                         'translated' => false
  99.                     ]
  100.                 ]
  101.                     
  102.             ],
  103.             'relations' => [
  104.                 [
  105.                     'entityName' => 'product'
  106.                 ]
  107.             ]
  108.         ]], $context->getContext());
  109.         // downloads
  110.         $customFieldSetRepository->create([
  111.             [
  112.                 'name' => 'custom_product_downloads',
  113.                 'config' => [
  114.                     'label' => [
  115.                         'en-GB' => 'Downloads',
  116.                         'de-DE' => 'Downloads'
  117.                     ]
  118.                 ],
  119.                 'customFields' => [
  120.                     [
  121.                         'name' => 'custom_product_downloads_name1',
  122.                         'type' => CustomFieldTypes::TEXT,
  123.                         'config' => [
  124.                             'label' => '1. Download Name',
  125.                             'translated' => false,
  126.                             'customFieldPosition' => 1
  127.                         ],
  128.                     ],
  129.                     [
  130.                         'name' => 'custom_product_downloads_media1',
  131.                         'type' => CustomFieldTypes::MEDIA,
  132.                         'config' => [
  133.                             'label' => '1. Download Media',
  134.                             'componentName' => 'sw-media-field',
  135.                             'customFieldType' => 'media',
  136.                             'translated' => false,
  137.                             'customFieldPosition' => 2
  138.                         ]
  139.                     ],
  140.                     [
  141.                         'name' => 'custom_product_downloads_name2',
  142.                         'type' => CustomFieldTypes::TEXT,
  143.                         'config' => [
  144.                             'label' => '2. Download Name',
  145.                             'translated' => false,
  146.                             'customFieldPosition' => 3
  147.                         ],
  148.                     ],
  149.                     [
  150.                         'name' => 'custom_product_downloads_media2',
  151.                         'type' => CustomFieldTypes::MEDIA,
  152.                         'config' => [
  153.                             'label' => '2. Download Media',
  154.                             'componentName' => 'sw-media-field',
  155.                             'customFieldType' => 'media',
  156.                             'translated' => false,
  157.                             'customFieldPosition' => 4
  158.                         ]
  159.                     ],
  160.                     [
  161.                         'name' => 'custom_product_downloads_name3',
  162.                         'type' => CustomFieldTypes::TEXT,
  163.                         'config' => [
  164.                             'label' => '3. Download Name',
  165.                             'translated' => false,
  166.                             'customFieldPosition' => 5
  167.                         ],
  168.                     ],
  169.                     [
  170.                         'name' => 'custom_product_downloads_media3',
  171.                         'type' => CustomFieldTypes::MEDIA,
  172.                         'config' => [
  173.                             'label' => '3. Download Media',
  174.                             'componentName' => 'sw-media-field',
  175.                             'customFieldType' => 'media',
  176.                             'translated' => false,
  177.                             'customFieldPosition' => 6
  178.                         ]
  179.                     ],
  180.                     [
  181.                         'name' => 'custom_product_downloads_name4',
  182.                         'type' => CustomFieldTypes::TEXT,
  183.                         'config' => [
  184.                             'label' => '4. Download Name',
  185.                             'translated' => false,
  186.                             'customFieldPosition' => 7
  187.                         ],
  188.                     ],
  189.                     [
  190.                         'name' => 'custom_product_downloads_media4',
  191.                         'type' => CustomFieldTypes::MEDIA,
  192.                         'config' => [
  193.                             'label' => '4. Download Media',
  194.                             'componentName' => 'sw-media-field',
  195.                             'customFieldType' => 'media',
  196.                             'translated' => false,
  197.                             'customFieldPosition' => 8
  198.                         ]
  199.                     ],
  200.                     [
  201.                         'name' => 'custom_product_downloads_name5',
  202.                         'type' => CustomFieldTypes::TEXT,
  203.                         'config' => [
  204.                             'label' => '5. Download Name',
  205.                             'translated' => false,
  206.                             'customFieldPosition' => 9
  207.                         ],
  208.                     ]
  209.                 ],
  210.                 'relations' => [
  211.                     [
  212.                         'entityName' => 'product'
  213.                     ]
  214.                 ]
  215.             ]
  216.         ], $context->getContext());
  217.         
  218.         // newsletter
  219.         $customFieldSetRepository->create([
  220.             [
  221.                 'name' => 'custom_category_newsletter',
  222.                 'config' => [
  223.                     'label' => [
  224.                         'en-GB' => 'Newsletter Column',
  225.                         'de-DE' => 'Newsletter Spalte'
  226.                     ]
  227.                 ],
  228.                 'customFields' => [
  229.                     [
  230.                         'name' => 'custom_category_newsletter_column',
  231.                         'type' => CustomFieldTypes::HTML,
  232.                         'config' => [
  233.                             'label' => 'Newsletter Editor (ONLY EDIT AS HTML)',
  234.                             'componentName' => 'sw-text-editor',
  235.                             'customFieldType' => 'textEditor',
  236.                             'translated' => false
  237.                         ]
  238.                     ]
  239.                 ],
  240.                 'relations' => [
  241.                     [
  242.                         'entityName' => 'category'
  243.                     ]
  244.                 ]
  245.             ]
  246.         ], $context->getContext());
  247.         
  248.         // clerk
  249.         $customFieldSetRepository->create([
  250.             [
  251.                 'name' => 'custom_clerk',
  252.                 'config' => [
  253.                     'label' => [
  254.                         'en-GB' => 'Clerk',
  255.                         'de-DE' => 'Clerk'
  256.                     ]
  257.                 ],
  258.                 'customFields' => [
  259.                     [
  260.                         'name' => 'custom_clerk_net_price',
  261.                         'type' => CustomFieldTypes::FLOAT,
  262.                         'config' => [
  263.                             'label' => 'Nettopreis',
  264.                             'componentName' => 'sw-number-field',
  265.                             'customFieldType' => 'number',
  266.                             'translated' => false,
  267.                             'numberType' => 'float'
  268.                         ]
  269.                         ],
  270.                         [
  271.                             'name' => 'custom_clerk_vat',
  272.                             'type' => CustomFieldTypes::FLOAT,
  273.                             'config' => [
  274.                                 'label' => 'Steuersatz',
  275.                                 'componentName' => 'sw-number-field',
  276.                                 'customFieldType' => 'number',
  277.                                 'translated' => false,
  278.                                 'numberType' => 'float'
  279.                             ]
  280.                         ],
  281.                         [
  282.                             'name' => 'custom_clerk_shipping_time',
  283.                             'type' => CustomFieldTypes::TEXT,
  284.                             'config' => [
  285.                                 'label' => 'Lieferzeit',
  286.                                 'translated' => false
  287.                             ]
  288.                         ]
  289.                 ],
  290.                 'relations' => [
  291.                     [
  292.                         'entityName' => 'product'
  293.                     ]
  294.                 ]
  295.             ]
  296.         ], $context->getContext());
  297.         // one field here was manually created by clients themselves within shop - wont be available on newinstalled theme
  298.         $customFieldSetRepository->create([
  299.             [
  300.                 'name' => 'custom_payment',
  301.                 'config' => [
  302.                     'label' => [
  303.                         'en-GB' => 'Extended Data for Payment methods',
  304.                         'de-DE' => 'Erweiterte Daten für Zahlungsarten'
  305.                     ]
  306.                 ],
  307.                 'customFields' => [
  308.                     [
  309.                         'name' => 'custom_payment_active_payment_method',
  310.                         'type' => CustomFieldTypes::HTML,
  311.                         'config' => [
  312.                             'label' => 'Aktive Methode Beschreibung',
  313.                             'componentName' => 'sw-text-editor',
  314.                             'customFieldType' => 'textEditor',
  315.                             'translated' => false
  316.                         ]
  317.                     ],
  318.                     [
  319.                         'name' => 'custom_payment_description',
  320.                         'type' => CustomFieldTypes::HTML,
  321.                         'config' => [
  322.                             'label' => 'Beschreibung',
  323.                             'componentName' => 'sw-text-editor',
  324.                             'customFieldType' => 'textEditor',
  325.                             'translated' => false
  326.                         ]
  327.                     ]
  328.                 ],
  329.                 'relations' => [
  330.                     [
  331.                         'entityName' => 'payment_method'
  332.                     ]
  333.                 ]
  334.             ]
  335.         ], $context->getContext());
  336.     }
  337.     public function uninstall(UninstallContext $context): void
  338.     {
  339.         if ($context->keepUserData()) {
  340.             return;
  341.         }
  342.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  343.         $criteria = new Criteria();
  344.         $criteria->addFilter(new EqualsAnyFilter('name', [self::FIELDSETNAME'custom_product_downloads''custom_category_newsletter''custom_clerk''custom_payment']));
  345.         // EntitySearchResult
  346.         $result $customFieldSetRepository->search($criteria$context->getContext());
  347.         foreach ($result->getEntities() as $entity) {
  348.             $customFieldSetRepository->delete([[
  349.                 'id' => $entity->getId()
  350.             ]], $context->getContext());
  351.         }
  352.     }
  353. }