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

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\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  7. use Shopware\Core\System\SystemConfig\SystemConfigService;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\DependencyInjection\ContainerInterface;
  10. class FrontendSubscriber implements EventSubscriberInterface
  11. {
  12.     private $container;
  13.     private $config;
  14.     private $pushHelper;
  15.     public function __construct(ContainerInterface $container,
  16.                                 SystemConfigService $config,
  17.                                 PushMessageHelper $pushHelper)
  18.     {
  19.         $this->container  $container;
  20.         $this->config     $config;
  21.         $this->pushHelper $pushHelper;
  22.     }
  23.     public static function getSubscribedEvents(): array
  24.     {
  25.         return [
  26.             CheckoutOrderPlacedEvent::class => 'onOrder'
  27.         ];
  28.     }
  29.     public function onOrder(CheckoutOrderPlacedEvent $event): void
  30.     {
  31.         $config $this->config->get('NetzpShopmanager6.config');
  32.         if(array_key_exists('usepush'$config) && $config['usepush']) {
  33.             $salesChannelId $event->getSalesChannelId();
  34.             $repo $this->container->get('language.repository');
  35.             $criteria = new Criteria();
  36.             $criteria->addFilter(new EqualsFilter('id'$event->getContext()->getLanguageId()));
  37.             $criteria->addAssociation('locale');
  38.             $language $repo->search($criteria$event->getContext())->getEntities()->first();
  39.             $localeCode 'de';
  40.             if($language != null) {
  41.                 $localeCode $language->getLocale()->getCode() ?? 'de';
  42.             }
  43.             $localeCode strtolower(substr($localeCode02));
  44.             $template $this->config->get('NetzpShopmanager6.config.pushtemplate'$salesChannelId);
  45.             if ($template == '') {
  46.                 $template PushMessageHelper::DEFAULT_PUSH_TEMPLATE;
  47.             }
  48.             $this->pushHelper->sendPushMessage(
  49.                 $event->getOrder(),
  50.                 $event->getContext(),
  51.                 $template,
  52.                 $salesChannelId,
  53.                 null,
  54.                 $localeCode);
  55.         }
  56.     }
  57. }