vendor/store.shopware.com/crswcleverreachofficial/src/Subscriber/Orders/OrderSubscriber.php line 72

Open in your IDE?
  1. <?php
  2. namespace Crsw\CleverReachOfficial\Subscriber\Orders;
  3. use Crsw\CleverReachOfficial\Components\EventHandlers\OrderHandler;
  4. use Crsw\CleverReachOfficial\Components\Utility\Bootstrap;
  5. use Crsw\CleverReachOfficial\Components\Utility\Initializer;
  6. use Crsw\CleverReachOfficial\Entity\Orders\Repositories\OrderItemsRepositoryInterface;
  7. use Shopware\Core\Checkout\Order\OrderEvents;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  11. /**
  12.  * Class OrderSubscriber
  13.  *
  14.  * @package Crsw\CleverReachOfficial\Subscriber\Orders
  15.  */
  16. class OrderSubscriber implements EventSubscriberInterface
  17. {
  18.     /**
  19.      * @var SessionInterface
  20.      */
  21.     private $session;
  22.     /**
  23.      * @var OrderHandler
  24.      */
  25.     private $orderHandler;
  26.     /**
  27.      * @var OrderItemsRepositoryInterface
  28.      */
  29.     private $orderItemsRepository;
  30.     /**
  31.      * OrderSubscriber constructor.
  32.      *
  33.      * @param SessionInterface $session
  34.      * @param OrderHandler $orderHandler
  35.      * @param OrderItemsRepositoryInterface $orderItemsRepository
  36.      * @param Initializer $initializer
  37.      */
  38.     public function __construct(
  39.         SessionInterface $session,
  40.         OrderHandler $orderHandler,
  41.         OrderItemsRepositoryInterface $orderItemsRepository,
  42.         Initializer $initializer
  43.     ) {
  44.         Bootstrap::init();
  45.         $initializer->registerServices();
  46.         $this->session $session;
  47.         $this->orderHandler $orderHandler;
  48.         $this->orderItemsRepository $orderItemsRepository;
  49.     }
  50.     /**
  51.      * @return string[]
  52.      */
  53.     public static function getSubscribedEvents(): array
  54.     {
  55.         return [
  56.             OrderEvents::ORDER_WRITTEN_EVENT => 'onOrderSave'
  57.         ];
  58.     }
  59.     /**
  60.      * Handles order created event.
  61.      *
  62.      * @param EntityWrittenEvent $event
  63.      */
  64.     public function onOrderSave(EntityWrittenEvent $event): void
  65.     {
  66.         if (!$this->orderHandler->canHandle() || !$this->session->isStarted()) {
  67.             return;
  68.         }
  69.         $ids $event->getIds();
  70.         $orderId reset($ids);
  71.         $crMailing $this->session->get('crMailing');
  72.         $email $this->orderItemsRepository->getEmailByOrderId($orderId);
  73.         $this->orderHandler->orderCreated($email$orderId$crMailing ?: '');
  74.     }
  75. }