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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Compra\EnvironmentalDiscountSW6;
  3. use Compra\FoundationSW6\Core\System\CustomFieldService;
  4. use Shopware\Core\Framework\Context;
  5. use Shopware\Core\Framework\Plugin;
  6. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  7. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  8. use Shopware\Core\System\CustomField\CustomFieldTypes;
  9. use Symfony\Component\DependencyInjection\ContainerBuilder;
  10. class CompraEnvironmentalDiscountSW6 extends Plugin
  11. {
  12.     public function build(ContainerBuilder $container): void
  13.     {
  14.         $container->setParameter('compra_environmental_discount_s_w6.plugin_dir'$this->getPath());
  15.         parent::build($container);
  16.     }
  17.     public function install(InstallContext $installContext): void
  18.     {
  19.         parent::install($installContext);
  20.         $this->addCustomFields($installContext->getContext());
  21.     }
  22.     public function update(UpdateContext $updateContext): void
  23.     {
  24.         parent::update($updateContext);
  25.         $this->addCustomFields($updateContext->getContext());
  26.     }
  27.     /**
  28.      * Function to create the custom fields for the plugin.
  29.      *
  30.      * @param Context $context
  31.      */
  32.     public function addCustomFields(Context $context): void
  33.     {
  34.         $customFieldService $this->container->get(CustomFieldService::class);
  35.         if (!$customFieldService) {
  36.             return;
  37.         }
  38.         try {
  39.             $customFieldService->createOrUpdateCustomFields([
  40.                 [
  41.                     'name' => 'compra_environmental_discount_has_changed_to_mail',
  42.                     'type' => CustomFieldTypes::BOOL
  43.                 ]
  44.             ], $context);
  45.         } catch (\Exception $e) {}
  46.     }
  47. }