app/Plugin/BundleSale4/Service/OrderStateMachine.php line 57

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of BundleSale4
  4.  *
  5.  * Copyright(c) Akira Kurozumi <info@a-zumi.net>
  6.  *
  7.  * https://a-zumi.net
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Plugin\BundleSale4\Service;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Plugin\BundleSale4\Service\PurchaseFlow\Processor\BundleItemStockReduceProcessor;
  15. use Eccube\Service\PurchaseFlow\PurchaseContext;
  16. use Symfony\Component\Workflow\Event\Event;
  17. class OrderStateMachine implements EventSubscriberInterface
  18. {
  19.     private $stockReduceProcessor;
  20.     public function __construct(BundleItemStockReduceProcessor $stockReduceProcessor)
  21.     {
  22.         $this->stockReduceProcessor $stockReduceProcessor;
  23.     }
  24.     public static function getSubscribedEvents(): array
  25.     {
  26.         return [
  27.             'workflow.order.transition.cancel' => [['rollbackStock']],
  28.             'workflow.order.transition.back_to_in_progress' => [['commitStock']],
  29.         ];
  30.     }
  31.     /**
  32.      * 在庫を減らす.
  33.      *
  34.      * @param Event $event
  35.      *
  36.      * @throws PurchaseFlow\PurchaseException
  37.      */
  38.     public function commitStock(Event $event)
  39.     {
  40.         /* @var Order $Order */
  41.         $Order $event->getSubject()->getOrder();
  42.         $this->stockReduceProcessor->prepare($Order, new PurchaseContext());
  43.     }
  44.     /**
  45.      * 在庫を戻す.
  46.      *
  47.      * @param Event $event
  48.      */
  49.     public function rollbackStock(Event $event)
  50.     {
  51.         /* @var Order $Order */
  52.         $Order $event->getSubject()->getOrder();
  53.         $this->stockReduceProcessor->rollback($Order, new PurchaseContext());
  54.     }
  55. }