Skip to content

Commit

Permalink
Handle cancelled order scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Aug 29, 2024
1 parent 94b6cd4 commit be847dc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Message/CommandHandler/ProcessUploadOrderRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

namespace Setono\SyliusPeakPlugin\Message\CommandHandler;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use Setono\Doctrine\ORMTrait;
use Setono\PeakWMS\Client\ClientInterface;
use Setono\PeakWMS\DataTransferObject\SalesOrder\SalesOrder;
use Setono\SyliusPeakPlugin\DataMapper\SalesOrder\SalesOrderDataMapperInterface;
use Setono\SyliusPeakPlugin\Message\Command\ProcessUploadOrderRequest;
use Setono\SyliusPeakPlugin\Model\OrderInterface;
use Setono\SyliusPeakPlugin\Model\UploadOrderRequestInterface;
use Setono\SyliusPeakPlugin\Workflow\UploadOrderRequestWorkflow;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
Expand Down Expand Up @@ -50,6 +52,27 @@ public function __invoke(ProcessUploadOrderRequest $message): void
throw new UnrecoverableMessageHandlingException(sprintf('The upload order request with id %d does not have an associated order', $message->uploadOrderRequest));
}

match ($order->getState()) {
OrderInterface::STATE_CANCELLED => $this->handleCancelledState($order, $uploadOrderRequest),
default => $this->handleOtherStates($message, $manager, $order, $uploadOrderRequest),
};
}

public function handleCancelledState(OrderInterface $order, UploadOrderRequestInterface $uploadOrderRequest): void
{
if ($uploadOrderRequest->getPeakOrderId() === null) {
return;
}

$this->peakClient->salesOrder()->cancel((string) $order->getId());
}

private function handleOtherStates(
ProcessUploadOrderRequest $message,
EntityManagerInterface $manager,
OrderInterface $order,
UploadOrderRequestInterface $uploadOrderRequest,
): void {
try {
$salesOrder = new SalesOrder();
$this->salesOrderDataMapper->map($order, $salesOrder);
Expand Down

0 comments on commit be847dc

Please sign in to comment.