custom/static-plugins/K3nAdditionalOrderFields/src/K3nAdditionalOrderFields.php line 11

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace K3n\AdditionalOrderFields;
  3. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  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\System\CustomField\CustomFieldTypes;
  8. class K3nAdditionalOrderFields extends Plugin
  9. {
  10.     public function install(InstallContext $installContext): void
  11.     {
  12.         $this->createFields($installContext);
  13.     }
  14.     public function uninstall(UninstallContext $uninstallContext): void
  15.     {
  16.         if (!$uninstallContext->keepUserData()) {
  17.             $this->removeFields($uninstallContext);
  18.         }
  19.     }
  20.     private function createFields(InstallContext $installContext)
  21.     {
  22.         /**
  23.          * @var $customFieldSetRepository EntityRepositoryInterface
  24.          */
  25.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  26.         $customFieldSetRepository->upsert($this->getCustomFields(), $installContext->getContext());
  27.     }
  28.     private function getCustomFields()
  29.     {
  30.         return [
  31.             [
  32.                 'id'     => '0617768191c57ed143fcd50eda6e7017',
  33.                 'name'   => 'k3n_order_fields',
  34.                 'active' => true,
  35.                 'config' => [
  36.                     'label' => [
  37.                         'en-GB' => 'Additional order fields (k3n)',
  38.                         'de-DE' => 'Zusätzliche Felder für Bestellungen (k3n)',
  39.                     ],
  40.                 ],
  41.                 'customFields' => [
  42.                     [
  43.                         'id'     => '9c5a6b742cd7da92f5c5dcffb7660249',
  44.                         'name'   => 'k3n_order_sales_consultant',
  45.                         'active' => true,
  46.                         'type'   => CustomFieldTypes::TEXT,
  47.                         'config' => [
  48.                             'label' => [
  49.                                 'en-GB' => 'Sales consultant',
  50.                                 'de-DE' => 'Verkaufsberater',
  51.                             ],
  52.                             'customFieldType' => CustomFieldTypes::TEXT,
  53.                             'customFieldPosition' => 1
  54.                         ],
  55.                     ],
  56.                 ],
  57.                 'relations' => [
  58.                     [
  59.                         'id'         => '292063964ad82b24a3d39ef3e8778d1b',
  60.                         'entityName' => 'order',
  61.                     ],
  62.                 ],
  63.             ],
  64.         ];
  65.     }
  66.     private function removeFields(UninstallContext $uninstallContext)
  67.     {
  68.         /**
  69.          * @var $customFieldSetRepository EntityRepositoryInterface
  70.          */
  71.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  72.         $customFieldSetRepository->delete([['id' => '0617768191c57ed143fcd50eda6e7017']], $uninstallContext->getContext());
  73.     }
  74. }