custom/plugins/PremsIndividualOffer6/src/Subscriber/OfferCreatedSubscriber.php line 35

Open in your IDE?
  1. <?php
  2. namespace Prems\Plugin\PremsIndividualOffer6\Subscriber;
  3. use Prems\Plugin\PremsIndividualOffer6\Core\Offer\NotificationService;
  4. use Prems\Plugin\PremsIndividualOffer6\Core\Offer\Storefront\ConfigService;
  5. use Prems\Plugin\PremsIndividualOffer6\Core\Offer\Storefront\OfferService;
  6. use Prems\Plugin\PremsIndividualOffer6\Event\OfferCreatedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class OfferCreatedSubscriber implements EventSubscriberInterface
  9. {
  10.     private ConfigService $configService;
  11.     private OfferService $offerService;
  12.     private NotificationService $notificationService;
  13.     public function __construct(
  14.         ConfigService $configService,
  15.         OfferService $offerService,
  16.         NotificationService $notificationService
  17.     )
  18.     {
  19.         $this->configService $configService;
  20.         $this->offerService $offerService;
  21.         $this->notificationService $notificationService;
  22.     }
  23.     public static function getSubscribedEvents(): array
  24.     {
  25.         return [
  26.             OfferCreatedEvent::class => 'onOfferCreated',
  27.         ];
  28.     }
  29.     public function onOfferCreated(OfferCreatedEvent $event): void
  30.     {
  31.         $config $this->configService->getConfig($event->getSalesChannelContext());
  32.         if (!$config->isCreateInstantOffer()) {
  33.             return;
  34.         }
  35.         $this->offerService->setOffered($event->getOfferId(), $event->getContext());
  36.         $offer $this->offerService->getOfferById($event->getOfferId(), $event->getContext());
  37.         $this->notificationService->adminCreatedOffer($event->getContext(), $offer);
  38.     }
  39. }