-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add order callbacks for symfony workflow
- Loading branch information
Showing
32 changed files
with
1,429 additions
and
2 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/Sylius/Bundle/CoreBundle/EventListener/Workflow/Order/AssignOrderNumberListener.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,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\CoreBundle\EventListener\Workflow\Order; | ||
|
||
use Sylius\Bundle\OrderBundle\NumberAssigner\OrderNumberAssignerInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Symfony\Component\Workflow\Event\TransitionEvent; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class AssignOrderNumberListener | ||
{ | ||
public function __construct(private OrderNumberAssignerInterface $orderNumberAssigner) | ||
{ | ||
} | ||
|
||
public function __invoke(TransitionEvent $event): void | ||
{ | ||
/** @var OrderInterface $order */ | ||
$order = $event->getSubject(); | ||
Assert::isInstanceOf($order, OrderInterface::class); | ||
|
||
$this->orderNumberAssigner->assignNumber($order); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Sylius/Bundle/CoreBundle/EventListener/Workflow/Order/AssignOrderTokenListener.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,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\CoreBundle\EventListener\Workflow\Order; | ||
|
||
use Sylius\Bundle\OrderBundle\NumberAssigner\OrderNumberAssignerInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\TokenAssigner\OrderTokenAssignerInterface; | ||
use Symfony\Component\Workflow\Event\TransitionEvent; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class AssignOrderTokenListener | ||
{ | ||
public function __construct(private OrderTokenAssignerInterface $orderTokenAssigner) | ||
{ | ||
} | ||
|
||
public function __invoke(TransitionEvent $event): void | ||
{ | ||
/** @var OrderInterface $order */ | ||
$order = $event->getSubject(); | ||
Assert::isInstanceOf($order, OrderInterface::class); | ||
|
||
$this->orderTokenAssigner->assignTokenValueIfNotSet($order); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/Sylius/Bundle/CoreBundle/EventListener/Workflow/Order/CancelOrderListener.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,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\CoreBundle\EventListener\Workflow\Order; | ||
|
||
use Sylius\Bundle\CoreBundle\StateMachine\StateMachineInterface; | ||
use Sylius\Component\Core\Inventory\Operator\OrderInventoryOperatorInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Shipping\ShipmentTransitions; | ||
use Symfony\Component\Workflow\Event\CompletedEvent; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class CancelOrderListener | ||
{ | ||
public function __construct(private OrderInventoryOperatorInterface $orderInventoryOperator) | ||
{ | ||
} | ||
|
||
public function __invoke(CompletedEvent $event): void | ||
{ | ||
/** @var OrderInterface $order */ | ||
$order = $event->getSubject(); | ||
Assert::isInstanceOf($order, OrderInterface::class); | ||
|
||
$this->orderInventoryOperator->cancel($order); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/Sylius/Bundle/CoreBundle/EventListener/Workflow/Order/CancelOrderPaymentListener.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,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\CoreBundle\EventListener\Workflow\Order; | ||
|
||
use Sylius\Bundle\CoreBundle\StateMachine\StateMachineInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\OrderPaymentTransitions; | ||
use Sylius\Component\Payment\PaymentTransitions; | ||
use Symfony\Component\Workflow\Event\CompletedEvent; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class CancelOrderPaymentListener | ||
{ | ||
public function __construct(private StateMachineInterface $compositeOrderStateMachine) | ||
{ | ||
} | ||
|
||
public function __invoke(CompletedEvent $event): void | ||
{ | ||
/** @var OrderInterface $order */ | ||
$order = $event->getSubject(); | ||
Assert::isInstanceOf($order, OrderInterface::class); | ||
|
||
$this->compositeOrderStateMachine->apply($order, OrderPaymentTransitions::GRAPH, OrderPaymentTransitions::TRANSITION_CANCEL); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Sylius/Bundle/CoreBundle/EventListener/Workflow/Order/CancelOrderShippingListener.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,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\CoreBundle\EventListener\Workflow\Order; | ||
|
||
use Sylius\Bundle\CoreBundle\StateMachine\StateMachineInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\OrderPaymentTransitions; | ||
use Sylius\Component\Core\OrderShippingTransitions; | ||
use Sylius\Component\Payment\PaymentTransitions; | ||
use Symfony\Component\Workflow\Event\CompletedEvent; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class CancelOrderShippingListener | ||
{ | ||
public function __construct(private StateMachineInterface $compositeOrderStateMachine) | ||
{ | ||
} | ||
|
||
public function __invoke(CompletedEvent $event): void | ||
{ | ||
/** @var OrderInterface $order */ | ||
$order = $event->getSubject(); | ||
Assert::isInstanceOf($order, OrderInterface::class); | ||
|
||
$this->compositeOrderStateMachine->apply($order, OrderShippingTransitions::GRAPH, OrderShippingTransitions::TRANSITION_CANCEL); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Sylius/Bundle/CoreBundle/EventListener/Workflow/Order/CancelPaymentListener.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,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\CoreBundle\EventListener\Workflow\Order; | ||
|
||
use Sylius\Bundle\CoreBundle\StateMachine\StateMachineInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Payment\PaymentTransitions; | ||
use Symfony\Component\Workflow\Event\CompletedEvent; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class CancelPaymentListener | ||
{ | ||
public function __construct(private StateMachineInterface $compositeOrderStateMachine) | ||
{ | ||
} | ||
|
||
public function __invoke(CompletedEvent $event): void | ||
{ | ||
/** @var OrderInterface $order */ | ||
$order = $event->getSubject(); | ||
Assert::isInstanceOf($order, OrderInterface::class); | ||
|
||
$payments = $order->getPayments(); | ||
|
||
foreach ($payments as $payment) { | ||
$this->compositeOrderStateMachine->apply($payment,PaymentTransitions::GRAPH, PaymentTransitions::TRANSITION_CANCEL); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Sylius/Bundle/CoreBundle/EventListener/Workflow/Order/CancelShipmentListener.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,41 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\CoreBundle\EventListener\Workflow\Order; | ||
|
||
use Sylius\Bundle\CoreBundle\StateMachine\StateMachineInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Payment\PaymentTransitions; | ||
use Sylius\Component\Shipping\ShipmentTransitions; | ||
use Symfony\Component\Workflow\Event\CompletedEvent; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class CancelShipmentListener | ||
{ | ||
public function __construct(private StateMachineInterface $compositeOrderStateMachine) | ||
{ | ||
} | ||
|
||
public function __invoke(CompletedEvent $event): void | ||
{ | ||
/** @var OrderInterface $order */ | ||
$order = $event->getSubject(); | ||
Assert::isInstanceOf($order, OrderInterface::class); | ||
|
||
$shipments = $order->getShipments(); | ||
|
||
foreach ($shipments as $shipment) { | ||
$this->compositeOrderStateMachine->apply($shipment,ShipmentTransitions::GRAPH, ShipmentTransitions::TRANSITION_CANCEL); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/Sylius/Bundle/CoreBundle/EventListener/Workflow/Order/CreatePaymentListener.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,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\CoreBundle\EventListener\Workflow\Order; | ||
|
||
use Sylius\Bundle\CoreBundle\StateMachine\StateMachineInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\OrderPaymentTransitions; | ||
use Sylius\Component\Core\OrderShippingTransitions; | ||
use Sylius\Component\Payment\PaymentTransitions; | ||
use Symfony\Component\Workflow\Event\CompletedEvent; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class CreatePaymentListener | ||
{ | ||
public function __construct(private StateMachineInterface $compositeStateMachine) | ||
{ | ||
} | ||
|
||
public function __invoke(CompletedEvent $event): void | ||
{ | ||
/** @var OrderInterface $order */ | ||
$order = $event->getSubject(); | ||
Assert::isInstanceOf($order, OrderInterface::class); | ||
|
||
$payments = $order->getPayments(); | ||
|
||
foreach ($payments as $payment) | ||
{ | ||
$this->compositeStateMachine->apply($payment, PaymentTransitions::GRAPH, PaymentTransitions::TRANSITION_CREATE); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Sylius/Bundle/CoreBundle/EventListener/Workflow/Order/CreateShipmentListener.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,41 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\CoreBundle\EventListener\Workflow\Order; | ||
|
||
use Sylius\Bundle\CoreBundle\StateMachine\StateMachineInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Shipping\ShipmentTransitions; | ||
use Symfony\Component\Workflow\Event\CompletedEvent; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class CreateShipmentListener | ||
{ | ||
public function __construct(private StateMachineInterface $compositeStateMachine) | ||
{ | ||
} | ||
|
||
public function __invoke(CompletedEvent $event): void | ||
{ | ||
/** @var OrderInterface $order */ | ||
$order = $event->getSubject(); | ||
Assert::isInstanceOf($order, OrderInterface::class); | ||
|
||
$shipments = $order->getShipments(); | ||
|
||
foreach ($shipments as $shipment) | ||
{ | ||
$this->compositeStateMachine->apply($shipment, ShipmentTransitions::GRAPH, ShipmentTransitions::TRANSITION_CREATE); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ylius/Bundle/CoreBundle/EventListener/Workflow/Order/DecrementPromotionUsagesListener.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,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\CoreBundle\EventListener\Workflow\Order; | ||
|
||
use Sylius\Component\Core\Inventory\Operator\OrderInventoryOperatorInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\Promotion\Modifier\OrderPromotionsUsageModifierInterface; | ||
use Symfony\Component\Workflow\Event\CompletedEvent; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class DecrementPromotionUsagesListener | ||
{ | ||
public function __construct(private OrderPromotionsUsageModifierInterface $orderPromotionsUsageModifier) | ||
{ | ||
} | ||
|
||
public function __invoke(CompletedEvent $event): void | ||
{ | ||
/** @var OrderInterface $order */ | ||
$order = $event->getSubject(); | ||
Assert::isInstanceOf($order, OrderInterface::class); | ||
|
||
$this->orderPromotionsUsageModifier->decrement($order); | ||
} | ||
} |
Oops, something went wrong.