custom/static-plugins/CioProductCustomerInputs/src/CioProductCustomerInputs.php line 18

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace CioProductCustomerInputs;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  7. use Shopware\Core\Framework\Plugin;
  8. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  9. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  10. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  11. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  12. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  13. use Shopware\Core\System\CustomField\CustomFieldTypes;
  14. class CioProductCustomerInputs extends Plugin
  15. {
  16.     public const CUSTOMER_INPUT_COUNT 10;
  17.     public const CUSTOMER_INPUT_POSITION_FACTOR 10;
  18.     public function install(InstallContext $installContext): void
  19.     {
  20.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  21.         for ($i 1$i <= CioProductCustomerInputs::CUSTOMER_INPUT_COUNT$i++) {
  22.             $criteria = new Criteria();
  23.             $criteria->addFilter(new EqualsFilter('name''cio_customer_input_' $i));
  24.             $result $customFieldSetRepository->searchIds($criteria$installContext->getContext());
  25.             if (!($result->getTotal() > 0)) {
  26.                 $customFieldSetRepository->create([[
  27.                     'name' => 'cio_customer_input_' $i,
  28.                     'config' => [
  29.                         'label' => [
  30.                             'de-DE' => 'Produkteingabe ' $i,
  31.                             'en-GB' => 'product input ' $i,
  32.                         ],
  33.                     ],
  34.                     'position' => ($i self::CUSTOMER_INPUT_POSITION_FACTOR),
  35.                     'customFields' => [
  36.                         [
  37.                             'name' => 'cio_customer_input_' $i '_active',
  38.                             'type' => CustomFieldTypes::BOOL,
  39.                             'config' => [
  40.                                 'label' => [
  41.                                     'de-DE' => 'Produkteingabe aktivieren',
  42.                                     'en-GB' => 'Activate product input',
  43.                                 ],
  44.                                 'componentName' => 'sw-field',
  45.                                 'customFieldType' => 'checkbox',
  46.                                 'customFieldPosition' => 1,
  47.                                 'type' => 'checkbox',
  48.                             ],
  49.                         ],
  50.                         [
  51.                             'name' => 'cio_customer_input_' $i '_fieldtype',
  52.                             'type' => CustomFieldTypes::SELECT,
  53.                             'config' => [
  54.                                 'label' => [
  55.                                     'de-DE' => 'Feldtyp der Produkteingabe',
  56.                                     'en-GB' => 'type of the field of the product input',
  57.                                 ],
  58.                                 'options' => [
  59.                                     [
  60.                                         'label' => [
  61.                                             'de-DE' => 'einzeiliges Eingabefeld',
  62.                                             'en-GB' => 'single-line input field',
  63.                                         ],
  64.                                         'value' => 'input',
  65.                                     ],
  66.                                     [
  67.                                         'label' => [
  68.                                             'de-DE' => 'einzeiliges Eingabefeld mit Checkbox',
  69.                                             'en-GB' => 'single-line input field with checkbox',
  70.                                         ],
  71.                                         'value' => 'input-checkbox',
  72.                                     ],
  73.                                     [
  74.                                         'label' => [
  75.                                             'de-DE' => 'mehrzeiliges Eingabefeld',
  76.                                             'en-GB' => 'multi-line input field',
  77.                                         ],
  78.                                         'value' => 'textarea',
  79.                                     ],
  80.                                     [
  81.                                         'label' => [
  82.                                             'de-DE' => 'Betrag Eingabefeld',
  83.                                             'en-GB' => 'amount input field',
  84.                                         ],
  85.                                         'value' => 'float',
  86.                                     ],
  87.                                     [
  88.                                         'label' => [
  89.                                             'de-DE' => 'Checkboxfeld',
  90.                                             'en-GB' => 'boolean field',
  91.                                         ],
  92.                                         'value' => 'boolean',
  93.                                     ],
  94.                                     [
  95.                                         'label' => [
  96.                                             'de-DE' => 'Datums- und Uhrzeitfeld',
  97.                                             'en-GB' => 'date and time field',
  98.                                         ],
  99.                                         'value' => 'datetime',
  100.                                     ],
  101.                                     [
  102.                                         'label' => [
  103.                                             'de-DE' => 'Datumsfeld',
  104.                                             'en-GB' => 'date field',
  105.                                         ],
  106.                                         'value' => 'date',
  107.                                     ],
  108.                                     [
  109.                                         'label' => [
  110.                                             'de-DE' => 'Uhrzeitfeld',
  111.                                             'en-GB' => 'time field',
  112.                                         ],
  113.                                         'value' => 'time',
  114.                                     ],
  115.                                     [
  116.                                         'label' => [
  117.                                             'de-DE' => 'Auswahlfeld',
  118.                                             'en-GB' => 'select field',
  119.                                         ],
  120.                                         'value' => 'select',
  121.                                     ],
  122.                                 ],
  123.                                 'componentName' => 'sw-single-select',
  124.                                 'customFieldType' => 'select',
  125.                                 'customFieldPosition' => 2,
  126.                                 'type' => 'select',
  127.                             ],
  128.                         ],
  129.                         [
  130.                             'name' => 'cio_customer_input_' $i '_title',
  131.                             'type' => CustomFieldTypes::TEXT,
  132.                             'config' => [
  133.                                 'label' => [
  134.                                     'de-DE' => 'Beschriftung oberhalb der Produkteingabe',
  135.                                     'en-GB' => 'label above the product input',
  136.                                 ],
  137.                                 'placeholder' => [
  138.                                     'de-DE' => 'Beschriftung oberhalb der Produkteingabe, bspw. "Texteingabe:"',
  139.                                     'en-GB' => 'label above the product input, e.g. "text input:"',
  140.                                 ],
  141.                                 'componentName' => 'sw-field',
  142.                                 'customFieldType' => 'text',
  143.                                 'customFieldPosition' => 3,
  144.                                 'type' => 'text',
  145.                             ],
  146.                         ],
  147.                         [
  148.                             'name' => 'cio_customer_input_' $i '_placeholder',
  149.                             'type' => CustomFieldTypes::TEXT,
  150.                             'config' => [
  151.                                 'label' => [
  152.                                     'de-DE' => 'Platzhalter der Produkteingabe',
  153.                                     'en-GB' => 'placeholder of the product input',
  154.                                 ],
  155.                                 'placeholder' => [
  156.                                     'de-DE' => 'Platzhalter der Produkteingabe, bspw. "Bitte geben Sie einen Wert ein"',
  157.                                     'en-GB' => 'placeholder of the product input, e.g. "please enter a value"',
  158.                                 ],
  159.                                 'componentName' => 'sw-field',
  160.                                 'customFieldType' => 'text',
  161.                                 'customFieldPosition' => 4,
  162.                                 'type' => 'text',
  163.                             ],
  164.                         ],
  165.                         [
  166.                             'name' => 'cio_customer_input_' $i '_required',
  167.                             'type' => CustomFieldTypes::BOOL,
  168.                             'config' => [
  169.                                 'label' => [
  170.                                     'de-DE' => 'Produkteingabe ist ein Pflichtfeld',
  171.                                     'en-GB' => 'product input is a required field',
  172.                                 ],
  173.                                 'componentName' => 'sw-field',
  174.                                 'customFieldType' => 'checkbox',
  175.                                 'customFieldPosition' => 5,
  176.                                 'type' => 'checkbox',
  177.                             ],
  178.                         ],
  179.                         [
  180.                             'name' => 'cio_customer_input_' $i '_price',
  181.                             'type' => CustomFieldTypes::FLOAT,
  182.                             'config' => [
  183.                                 'label' => [
  184.                                     'de-DE' => 'Preis für Veredelung',
  185.                                     'en-GB' => 'price for finishing',
  186.                                 ],
  187.                                 'placeholder' => [
  188.                                     'de-DE' => 'Preis in € bspw. "45.00"',
  189.                                     'en-GB' => 'price in €, e.g. "45.00"',
  190.                                 ],
  191.                                 'componentName' => 'sw-field',
  192.                                 'customFieldType' => 'text',
  193.                                 'customFieldPosition' => 6,
  194.                                 'type' => 'text',
  195.                             ],
  196.                         ],
  197.                         [
  198.                             'name' => 'cio_customer_input_' $i '_startdate',
  199.                             'type' => CustomFieldTypes::TEXT,
  200.                             'config' => [
  201.                                 'label' => [
  202.                                     'de-DE' => 'Startdatum des Datumsfeldes',
  203.                                     'en-GB' => 'start date of the date field',
  204.                                 ],
  205.                                 'placeholder' => [
  206.                                     'de-DE' => '+2 days',
  207.                                     'en-GB' => '+2 days',
  208.                                 ],
  209.                                 'helpText' => [
  210.                                     'de-DE' => 'Folgende Werte werden bspw. ohne eckige Klammern unterstützt: [today] (für heute), [+2 days] (für heute zzgl. eines festgelegten Zeitraums in der Form [+ 1 day], [+1 week], [+1 month] oder [+1 year]) oder [01.01.2021] (für ein festes Datum)',
  211.                                     'en-GB' => 'For example the following values are supported without square brackets: [today] (for today), [+2 days] (for today plus a specified period in the form [+ 1 day], [+1 week], [+1 month] or [+1 year]) or [01.01.2021] (for a fixed date)',
  212.                                 ],
  213.                                 'componentName' => 'sw-field',
  214.                                 'customFieldType' => 'text',
  215.                                 'customFieldPosition' => 7,
  216.                                 'type' => 'text',
  217.                             ],
  218.                         ],
  219.                         [
  220.                             'name' => 'cio_customer_input_' $i '_enddate',
  221.                             'type' => CustomFieldTypes::TEXT,
  222.                             'config' => [
  223.                                 'label' => [
  224.                                     'de-DE' => 'Enddatum des Datumsfeldes',
  225.                                     'en-GB' => 'end date of the date field',
  226.                                 ],
  227.                                 'placeholder' => [
  228.                                     'de-DE' => '+2 days',
  229.                                     'en-GB' => '+2 days',
  230.                                 ],
  231.                                 'helpText' => [
  232.                                     'de-DE' => 'Folgende Werte werden bspw. ohne eckige Klammern unterstützt: [today] (für heute), [+2 days] (für heute zzgl. eines festgelegten Zeitraums in der Form [+ 1 day], [+1 week], [+1 month] oder [+1 year]) oder [31.12.2021] (für ein festes Datum)',
  233.                                     'en-GB' => 'For example the following values are supported without square brackets: [today] (for today), [+2 days] (for today plus a specified period in the form [+ 1 day], [+1 week], [+1 month] or [+1 year]) or [31.12.2021] (for a fixed date)',
  234.                                 ],
  235.                                 'componentName' => 'sw-field',
  236.                                 'customFieldType' => 'text',
  237.                                 'customFieldPosition' => 8,
  238.                                 'type' => 'text',
  239.                             ],
  240.                         ],
  241.                         [
  242.                             'name' => 'cio_customer_input_' $i '_disableddates',
  243.                             'type' => CustomFieldTypes::TEXT,
  244.                             'config' => [
  245.                                 'label' => [
  246.                                     'de-DE' => 'Ausgeschlossene Daten für das Datumsfeld',
  247.                                     'en-GB' => 'excluded dates for the date field',
  248.                                 ],
  249.                                 'placeholder' => [
  250.                                     'de-DE' => '"01.04.2021","01.05.2021"',
  251.                                     'en-GB' => '"01.04.2021","01.05.2021"',
  252.                                 ],
  253.                                 'helpText' => [
  254.                                     'de-DE' => 'Folgende Werte werden bspw. ohne eckige Klammern unterstützt: ["01.01.2021"] (für ein ausgeschlossenes Datum), ["01.04.2021","01.05.2021"] (für mehrere ausgeschlossene Daten) [{"from": "02.04.2021", "to": "05.04.2021"},{"from": "03.05.2021", "to": "09.05.2021"}] (für mehrere Zeiträume) oder eine Kombination daraus',
  255.                                     'en-GB' => 'For example the following values are supported without square brackets: ["01.01.2021"] (for one excluded date), ["01.04.2021", "01.05.2021"] (for several excluded dates) [{"from": "02.04.2021", "to": "05.04.2021"},{"from": "03.05.2021", "to": "09.05.2021"}] (for several periods) or a combination of these',
  256.                                 ],
  257.                                 'componentName' => 'sw-field',
  258.                                 'customFieldType' => 'text',
  259.                                 'customFieldPosition' => 9,
  260.                                 'type' => 'text',
  261.                             ],
  262.                         ],
  263.                         [
  264.                             'name' => 'cio_customer_input_' $i '_starttime',
  265.                             'type' => CustomFieldTypes::TEXT,
  266.                             'config' => [
  267.                                 'label' => [
  268.                                     'de-DE' => 'Startzeit des Uhrzeitfeldes',
  269.                                     'en-GB' => 'start time of the time field',
  270.                                 ],
  271.                                 'placeholder' => [
  272.                                     'de-DE' => '08:00',
  273.                                     'en-GB' => '08:00',
  274.                                 ],
  275.                                 'helpText' => [
  276.                                     'de-DE' => 'Folgender Wert wird ohne eckige Klammern unterstützt: [14:00] (für 14:00 Uhr)',
  277.                                     'en-GB' => 'The following value is supported without square brackets: [14:00] (for 2:00 p.m.)',
  278.                                 ],
  279.                                 'componentName' => 'sw-field',
  280.                                 'customFieldType' => 'text',
  281.                                 'customFieldPosition' => 10,
  282.                                 'type' => 'text',
  283.                             ],
  284.                         ],
  285.                         [
  286.                             'name' => 'cio_customer_input_' $i '_endtime',
  287.                             'type' => CustomFieldTypes::TEXT,
  288.                             'config' => [
  289.                                 'label' => [
  290.                                     'de-DE' => 'Endzeit des Uhrzeitfeldes',
  291.                                     'en-GB' => 'end time of the time field',
  292.                                 ],
  293.                                 'placeholder' => [
  294.                                     'de-DE' => '17:00',
  295.                                     'en-GB' => '17:00',
  296.                                 ],
  297.                                 'helpText' => [
  298.                                     'de-DE' => 'Folgender Wert wird ohne eckige Klammern unterstützt: [20:00] (für 20:00 Uhr)',
  299.                                     'en-GB' => 'The following value is supported without square brackets: [20:00] (for 8:00 p.m.)',
  300.                                 ],
  301.                                 'componentName' => 'sw-field',
  302.                                 'customFieldType' => 'text',
  303.                                 'customFieldPosition' => 11,
  304.                                 'type' => 'text',
  305.                             ],
  306.                         ],
  307.                         [
  308.                             'name' => 'cio_customer_input_' $i '_daterange',
  309.                             'type' => CustomFieldTypes::BOOL,
  310.                             'config' => [
  311.                                 'label' => [
  312.                                     'de-DE' => 'Zeitraumauswahl beim Datumsfeld möglich',
  313.                                     'en-GB' => 'period selection is possible for the date field',
  314.                                 ],
  315.                                 'componentName' => 'sw-field',
  316.                                 'customFieldType' => 'checkbox',
  317.                                 'customFieldPosition' => 12,
  318.                                 'type' => 'checkbox',
  319.                             ],
  320.                         ],
  321.                         [
  322.                             'name' => 'cio_customer_input_' $i '_selectfieldvalues',
  323.                             'type' => CustomFieldTypes::TEXT,
  324.                             'config' => [
  325.                                 'label' => [
  326.                                     'de-DE' => 'Werte für das Auswahlfeld kommasepariert',
  327.                                     'en-GB' => 'Values for the selection field separated by commas',
  328.                                 ],
  329.                                 'placeholder' => [
  330.                                     'de-DE' => 'rot,gelb,blau',
  331.                                     'en-GB' => 'red,yellow,blue',
  332.                                 ],
  333.                                 'helpText' => [
  334.                                     'de-DE' => 'Folgender Wert wird ohne eckige Klammern unterstützt: [rot,gelb,blau]',
  335.                                     'en-GB' => 'The following value is supported without square brackets: [red,yellow,blue]',
  336.                                 ],
  337.                                 'componentName' => 'sw-field',
  338.                                 'customFieldType' => 'text',
  339.                                 'customFieldPosition' => 13,
  340.                                 'type' => 'text',
  341.                             ],
  342.                         ],
  343.                     ],
  344.                     'relations' => [
  345.                         ['entityName' => 'product'],
  346.                     ],
  347.                 ]], $installContext->getContext());
  348.             }
  349.         }
  350.         $criteria = new Criteria();
  351.         $criteria->addFilter(new EqualsFilter('name''cio_customer_input_general'));
  352.         $result $customFieldSetRepository->searchIds($criteria$installContext->getContext());
  353.         if (!($result->getTotal() > 0)) {
  354.             $data = [
  355.                 'name' => 'cio_customer_input_general',
  356.                 'config' => [
  357.                     'label' => [
  358.                         'de-DE' => 'Produkteingabe Allgemein',
  359.                         'en-GB' => 'product input general',
  360.                     ],
  361.                 ],
  362.                 'position' => 100,
  363.                 'customFields' => [
  364.                     [
  365.                         'name' => 'cio_customer_input_general_group',
  366.                         'type' => CustomFieldTypes::SELECT,
  367.                         'config' => [
  368.                             'label' => [
  369.                                 'de-DE' => 'Produkteingabefelder gruppieren',
  370.                                 'en-GB' => 'group product input fields',
  371.                             ],
  372.                             'options' => [],
  373.                             'componentName' => 'sw-multi-select',
  374.                             'customFieldType' => 'select',
  375.                             'customFieldPosition' => 1,
  376.                             'type' => 'select',
  377.                         ],
  378.                     ],
  379.                     [
  380.                         'name' => 'cio_customer_input_count_rows',
  381.                         'type' => CustomFieldTypes::INT,
  382.                         'config' => [
  383.                             'label' => [
  384.                                 'de-DE' => 'Anzahl der Reihen',
  385.                                 'en-GB' => 'row count',
  386.                             ],
  387.                             'componentName' => 'sw-field',
  388.                             'customFieldType' => 'number',
  389.                             'numberType' => 'int',
  390.                             'customFieldPosition' => 2,
  391.                             'type' => 'number',
  392.                             'step' => 1,
  393.                             'min' => 1
  394.                         ],
  395.                     ],
  396.                     [
  397.                         'name' => 'cio_customer_input_row_label_prefix',
  398.                         'type' => CustomFieldTypes::TEXT,
  399.                         'config' => [
  400.                             'label' => [
  401.                                 'de-DE' => 'Reihen Label Prefix',
  402.                                 'en-GB' => 'row label prefix',
  403.                             ],
  404.                             'placeholder' => [
  405.                                 'de-DE' => 'Reihe %index%',
  406.                                 'en-GB' => 'row %index%',
  407.                             ],
  408.                             'componentName' => 'sw-field',
  409.                             'customFieldType' => 'text',
  410.                             'customFieldPosition' => 3,
  411.                             'type' => 'text',
  412.                         ],
  413.                     ],
  414.                 ],
  415.                 'relations' => [
  416.                     ['entityName' => 'product'],
  417.                 ],
  418.             ];
  419.             for ($i 1$i <= CioProductCustomerInputs::CUSTOMER_INPUT_COUNT$i++) {
  420.                 $data['customFields'][0]['config']['options'][] = [
  421.                     'label' => [
  422.                         'de-DE' => 'Produkteingabe ' $i,
  423.                         'en-GB' => 'product input ' $i,
  424.                     ],
  425.                     'value' => 'cio_customer_input_' $i,
  426.                 ];
  427.             }
  428.             $customFieldSetRepository->create([
  429.                 $data
  430.             ], $installContext->getContext());
  431.         }
  432.         parent::install($installContext);
  433.     }
  434.     public function postInstall(InstallContext $installContext): void
  435.     {
  436.         parent::postInstall($installContext);
  437.     }
  438.     public function update(UpdateContext $updateContext): void
  439.     {
  440.     }
  441.     public function postUpdate(UpdateContext $updateContext): void
  442.     {
  443.     }
  444.     public function activate(ActivateContext $activateContext): void
  445.     {
  446.         parent::activate($activateContext);
  447.     }
  448.     public function deactivate(DeactivateContext $deactivateContext): void
  449.     {
  450.         parent::deactivate($deactivateContext);
  451.     }
  452.     public function uninstall(UninstallContext $uninstallContext): void
  453.     {
  454.         if ($uninstallContext->keepUserData()) {
  455.             parent::uninstall($uninstallContext);
  456.             return;
  457.         }
  458.         $customFieldSets = [];
  459.         $customFieldSets[] = 'cio_customer_input_general';
  460.         for ($i 1$i <= CioProductCustomerInputs::CUSTOMER_INPUT_COUNT; ++$i) {
  461.             $customFieldSets[] = 'cio_customer_input_' $i;
  462.         }
  463.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  464.         $criteria = new Criteria();
  465.         $criteria->addFilter(new EqualsAnyFilter('name'$customFieldSets));
  466.         $result $customFieldSetRepository->searchIds($criteria$uninstallContext->getContext());
  467.         foreach ($result->getIds() as $id) {
  468.             $data $result->getDataOfId($id);
  469.             $customFieldSetRepository->delete([$data], $uninstallContext->getContext());
  470.         }
  471.         parent::uninstall($uninstallContext);
  472.     }
  473. }