-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
393 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/EventListener/Workflow/CheckoutWorkflowEventListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusOrderHistoryPlugin\EventListener\Workflow; | ||
|
||
use MonsieurBiz\SyliusOrderHistoryPlugin\Entity\OrderHistoryEventInterface; | ||
use MonsieurBiz\SyliusOrderHistoryPlugin\Notifier\OrderHistoryNotifier; | ||
use MonsieurBiz\SyliusOrderHistoryPlugin\Notifier\OrderHistoryNotifierInterface; | ||
use MonsieurBiz\SyliusOrderHistoryPlugin\Notifier\OrderHistoryWithAddressesDataNotifier; | ||
use MonsieurBiz\SyliusOrderHistoryPlugin\Notifier\OrderHistoryWithPaymentDataNotifier; | ||
use MonsieurBiz\SyliusOrderHistoryPlugin\Notifier\OrderHistoryWithShipmentDataNotifier; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
use Symfony\Component\Workflow\Event\CompletedEvent; | ||
|
||
final class CheckoutWorkflowEventListener | ||
{ | ||
public function __construct( | ||
#[Autowire(service: OrderHistoryWithAddressesDataNotifier::class)] | ||
private OrderHistoryNotifierInterface $orderHistoryWithAddressesDataNotifier, | ||
#[Autowire(service: OrderHistoryNotifier::class)] | ||
private OrderHistoryNotifierInterface $orderHistoryNotifier, | ||
#[Autowire(service: OrderHistoryWithShipmentDataNotifier::class)] | ||
private OrderHistoryNotifierInterface $orderHistoryWithShipmentDataNotifier, | ||
#[Autowire(service: OrderHistoryWithPaymentDataNotifier::class)] | ||
private OrderHistoryNotifierInterface $orderHistoryWithPaymentDataNotifier, | ||
) { | ||
} | ||
|
||
#[AsEventListener(event: 'workflow.sylius_order_checkout.completed.addressed')] | ||
public function addressed(CompletedEvent $event): void | ||
{ | ||
$order = $event->getSubject(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$this->orderHistoryWithAddressesDataNotifier->notifyEvent($order, OrderHistoryEventInterface::TYPE_CHECKOUT, 'addressed'); | ||
} | ||
|
||
#[AsEventListener(event: 'workflow.sylius_order_checkout.completed.skip_shipping')] | ||
public function shippingSkipped(CompletedEvent $event): void | ||
{ | ||
$order = $event->getSubject(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$this->orderHistoryNotifier->notifyEvent($order, OrderHistoryEventInterface::TYPE_CHECKOUT, 'shipping_skipped'); | ||
} | ||
|
||
#[AsEventListener(event: 'workflow.sylius_order_checkout.completed.select_shipping')] | ||
public function shippingSelected(CompletedEvent $event): void | ||
{ | ||
$order = $event->getSubject(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$this->orderHistoryWithShipmentDataNotifier->notifyEvent($order, OrderHistoryEventInterface::TYPE_CHECKOUT, 'shipping_selected'); | ||
} | ||
|
||
#[AsEventListener(event: 'workflow.sylius_order_checkout.completed.skip_payment')] | ||
public function paymentSkipped(CompletedEvent $event): void | ||
{ | ||
$order = $event->getSubject(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$this->orderHistoryNotifier->notifyEvent($order, OrderHistoryEventInterface::TYPE_CHECKOUT, 'payment_skipped'); | ||
} | ||
|
||
#[AsEventListener(event: 'workflow.sylius_order_checkout.completed.select_payment')] | ||
public function paymentSelected(CompletedEvent $event): void | ||
{ | ||
$order = $event->getSubject(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$this->orderHistoryWithPaymentDataNotifier->notifyEvent($order, OrderHistoryEventInterface::TYPE_CHECKOUT, 'payment_selected'); | ||
} | ||
|
||
#[AsEventListener(event: 'workflow.sylius_order_checkout.completed.complete')] | ||
public function completed(CompletedEvent $event): void | ||
{ | ||
$order = $event->getSubject(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$this->orderHistoryNotifier->notifyEvent($order, OrderHistoryEventInterface::TYPE_CHECKOUT, 'completed'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusOrderHistoryPlugin\EventListener\Workflow; | ||
|
||
use MonsieurBiz\SyliusOrderHistoryPlugin\Entity\OrderHistoryEventInterface; | ||
use MonsieurBiz\SyliusOrderHistoryPlugin\Notifier\OrderHistoryNotifier; | ||
use MonsieurBiz\SyliusOrderHistoryPlugin\Notifier\OrderHistoryNotifierInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
use Symfony\Component\Workflow\Event\CompletedEvent; | ||
|
||
final class OrderWorkflowEventListener | ||
{ | ||
public function __construct( | ||
#[Autowire(service: OrderHistoryNotifier::class)] | ||
private OrderHistoryNotifierInterface $orderHistoryNotifier, | ||
) { | ||
} | ||
|
||
#[AsEventListener(event: 'workflow.sylius_order.completed.create')] | ||
public function new(CompletedEvent $event): void | ||
{ | ||
$order = $event->getSubject(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$this->orderHistoryNotifier->notifyEvent($order, OrderHistoryEventInterface::TYPE_ORDER, 'new'); | ||
} | ||
|
||
#[AsEventListener(event: 'workflow.sylius_order.completed.cancel')] | ||
public function cancelled(CompletedEvent $event): void | ||
{ | ||
$order = $event->getSubject(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$this->orderHistoryNotifier->notifyEvent($order, OrderHistoryEventInterface::TYPE_ORDER, 'cancelled'); | ||
} | ||
|
||
#[AsEventListener(event: 'workflow.sylius_order.completed.fulfill')] | ||
public function fulfilled(CompletedEvent $event): void | ||
{ | ||
$order = $event->getSubject(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$this->orderHistoryNotifier->notifyEvent($order, OrderHistoryEventInterface::TYPE_ORDER, 'fulfilled'); | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
src/EventListener/Workflow/PaymentWorkflowEventListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusOrderHistoryPlugin\EventListener\Workflow; | ||
|
||
use MonsieurBiz\SyliusOrderHistoryPlugin\Entity\OrderHistoryEventInterface; | ||
use MonsieurBiz\SyliusOrderHistoryPlugin\Notifier\OrderHistoryNotifierInterface; | ||
use MonsieurBiz\SyliusOrderHistoryPlugin\Notifier\OrderHistoryWithPaymentDataNotifier; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\Model\PaymentInterface; | ||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
use Symfony\Component\Workflow\Event\CompletedEvent; | ||
|
||
final class PaymentWorkflowEventListener | ||
{ | ||
public function __construct( | ||
#[Autowire(service: OrderHistoryWithPaymentDataNotifier::class)] | ||
private OrderHistoryNotifierInterface $orderHistoryWithPaymentDataNotifier, | ||
) { | ||
} | ||
|
||
#[AsEventListener(event: 'workflow.sylius_payment.completed.create')] | ||
public function new(CompletedEvent $event): void | ||
{ | ||
$payment = $event->getSubject(); | ||
if (!$payment instanceof PaymentInterface) { | ||
return; | ||
} | ||
$order = $payment->getOrder(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$this->orderHistoryWithPaymentDataNotifier->notifyEvent($order, OrderHistoryEventInterface::TYPE_PAYMENT, 'new'); | ||
} | ||
|
||
#[AsEventListener(event: 'workflow.sylius_payment.completed.process')] | ||
public function processing(CompletedEvent $event): void | ||
{ | ||
$payment = $event->getSubject(); | ||
if (!$payment instanceof PaymentInterface) { | ||
return; | ||
} | ||
$order = $payment->getOrder(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$this->orderHistoryWithPaymentDataNotifier->notifyEvent($order, OrderHistoryEventInterface::TYPE_PAYMENT, 'processing'); | ||
} | ||
|
||
#[AsEventListener(event: 'workflow.sylius_payment.completed.authorize')] | ||
public function authorized(CompletedEvent $event): void | ||
{ | ||
$payment = $event->getSubject(); | ||
if (!$payment instanceof PaymentInterface) { | ||
return; | ||
} | ||
$order = $payment->getOrder(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$this->orderHistoryWithPaymentDataNotifier->notifyEvent($order, OrderHistoryEventInterface::TYPE_PAYMENT, 'authorized'); | ||
} | ||
|
||
#[AsEventListener(event: 'workflow.sylius_payment.completed.complete')] | ||
public function completed(CompletedEvent $event): void | ||
{ | ||
$payment = $event->getSubject(); | ||
if (!$payment instanceof PaymentInterface) { | ||
return; | ||
} | ||
$order = $payment->getOrder(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$this->orderHistoryWithPaymentDataNotifier->notifyEvent($order, OrderHistoryEventInterface::TYPE_PAYMENT, 'completed'); | ||
} | ||
|
||
#[AsEventListener(event: 'workflow.sylius_payment.completed.fail')] | ||
public function failed(CompletedEvent $event): void | ||
{ | ||
$payment = $event->getSubject(); | ||
if (!$payment instanceof PaymentInterface) { | ||
return; | ||
} | ||
$order = $payment->getOrder(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$this->orderHistoryWithPaymentDataNotifier->notifyEvent($order, OrderHistoryEventInterface::TYPE_PAYMENT, 'failed'); | ||
} | ||
|
||
#[AsEventListener(event: 'workflow.sylius_payment.completed.cancel')] | ||
public function cancelled(CompletedEvent $event): void | ||
{ | ||
$payment = $event->getSubject(); | ||
if (!$payment instanceof PaymentInterface) { | ||
return; | ||
} | ||
$order = $payment->getOrder(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$this->orderHistoryWithPaymentDataNotifier->notifyEvent($order, OrderHistoryEventInterface::TYPE_PAYMENT, 'cancelled'); | ||
} | ||
|
||
#[AsEventListener(event: 'workflow.sylius_payment.completed.refund')] | ||
public function refunded(CompletedEvent $event): void | ||
{ | ||
$payment = $event->getSubject(); | ||
if (!$payment instanceof PaymentInterface) { | ||
return; | ||
} | ||
$order = $payment->getOrder(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$this->orderHistoryWithPaymentDataNotifier->notifyEvent($order, OrderHistoryEventInterface::TYPE_PAYMENT, 'refunded'); | ||
} | ||
} |
Oops, something went wrong.