generated from Setono/SyliusPluginSkeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Setono/order-edit-events
Order update events
- Loading branch information
Showing
27 changed files
with
281 additions
and
88 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
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
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusOrderEditPlugin\Event; | ||
|
||
final class OrderUpdated | ||
{ | ||
public function __construct(public int $orderId) | ||
{ | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusOrderEditPlugin\Event; | ||
|
||
final class PaidOrderUpdated | ||
{ | ||
public function __construct(public int $orderId, public int $oldTotal, public int $newTotal) | ||
{ | ||
} | ||
} |
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
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
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
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
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
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
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
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
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,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusOrderEditPlugin\Updated; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Setono\SyliusOrderEditPlugin\Checker\PostUpdateChangesCheckerInterface; | ||
use Setono\SyliusOrderEditPlugin\Entity\EditableOrderInterface; | ||
use Setono\SyliusOrderEditPlugin\Event\OrderUpdated; | ||
use Setono\SyliusOrderEditPlugin\Event\PaidOrderUpdated; | ||
use Setono\SyliusOrderEditPlugin\Preparer\OrderPreparerInterface; | ||
use Setono\SyliusOrderEditPlugin\Processor\UpdatedOrderProcessorInterface; | ||
use Setono\SyliusOrderEditPlugin\Provider\UpdatedOrderProviderInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Messenger\MessageBusInterface; | ||
|
||
final class OrderUpdater implements OrderUpdaterInterface | ||
{ | ||
public function __construct( | ||
private readonly OrderPreparerInterface $oldOrderProvider, | ||
private readonly UpdatedOrderProviderInterface $updatedOrderProvider, | ||
private readonly UpdatedOrderProcessorInterface $updatedOrderProcessor, | ||
private readonly PostUpdateChangesCheckerInterface $postUpdateChangesChecker, | ||
private readonly EntityManagerInterface $entityManager, | ||
private readonly MessageBusInterface $eventBus, | ||
) { | ||
} | ||
|
||
public function update(Request $request, int $orderId): void | ||
{ | ||
$order = $this->oldOrderProvider->prepareToUpdate($orderId); | ||
/** @var EditableOrderInterface $oldOrder */ | ||
$oldOrder = clone $order; | ||
|
||
$updatedOrder = $this->updatedOrderProvider->provideFromOldOrderAndRequest($order, $request); | ||
$this->updatedOrderProcessor->process($updatedOrder); | ||
$this->postUpdateChangesChecker->check($oldOrder, $updatedOrder); | ||
$this->entityManager->flush(); | ||
|
||
$this->eventBus->dispatch(new OrderUpdated($orderId)); | ||
if ($updatedOrder->isAlreadyPaid()) { | ||
$this->eventBus->dispatch(new PaidOrderUpdated($orderId, $oldOrder->getTotal(), $updatedOrder->getTotal())); | ||
} | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusOrderEditPlugin\Updated; | ||
|
||
use Setono\SyliusOrderEditPlugin\Exception\NewOrderWrongTotalException; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
interface OrderUpdaterInterface | ||
{ | ||
/** | ||
* @throws NewOrderWrongTotalException | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function update(Request $request, int $orderId): void; | ||
} |
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
Oops, something went wrong.