custom/plugins/NetzpShopmanager6/src/Subscriber/FrontendSubscriber.php line 33

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace NetzpShopmanager6\Subscriber;
  3. use NetzpShopmanager6\Components\PushMessageHelper;
  4. use Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;
  5. use Shopware\Core\System\SystemConfig\SystemConfigService;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\DependencyInjection\ContainerInterface;
  8. class FrontendSubscriber implements EventSubscriberInterface
  9. {
  10.     private $container;
  11.     private $config;
  12.     private $pushHelper;
  13.     public function __construct(ContainerInterface $container,
  14.                                 SystemConfigService $config,
  15.                                 PushMessageHelper $pushHelper)
  16.     {
  17.         $this->container  $container;
  18.         $this->config     $config;
  19.         $this->pushHelper $pushHelper;
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             CheckoutOrderPlacedEvent::class => 'onOrder'
  25.         ];
  26.     }
  27.     public function onOrder(CheckoutOrderPlacedEvent $event): void
  28.     {
  29.         $config $this->config->get('NetzpShopmanager6.config');
  30.         if(array_key_exists('usepush'$config) && $config['usepush']) {
  31.             $salesChannelId $event->getSalesChannelId();
  32.             $template $this->config->get('NetzpShopmanager6.config.pushtemplate'$salesChannelId);
  33.             if ($template == '') {
  34.                 $template PushMessageHelper::DEFAULT_PUSH_TEMPLATE;
  35.             }
  36.             $this->pushHelper->sendPushMessage($event->getOrder(), $event->getContext(), $template$salesChannelId);
  37.         }
  38.     }
  39. }