diff --git a/src/Controller/HandleWebhookAction.php b/src/Controller/HandleWebhookAction.php index 4431190..8ac0802 100644 --- a/src/Controller/HandleWebhookAction.php +++ b/src/Controller/HandleWebhookAction.php @@ -39,10 +39,9 @@ public function __invoke(Request $request): JsonResponse try { $webhook = $this->webhookFactory->createFromRequest($request); - $logger = new WebhookLogger($webhook); if ($this->webhookHandler instanceof LoggerAwareInterface) { - $this->webhookHandler->setLogger($logger); + $this->webhookHandler->setLogger(new WebhookLogger($webhook)); } $dataClass = WebhookParser::convertNameToDataClass($request->query->getInt('name')); diff --git a/src/Resources/config/services/webhook_handler.xml b/src/Resources/config/services/webhook_handler.xml index 832a722..85f8324 100644 --- a/src/Resources/config/services/webhook_handler.xml +++ b/src/Resources/config/services/webhook_handler.xml @@ -16,7 +16,7 @@ - + diff --git a/src/WebhookHandler/StockAdjustmentWebhookHandler.php b/src/WebhookHandler/StockAdjustmentWebhookHandler.php index 498a885..1ec094c 100644 --- a/src/WebhookHandler/StockAdjustmentWebhookHandler.php +++ b/src/WebhookHandler/StockAdjustmentWebhookHandler.php @@ -9,9 +9,8 @@ use Psr\Log\NullLogger; use Setono\PeakWMS\DataTransferObject\Webhook\WebhookDataStockAdjust; use Setono\SyliusPeakPlugin\Exception\UnsupportedWebhookException; -use Setono\SyliusPeakPlugin\Message\Command\UpdateInventory; use Setono\SyliusPeakPlugin\Provider\ProductVariantProviderInterface; -use Symfony\Component\Messenger\MessageBusInterface; +use Setono\SyliusPeakPlugin\Updater\InventoryUpdaterInterface; final class StockAdjustmentWebhookHandler implements WebhookHandlerInterface, LoggerAwareInterface { @@ -19,7 +18,7 @@ final class StockAdjustmentWebhookHandler implements WebhookHandlerInterface, Lo public function __construct( private readonly ProductVariantProviderInterface $productVariantProvider, - private readonly MessageBusInterface $commandBus, + private readonly InventoryUpdaterInterface $inventoryUpdater, ) { $this->logger = new NullLogger(); } @@ -35,9 +34,9 @@ public function handle(object $data): void throw new \InvalidArgumentException(sprintf('Product variant with id/code "%s" not found', (string) $data->variantId)); } - $this->logger->debug(sprintf('Dispatching a message onto the message to update the inventory for product variant %s', (string) $productVariant->getCode())); + $this->inventoryUpdater->update($productVariant); - $this->commandBus->dispatch(UpdateInventory::for($productVariant)); + $this->logger->debug(sprintf('Updated inventory for product variant %s', (string) $productVariant->getCode())); } /**