custom/plugins/BjerregaardTheme/src/BjerregaardTheme.php line 11

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace BjerregaardTheme;
  3. use Doctrine\DBAL\Driver\PDO\Connection;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  6. use Shopware\Core\System\CustomField\CustomFieldTypes;
  7. use Shopware\Storefront\Framework\ThemeInterface;
  8. class BjerregaardTheme extends Plugin implements ThemeInterface
  9. {
  10.     public function boot(): void
  11.     {
  12.         parent::boot();
  13.         if (!$this->isActive()) {
  14.             return;
  15.         }
  16.         if (file_exists(__DIR__ '/../vendor/autoload.php')) {
  17.             require __DIR__ '/../vendor/autoload.php';
  18.         }
  19.     }
  20.     public function activate(ActivateContext $activateContext): void
  21.     {
  22.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  23.         //$this->installCustomFields($activateContext, $customFieldSetRepository);
  24.         parent::activate($activateContext); // TODO: Change the autogenerated stub
  25.     }
  26.     /** @phpstan-ignore-next-line */
  27.     private function installCustomFields(Plugin\Context\ActivateContext $context, ?object $customFieldSetRepository): void
  28.     {
  29.         /** @var Connection $connection */
  30.         $connection $this->container->get('Doctrine\DBAL\Connection');
  31.         $customFieldSetRepository->upsert([[
  32.             'name' => 'bjerregaardcustomercustomfields',
  33.             'active' => true,
  34.             'global' => true,
  35.             'config' => [
  36.                 'label' => [
  37.                     'en-GB' => 'Bjerregaard Customer Custom fields'
  38.                 ],
  39.             ],
  40.             'customFields' => $this->getCustomFields(),
  41.             'relations' => [
  42.                 [
  43.                     'entityName' => 'customer'
  44.                 ]
  45.             ]
  46.         ]], $context->getContext());
  47.     }
  48.     /**
  49.      * @return array<array<string, mixed>>
  50.      */
  51.     private function getCustomFields(): array
  52.     {
  53.         return [
  54.             [
  55.                 'name' => 'DiscountGroup',
  56.                 'type' => CustomFieldTypes::TEXT,
  57.                 'config' => [
  58.                     'bordered' => false,
  59.                     'label' => [
  60.                         'en-GB' => 'Customer discount group'
  61.                     ],
  62.                     'customFieldPosition' => 0
  63.                 ],
  64.             ],
  65.             [
  66.                 'name' => 'FreightCode',
  67.                 'type' => CustomFieldTypes::TEXT,
  68.                 'config' => [
  69.                     'bordered' => false,
  70.                     'label' => [
  71.                         'en-GB' => 'Freight Code'
  72.                     ],
  73.                     'customFieldPosition' => 1,
  74.                 ],
  75.             ]
  76.         ];
  77.     }
  78. }