vendor/ibexa/order-management/src/bundle/EventSubscriber/StockRestoringSubscriber.php line 38

Open in your IDE?
  1. <?php
  2. /**
  3. * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4. * @license For full copyright and license information view LICENSE file distributed with this source code.
  5. */
  6. declare(strict_types=1);
  7. namespace Ibexa\Bundle\OrderManagement\EventSubscriber;
  8. use Ibexa\Contracts\OrderManagement\Value\Order\OrderInterface;
  9. use Ibexa\OrderManagement\Stock\StockManagerInterface;
  10. use Ibexa\OrderManagement\Workflow\WorkflowCoordinator;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\Workflow\Event\Event;
  13. final class StockRestoringSubscriber implements EventSubscriberInterface
  14. {
  15. private WorkflowCoordinator $workflowCoordinator;
  16. private StockManagerInterface $stockManager;
  17. public function __construct(
  18. WorkflowCoordinator $workflowCoordinator,
  19. StockManagerInterface $stockManager
  20. ) {
  21. $this->workflowCoordinator = $workflowCoordinator;
  22. $this->stockManager = $stockManager;
  23. }
  24. public static function getSubscribedEvents(): array
  25. {
  26. return [
  27. 'workflow.entered' => 'onEntered',
  28. ];
  29. }
  30. public function onEntered(Event $event): void
  31. {
  32. $order = $event->getSubject();
  33. if (!$order instanceof OrderInterface) {
  34. return;
  35. }
  36. $restoreStockParameter = $this->workflowCoordinator->getPlaceMetadataParameter(
  37. $order,
  38. $order->getStatus(),
  39. WorkflowCoordinator::RESTORE_STOCK_METADATA_PARAMETER
  40. );
  41. if ($restoreStockParameter === true) {
  42. $this->stockManager->restore($order);
  43. }
  44. }
  45. }