custom/plugins/ProxaOrderManagement/src/Subscribers/OrderSubscriber.php line 51

Open in your IDE?
  1. <?php
  2. namespace ProxaOrderManagement\Subscribers;
  3. use ProxaOrderManagement\Exception\Order\Warehouse\StockException;
  4. use ProxaOrderManagement\Services\Order\OrderService;
  5. use ProxaOrderManagement\Services\Warehouse\WarehouseMailService;
  6. use ProxaOrderManagement\Struct\Order\Warehouse\OrderWarehouseFilterCollection;
  7. use Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;
  8. use Shopware\Core\Content\MailTemplate\Subscriber\MailSendSubscriber;
  9. use Shopware\Core\Content\MailTemplate\Subscriber\MailSendSubscriberConfig;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class OrderSubscriber implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * @var WarehouseMailService
  15.      */
  16.     private WarehouseMailService $warehouseMailService;
  17.     private OrderService $orderService;
  18.     /**
  19.      * @param WarehouseMailService $warehouseMailService
  20.      * @param OrderService $orderService
  21.      */
  22.     public function __construct(
  23.         WarehouseMailService $warehouseMailService,
  24.         OrderService         $orderService
  25.     )
  26.     {
  27.         $this->warehouseMailService $warehouseMailService;
  28.         $this->orderService $orderService;
  29.     }
  30.     /**
  31.      * @return string[]
  32.      */
  33.     public static function getSubscribedEvents(): array
  34.     {
  35.         return [
  36.             CheckoutOrderPlacedEvent::class => ['onCheckoutOrderPlacedEvent', -999],
  37.             OrderWarehouseFilterCollection::class => 'onOrderWarehouseFilterCollection'
  38.         ];
  39.     }
  40.     /**
  41.      * @param CheckoutOrderPlacedEvent $event
  42.      * @return void
  43.      * @throws StockException
  44.      */
  45.     public function onCheckoutOrderPlacedEvent(CheckoutOrderPlacedEvent $event)
  46.     {
  47.         $this->warehouseMailService->orderPlacedMailAction($event);
  48.         //this must set after mailAction
  49.         if ($this->orderService->saveOrderClickAndCollectWarehouse($event->getOrder())) {
  50.             //it`s stop send mails sender via context
  51.             $event->getContext()->addExtension(MailSendSubscriber::MAIL_CONFIG_EXTENSION, new MailSendSubscriberConfig(true, [], [])); //not sent order mail to customer
  52.         }
  53.     }
  54.     public function onOrderWarehouseFilterCollection(OrderWarehouseFilterCollection $collection)
  55.     {
  56.         $this->orderService->saveOrderWarehouse($collection);
  57.     }
  58. }