src/Subscribers/CheckoutSubscriber.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Subscribers;
  3. use App\Doctrine\Types\CustomerType;
  4. use App\Events\Checkout\CheckoutTypeEvent;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Contracts\EventDispatcher\Event;
  8. class CheckoutSubscriber implements EventSubscriberInterface
  9. {
  10. private EntityManagerInterface $entityManager;
  11. public function __construct(EntityManagerInterface $entityManager)
  12. {
  13. $this->entityManager = $entityManager;
  14. }
  15. public static function getSubscribedEvents(): array
  16. {
  17. return [
  18. CheckoutTypeEvent::NAME => [
  19. ['setUserTypeInCheckout', 10]
  20. ],
  21. ];
  22. }
  23. public function setUserTypeInCheckout(CheckoutTypeEvent $event): void
  24. {
  25. $option = $event->getOptionType();
  26. $cart = $event->getCart();
  27. //TODO: look in to the method inside the CartController and refactor it here. then we can create another event with a timer
  28. // to set the expiration of the cart and redirect the user to the main checkout page where he can start filling all the details
  29. // ultimately ensure creating the order works the same way as well. change all the set guest and the other user types to the enums.
  30. $this->entityManager->flush();
  31. }
  32. }