custom/plugins/CompraInvoiceDispatchSW6/src/CompraInvoiceDispatchSW6.php line 12

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Compra\InvoiceDispatchSW6;
  3. use Compra\FoundationSW6\Core\System\CustomFieldService;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  6. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  7. use Shopware\Core\System\CustomField\CustomFieldTypes;
  8. use Symfony\Component\DependencyInjection\ContainerBuilder;
  9. class CompraInvoiceDispatchSW6 extends Plugin
  10. {
  11.     public function build(ContainerBuilder $container): void
  12.     {
  13.         $container->setParameter('compra_invoice_dispatch_s_w6.plugin_dir'$this->getPath());
  14.         parent::build($container);
  15.     }
  16.     public function install(InstallContext $installContext): void
  17.     {
  18.         parent::install($installContext);
  19.         $this->addCustomFields($installContext->getContext());
  20.     }
  21.     public function update(UpdateContext $updateContext): void
  22.     {
  23.         parent::update($updateContext);
  24.         $this->addCustomFields($updateContext->getContext());
  25.     }
  26.     /**
  27.      * Function to create the custom fields for the plugin.
  28.      *
  29.      * @param $context
  30.      */
  31.     public function addCustomFields($context): void
  32.     {
  33.         $customFieldService $this->container->get(CustomFieldService::class);
  34.         if (!$customFieldService) {
  35.             return;
  36.         }
  37.         try {
  38.             $customFieldService->createOrUpdateCustomFieldSets([
  39.                 [
  40.                     'name' => 'compra_invoice_dispatch',
  41.                     'config' => [
  42.                         'label' => [
  43.                             'de-DE' => 'COMPRA Rechnungsversand',
  44.                             'en-GB' => 'COMPRA Invoice Dispatch'
  45.                         ]
  46.                     ],
  47.                     'relations' => [
  48.                         [
  49.                             'entityName' => 'customer'
  50.                         ]
  51.                     ],
  52.                     'customFields' => [
  53.                         [
  54.                             'name' => 'compra_invoice_mail_enabled',
  55.                             'type' => 'bool',
  56.                             'config' => [
  57.                                 'type' => 'checkbox',
  58.                                 'label' => [
  59.                                     'de-DE' => 'Rechnungsversand per E-Mail',
  60.                                     'en-GB' => 'Invoice dispatch by e-mail'
  61.                                 ],
  62.                                 'helpText' => [
  63.                                     'de-DE' => 'Sollen Rechnungen per E-Mail versandt werden?',
  64.                                     'en-GB' => 'Should invoices be sent by e-mail?'
  65.                                 ],
  66.                                 'componentName' => 'sw-field',
  67.                                 'customFieldType' => 'checkbox',
  68.                                 'customFieldPosition' => 0
  69.                             ]
  70.                         ],
  71.                         [
  72.                             'name' => 'compra_invoice_mail_address',
  73.                             'type' => 'text',
  74.                             'config' => [
  75.                                 'label' => [
  76.                                     'de-DE' => 'Rechnungs-E-Mail-Adresse',
  77.                                     'en-GB' => 'Invoice e-mail address'
  78.                                 ],
  79.                                 'helpText' => [
  80.                                     'de-DE' => 'E-Mail-Adresse für den Rechnungsversannd',
  81.                                     'en-GB' => 'E-mail address for the invoice dispatch'
  82.                                 ],
  83.                                 'componentName' => 'sw-field',
  84.                                 'customFieldType' => 'text',
  85.                                 'customFieldPosition' => 1
  86.                             ]
  87.                         ]
  88.                     ]
  89.                 ]], $context);
  90.         } catch (\Exception $e) {}
  91.     }
  92. }