<?php declare(strict_types=1);
namespace NetzpShopmanager6\Subscriber;
use NetzpShopmanager6\Components\PushMessageHelper;
use Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class FrontendSubscriber implements EventSubscriberInterface
{
private $container;
private $config;
private $pushHelper;
public function __construct(ContainerInterface $container,
SystemConfigService $config,
PushMessageHelper $pushHelper)
{
$this->container = $container;
$this->config = $config;
$this->pushHelper = $pushHelper;
}
public static function getSubscribedEvents(): array
{
return [
CheckoutOrderPlacedEvent::class => 'onOrder'
];
}
public function onOrder(CheckoutOrderPlacedEvent $event): void
{
$config = $this->config->get('NetzpShopmanager6.config');
if(array_key_exists('usepush', $config) && $config['usepush']) {
$salesChannelId = $event->getSalesChannelId();
$template = $this->config->get('NetzpShopmanager6.config.pushtemplate', $salesChannelId);
if ($template == '') {
$template = PushMessageHelper::DEFAULT_PUSH_TEMPLATE;
}
$this->pushHelper->sendPushMessage($event->getOrder(), $event->getContext(), $template, $salesChannelId);
}
}
}