custom/plugins/NetzpPowerPack6/src/NetzpPowerPack6.php line 13

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace NetzpPowerPack6;
  3. use Shopware\Core\Framework\Context;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  6. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  7. use Shopware\Core\Framework\Uuid\Uuid;
  8. use Shopware\Core\System\CustomField\CustomFieldTypes;
  9. use Shopware\Core\System\SalesChannel\SalesChannelDefinition;
  10. class NetzpPowerPack6 extends Plugin
  11. {
  12.     const CUSTOM_FIELDSET_ID '0A202BD62BDF4DABBE829B1BA499F73E';
  13.     public function install(InstallContext $context) : void
  14.     {
  15.         parent::install($context);
  16.         try {
  17.             $this->addCustomFields($context->getContext());
  18.         }
  19.         catch (\Exception $ex) {
  20.             //
  21.         }
  22.     }
  23.     public function uninstall(UninstallContext $context): void
  24.     {
  25.         parent::uninstall($context);
  26.         if ($context->keepUserData()) {
  27.             return;
  28.         }
  29.         try {
  30.             $this->removeCustomFields($context->getContext());
  31.         }
  32.         catch (\Exception $ex) {
  33.             //
  34.         }
  35.     }
  36.     public function addCustomFields(Context $context)
  37.     {
  38.         $customFieldsRepository $this->container->get('custom_field_set.repository');
  39.         $customFieldsRepository->upsert([[
  40.             'id'     => strtolower(self::CUSTOM_FIELDSET_ID),
  41.             'name'   => 'netzp_powerpack6',
  42.             'config' => [
  43.                 'label' => [
  44.                     'en-GB' => 'PowerPack',
  45.                     'de-DE' => 'PowerPack'
  46.                 ]
  47.             ],
  48.             'customFields' => [
  49.                 [
  50.                     'id'     => Uuid::randomHex(),
  51.                     'name'   => 'netzp_powerpack6_header_cms_show',
  52.                     'type'   => CustomFieldTypes::BOOL,
  53.                     'config' => [
  54.                         'customFieldPosition' => 1,
  55.                         'label' => [
  56.                             'en-GB' => 'Show CMS Element in header',
  57.                             'de-DE' => 'Zeige CMS-Element im Header'
  58.                         ]
  59.                     ]
  60.                 ],
  61.                 [
  62.                     'id'     => Uuid::randomHex(),
  63.                     'name'   => 'netzp_powerpack6_header_cms_id',
  64.                     'type'   => CustomFieldTypes::TEXT,
  65.                     'config' => [
  66.                         'componentName'       => 'sw-entity-single-select',
  67.                         'entity'              => 'cms_page',
  68.                         'customFieldType'     => 'text',
  69.                         'customFieldPosition' => 2,
  70.                         'label' => [
  71.                             'en-GB' => 'Header CMS Page ID',
  72.                             'de-DE' => 'Header CMS Seiten ID'
  73.                         ]
  74.                     ]
  75.                 ],
  76.                 [
  77.                     'id'     => Uuid::randomHex(),
  78.                     'name'   => 'netzp_powerpack6_header_cms_sticky',
  79.                     'type'   => CustomFieldTypes::BOOL,
  80.                     'config' => [
  81.                         'customFieldPosition' => 3,
  82.                         'label' => [
  83.                             'en-GB' => 'Sticky header block',
  84.                             'de-DE' => 'Fixiere das CMS-Element im Header (sticky)'
  85.                         ]
  86.                     ]
  87.                 ],
  88.                 [
  89.                     'id'     => Uuid::randomHex(),
  90.                     'name'   => 'netzp_powerpack6_footer_cms_show',
  91.                     'type'   => CustomFieldTypes::TEXT,
  92.                     'config' => [
  93.                         'componentName'       => 'sw-single-select',
  94.                         'options'             => [
  95.                             ['value' => '0''label' => ['en-GB' => 'no''de-DE' => 'nein']],
  96.                             ['value' => '1''label' => ['en-GB' => 'above standard footer''de-DE' => 'oberhalb des Standard-Footers']],
  97.                             ['value' => '2''label' => ['en-GB' => 'below standard footer''de-DE' => 'unterhalb des Standard-Footers']]
  98.                         ],
  99.                         'customFieldType'     => 'text',
  100.                         'customFieldPosition' => 4,
  101.                         'label' => [
  102.                             'en-GB' => 'Show CMS Element in footer',
  103.                             'de-DE' => 'Zeige CMS-Element im Footer'
  104.                         ]
  105.                     ]
  106.                 ],
  107.                 [
  108.                     'id'     => Uuid::randomHex(),
  109.                     'name'   => 'netzp_powerpack6_footer_cms_id',
  110.                     'type'   => CustomFieldTypes::TEXT,
  111.                     'config' => [
  112.                         'componentName'       => 'sw-entity-single-select',
  113.                         'entity'              => 'cms_page',
  114.                         'customFieldType'     => 'text',
  115.                         'customFieldPosition' => 5,
  116.                         'label' => [
  117.                             'en-GB' => 'Footer CMS Page ID',
  118.                             'de-DE' => 'Footer CMS Seiten ID'
  119.                         ]
  120.                     ]
  121.                 ],
  122.                 [
  123.                     'id'     => Uuid::randomHex(),
  124.                     'name'   => 'netzp_powerpack6_finish_cms_show',
  125.                     'type'   => CustomFieldTypes::TEXT,
  126.                     'config' => [
  127.                         'componentName'       => 'sw-single-select',
  128.                         'options'             => [
  129.                             ['value' => '0''label' => ['en-GB' => 'no''de-DE' => 'nein']],
  130.                             ['value' => '1''label' => ['en-GB' => 'above standard finish data''de-DE' => 'oberhalb der Standard-Bestellzusammenfassung']],
  131.                             ['value' => '2''label' => ['en-GB' => 'below standard finish data''de-DE' => 'unterhalb der Standard-Bestellzusammenfassung']]
  132.                         ],
  133.                         'customFieldType'     => 'text',
  134.                         'customFieldPosition' => 6,
  135.                         'label' => [
  136.                             'en-GB' => 'Show CMS Element in finish page',
  137.                             'de-DE' => 'Zeige CMS-Element auf der Bestellzusammenfassung'
  138.                         ]
  139.                     ]
  140.                 ],
  141.                 [
  142.                     'id'     => Uuid::randomHex(),
  143.                     'name'   => 'netzp_powerpack6_finish_cms_id',
  144.                     'type'   => CustomFieldTypes::TEXT,
  145.                     'config' => [
  146.                         'componentName'       => 'sw-entity-single-select',
  147.                         'entity'              => 'cms_page',
  148.                         'customFieldType'     => 'text',
  149.                         'customFieldPosition' => 7,
  150.                         'label' => [
  151.                             'en-GB' => 'Finish CMS Page ID',
  152.                             'de-DE' => 'Bestellzusammenfassung CMS Seiten ID'
  153.                         ]
  154.                     ]
  155.                 ]
  156.             ],
  157.             'relations' => [
  158.                 [
  159.                     'id' => strtolower(self::CUSTOM_FIELDSET_ID),
  160.                     'entityName' => $this->container->get(SalesChannelDefinition::class)->getEntityName()
  161.                 ]
  162.             ]
  163.         ]], $context);
  164.     }
  165.     public function removeCustomFields(Context $context)
  166.     {
  167.         $customFieldsRepository $this->container->get('custom_field_set.repository');
  168.         $customFieldsRepository->delete([['id' => self::CUSTOM_FIELDSET_ID]], $context);
  169.     }
  170. }