custom/plugins/digi1Custombutton/src/digi1Custombutton.php line 16

Open in your IDE?
  1. <?php declare(strict_types=1);
  2.     namespace digi1\digi1Custombutton;
  3.     use Shopware\Core\Framework\Plugin;
  4.     use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  5.     use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  6.     use Shopware\Core\Framework\Plugin\Context\InstallContext;
  7.     use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  8.     use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  9.     use Shopware\Core\System\CustomField\CustomFieldTypes;
  10.     use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  11.     use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  12.     class digi1Custombutton extends Plugin {
  13.         public function install(InstallContext $installContext): void {
  14.             $customFieldSetRepository $this->container->get('custom_field_set.repository');
  15.             $criteriaButton = new Criteria();
  16.             $criteriaButton->addFilter(new EqualsFilter('name''digi1_custombuttons'));
  17.             $resultButton $customFieldSetRepository->searchIds($criteriaButton$installContext->getContext());
  18.             $criteriaText = new Criteria();
  19.             $criteriaText->addFilter(new EqualsFilter('name''digi1_customtexts'));
  20.             $resultText $customFieldSetRepository->searchIds($criteriaText$installContext->getContext());
  21.             if ($resultButton->getTotal() == 0) {
  22.                 $customFieldSetRepository->create([[
  23.                     'name' => 'digi1_custombuttons',
  24.                     'config' => [
  25.                         'label' => [
  26.                             'de-DE' => 'Individuelle Schaltfläche',
  27.                             'en-GB' => 'Custom button'
  28.                         ],
  29.                         'translated' => true
  30.                     ],
  31.                     'customFields' => [
  32.                         [
  33.                             'name' => 'digi1_custombuttons_custombutton',
  34.                             'type' => CustomFieldTypes::BOOL,
  35.                             'config' => [
  36.                                 'label' => [
  37.                                     'de-DE' => 'Individuelle Schaltfläche für dieses Produkt (falls der Wert ausgewählte Produkte ausgewählt wurde)',
  38.                                     'en-GB' => 'Custom button for this product (if the value selected products is selected)'
  39.                                 ],
  40.                                 'componentName' => 'sw-field',
  41.                                 'customFieldType' => 'switch',
  42.                                 'customFieldPosition' => 1,
  43.                                 'type' => 'switch'
  44.                             ]
  45.                         ],
  46.                         [
  47.                             'name' => 'digi1_custombuttons_buttontext',
  48.                             'type' => CustomFieldTypes::TEXT,
  49.                             'config' => [
  50.                                 'label' => [
  51.                                     'de-DE' => 'Text der individuellen Schaltfläche',
  52.                                     'en-GB' => 'Text of the custom button'
  53.                                 ],
  54.                                 'componentName' => 'sw-field',
  55.                                 'customFieldType' => 'text',
  56.                                 'customFieldPosition' => 2,
  57.                                 'type' => 'text'
  58.                             ]
  59.                         ],
  60.                         [
  61.                             'name' => 'digi1_custombuttons_buttonaction',
  62.                             'type' => 'select',
  63.                             'config' => [
  64.                                 'label' => [
  65.                                     'de-DE' => 'Aktion der Individuellen Schaltfläche',
  66.                                     'en-GB' => 'action of the custom button'
  67.                                 ],
  68.                                 'options' => [
  69.                                     [
  70.                                         'label' => [
  71.                                             'de-DE' => 'Verlinken auf eine URL',
  72.                                             'en-GB' => 'Link to a URL'
  73.                                         ],
  74.                                         'value' => 'url'
  75.                                     ],
  76.                                     [
  77.                                         'label' => [
  78.                                             'de-DE' => 'Verlinken auf eine E-Mail-Adresse',
  79.                                             'en-GB' => 'Link to a email address'
  80.                                         ],
  81.                                         'value' => 'email'
  82.                                     ],
  83.                                     [
  84.                                         'label' => [
  85.                                             'de-DE' => 'Verlinken auf ein Formular',
  86.                                             'en-GB' => 'Link to a form'
  87.                                         ],
  88.                                         'value' => 'form'
  89.                                     ]
  90.                                 ],
  91.                                 'componentName' => 'sw-single-select',
  92.                                 'customFieldType' => 'select',
  93.                                 'customFieldPosition' => 3,
  94.                                 'type' => 'select'
  95.                             ]
  96.                         ],
  97.                         [
  98.                             'name' => 'digi1_custombuttons_actionvalue',
  99.                             'type' => CustomFieldTypes::TEXT,
  100.                             'config' => [
  101.                                 'label' => [
  102.                                     'de-DE' => 'URL, E-Mail-Adresse oder die CMS - ID des Formulars',
  103.                                     'en-GB' => 'URL, email address or the cms id of the form'
  104.                                 ],
  105.                                 'componentName' => 'sw-field',
  106.                                 'customFieldType' => 'text',
  107.                                 'customFieldPosition' => 4,
  108.                                 'type' => 'text'
  109.                             ]
  110.                         ],
  111.                         [
  112.                             'name' => 'digi1_custombuttons_actionvaluesubject',
  113.                             'type' => CustomFieldTypes::TEXT,
  114.                             'config' => [
  115.                                 'label' => [
  116.                                     'de-DE' => 'Betreff der E-Mail',
  117.                                     'en-GB' => 'Subject of the email'
  118.                                 ],
  119.                                 'componentName' => 'sw-field',
  120.                                 'customFieldType' => 'text',
  121.                                 'customFieldPosition' => 5,
  122.                                 'type' => 'text'
  123.                             ]
  124.                         ],
  125.                         [
  126.                             'name' => 'digi1_custombuttons_actionvaluebody',
  127.                             'type' => CustomFieldTypes::TEXT,
  128.                             'config' => [
  129.                                 'label' => [
  130.                                     'de-DE' => 'Inhalt der E-Mail',
  131.                                     'en-GB' => 'Body of the email'
  132.                                 ],
  133.                                 'componentName' => 'sw-field',
  134.                                 'customFieldType' => 'text',
  135.                                 'customFieldPosition' => 6
  136.                             ]
  137.                         ],
  138.                         [
  139.                             'name' => 'digi1_custombuttons_actiontarget',
  140.                             'type' => CustomFieldTypes::BOOL,
  141.                             'config' => [
  142.                                 'label' => [
  143.                                     'de-DE' => 'URL in einem neuen Fenster öffnen',
  144.                                     'en-GB' => 'Open the url in a new window'
  145.                                 ],
  146.                                 'componentName' => 'sw-field',
  147.                                 'customFieldType' => 'switch',
  148.                                 'customFieldPosition' => 7,
  149.                                 'type' => 'switch'
  150.                             ]
  151.                         ]
  152.                     ],
  153.                     'relations' => [
  154.                         ['entityName' => 'product']
  155.                     ]
  156.                 ]], $installContext->getContext());
  157.             }
  158.             if ($resultButton->getTotal() == 0) {
  159.                 $customFieldSetRepository->create([[
  160.                     'name' => 'digi1_customtexts',
  161.                     'config' => [
  162.                         'label' => [
  163.                             'de-DE' => 'Individueller Text',
  164.                             'en-GB' => 'Custom text'
  165.                         ],
  166.                         'translated' => true
  167.                     ],
  168.                     'customFields' => [
  169.                         [
  170.                             'name' => 'digi1_customtexts_showcustomtext',
  171.                             'type' => CustomFieldTypes::BOOL,
  172.                             'config' => [
  173.                                 'label' => [
  174.                                     'de-DE' => 'Individueller Text für dieses Produkt anzeigen (falls der Wert ausgewählte Produkte ausgewählt wurde)',
  175.                                     'en-GB' => 'Show custom text for this product (if the value selected products is selected)'
  176.                                 ],
  177.                                 'componentName' => 'sw-field',
  178.                                 'customFieldType' => 'switch',
  179.                                 'customFieldPosition' => 1,
  180.                                 'type' => 'switch'
  181.                             ]
  182.                         ],
  183.                         [
  184.                             'name' => 'digi1_customtexts_customtext',
  185.                             'type' => CustomFieldTypes::HTML,
  186.                             'config' => [
  187.                                 'label' => [
  188.                                     'de-DE' => 'Individueller Text',
  189.                                     'en-GB' => 'Custom text'
  190.                                 ],
  191.                                 'componentName' => 'sw-text-editor',
  192.                                 'customFieldType' => 'textEditor',
  193.                                 'customFieldPosition' => 2
  194.                             ]
  195.                         ]
  196.                     ],
  197.                     'relations' => [
  198.                         ['entityName' => 'product']
  199.                     ]
  200.                 ]], $installContext->getContext());
  201.             }
  202.             parent::install($installContext);
  203.         }
  204.         public function postInstall(InstallContext $installContext): void {
  205.             parent::postInstall($installContext);
  206.         }
  207.         public function update(UpdateContext $updateContext): void {
  208.         }
  209.         public function postUpdate(UpdateContext $updateContext): void {
  210.         }
  211.         public function activate(ActivateContext $activateContext): void {
  212.             parent::activate($activateContext);
  213.         }
  214.         public function deactivate(DeactivateContext $deactivateContext): void {
  215.             parent::deactivate($deactivateContext);
  216.         }
  217.         public function uninstall(UninstallContext $uninstallContext): void {
  218.             $customFieldSetRepository $this->container->get('custom_field_set.repository');
  219.             $criteriaButton = new Criteria();
  220.             $criteriaButton->addFilter(new EqualsFilter('name''digi1_custombuttons'));
  221.             $resultButton $customFieldSetRepository->searchIds($criteriaButton$uninstallContext->getContext());
  222.             if ($resultButton->getTotal() > && !$uninstallContext->keepUserData()) {
  223.                 $dataButton $resultButton->getDataOfId($resultButton->firstId());
  224.                 $customFieldSetRepository->delete([$dataButton], $uninstallContext->getContext());
  225.             }
  226.             $criteriaText = new Criteria();
  227.             $criteriaText->addFilter(new EqualsFilter('name''digi1_customtexts'));
  228.             $resultText $customFieldSetRepository->searchIds($criteriaText$uninstallContext->getContext());
  229.             if ($resultText->getTotal() > && !$uninstallContext->keepUserData()) {
  230.                 $dataText $resultText->getDataOfId($resultText->firstId());
  231.                 $customFieldSetRepository->delete([$dataText], $uninstallContext->getContext());
  232.             }
  233.             parent::uninstall($uninstallContext);
  234.         }
  235.     }