<?php
namespace Customize\Service;
use Eccube\Entity\Master\OrderStatus;
use Eccube\Entity\Order;
use Eccube\Repository\Master\OrderStatusRepository;
use Eccube\Service\PurchaseFlow\Processor\PointProcessor;
use Eccube\Service\PurchaseFlow\Processor\StockReduceProcessor;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Workflow\Event\Event;
use Symfony\Component\Workflow\StateMachine;
class OrderStateMachine implements EventSubscriberInterface
{
/**
* @var StateMachine
*/
private $machine;
/**
* @var OrderStatusRepository
*/
private $orderStatusRepository;
/**
* @var PointProcessor
*/
private $pointProcessor;
/**
* @var StockReduceProcessor
*/
private $stockReduceProcessor;
/**
* @var MailService
*/
protected $mailService;
public function __construct(StateMachine $_orderStateMachine, OrderStatusRepository $orderStatusRepository, PointProcessor $pointProcessor, StockReduceProcessor $stockReduceProcessor, MailService $mailService)
{
$this->machine = $_orderStateMachine;
$this->orderStatusRepository = $orderStatusRepository;
$this->pointProcessor = $pointProcessor;
$this->stockReduceProcessor = $stockReduceProcessor;
$this->mailService = $mailService;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
//'workflow.order.completed' => ['onCompleted'],
'workflow.order.transition.pay' => ['sendPaymentMail'],
'workflow.order.transition.cancel' => ['sendCancelMail'],
// 'workflow.order.transition.back_to_in_progress' => [['commitStock'], ['commitUsePoint']],
// 'workflow.order.transition.ship' => [['commitAddPoint']],
// 'workflow.order.transition.return' => [['rollbackUsePoint'], ['rollbackAddPoint']],
// 'workflow.order.transition.cancel_return' => [['commitUsePoint'], ['commitAddPoint']],
];
}
/*
* Event handlers.
*/
public function sendPaymentMail(Event $event)
{
/* @var Order $Order */
$Order = $event->getSubject()->getOrder();
$this->mailService->sendPaymentMail($Order);
}
public function sendCancelMail(Event $event)
{
/* @var Order $Order */
$Order = $event->getSubject()->getOrder();
$this->mailService->sendCancelMail($Order);
}
}