<?php
namespace Prems\Plugin\PremsIndividualOffer6\Subscriber;
use Prems\Plugin\PremsIndividualOffer6\Core\Offer\NotificationService;
use Prems\Plugin\PremsIndividualOffer6\Core\Offer\Storefront\ConfigService;
use Prems\Plugin\PremsIndividualOffer6\Core\Offer\Storefront\OfferService;
use Prems\Plugin\PremsIndividualOffer6\Event\OfferCreatedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class OfferCreatedSubscriber implements EventSubscriberInterface
{
private ConfigService $configService;
private OfferService $offerService;
private NotificationService $notificationService;
public function __construct(
ConfigService $configService,
OfferService $offerService,
NotificationService $notificationService
)
{
$this->configService = $configService;
$this->offerService = $offerService;
$this->notificationService = $notificationService;
}
public static function getSubscribedEvents(): array
{
return [
OfferCreatedEvent::class => 'onOfferCreated',
];
}
public function onOfferCreated(OfferCreatedEvent $event): void
{
$config = $this->configService->getConfig($event->getSalesChannelContext());
if (!$config->isCreateInstantOffer()) {
return;
}
$this->offerService->setOffered($event->getOfferId(), $event->getContext());
$offer = $this->offerService->getOfferById($event->getOfferId(), $event->getContext());
$this->notificationService->adminCreatedOffer($event->getContext(), $offer);
}
}