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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace TigerMedia\General\TigerRequestDeliveryDate;
  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\Framework\Uuid\Uuid;
  7. use Shopware\Core\System\CustomField\CustomFieldTypes;
  8. class TigerRequestDeliveryDate extends Plugin
  9. {
  10.     public function activate(ActivateContext $activateContext): void
  11.     {
  12.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  13.         $this->installCustomFieldsForProduct($activateContext$customFieldSetRepository);
  14.         parent::activate($activateContext);
  15.     }
  16.     private function installCustomFieldsForProduct(Plugin\Context\ActivateContext $context, ?object $customFieldSetRepository): void
  17.     {
  18.         /** @var Connection $connection */
  19.         $connection $this->container->get('Doctrine\DBAL\Connection');
  20.         $customFieldSetRepository->upsert([[
  21.             'id' => Uuid::fromStringToHex('tigermediarequestdeliverydate'),
  22.             'name' => 'tigermediarequestdeliverydate',
  23.             'active' => true,
  24.             'config' => [
  25.                 'label' => [
  26.                     'en-GB' => 'Tiger Request Delivery Date'
  27.                 ],
  28.             ],
  29.             'customFields' => $this->getOrderCustomFields(),
  30.             'relations' => [
  31.                 [
  32.                     'entityName' => 'order'
  33.                 ]
  34.             ]
  35.         ]], $context->getContext());
  36.     }
  37.     /**
  38.      * @return array<mixed>
  39.      */
  40.     private function getOrderCustomFields(): array
  41.     {
  42.         return [
  43.             [
  44.                 'id' => Uuid::fromStringToHex('tigermediarequestdelivery'),
  45.                 'name' => 'tigermediarequestdelivery',
  46.                 'type' => CustomFieldTypes::TEXT,
  47.                 'config' => [
  48.                     'bordered' => false,
  49.                     'label' => [
  50.                         'en-GB' => 'Requested delivery date'
  51.                     ],
  52.                     'customFieldPosition' => 0,
  53.                     'helpText' => [
  54.                         'en-GB' => 'Requested delivery date'
  55.                     ],
  56.                 ],
  57.             ]
  58.         ];
  59.     }
  60. }