vendor/ibexa/checkout/src/bundle/EventSubscriber/LastCheckoutStepSubscriber.php line 31

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\Checkout\EventSubscriber;
  8. use Ibexa\Contracts\Cart\CartServiceInterface;
  9. use Ibexa\Contracts\Checkout\Value\CheckoutInterface;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\Workflow\Event\CompletedEvent;
  12. final class LastCheckoutStepSubscriber implements EventSubscriberInterface
  13. {
  14. private CartServiceInterface $cartService;
  15. public function __construct(
  16. CartServiceInterface $cartService
  17. ) {
  18. $this->cartService = $cartService;
  19. }
  20. public static function getSubscribedEvents(): array
  21. {
  22. return ['workflow.completed' => 'deleteCart'];
  23. }
  24. public function deleteCart(CompletedEvent $event): void
  25. {
  26. $checkout = $event->getSubject();
  27. if (!$checkout instanceof CheckoutInterface) {
  28. return;
  29. }
  30. $placeMetadata = $event->getWorkflow()->getMetadataStore()->getPlaceMetadata($checkout->getStatus());
  31. if (!array_key_exists('is_final_step', $placeMetadata) || $placeMetadata['is_final_step'] !== true) {
  32. return;
  33. }
  34. $this->cartService->deleteCart(
  35. $this->cartService->getCart($checkout->getCartIdentifier())
  36. );
  37. }
  38. }