<?php
namespace App\Subscribers;
use App\Doctrine\Types\CustomerType;
use App\Events\Checkout\CheckoutTypeEvent;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Contracts\EventDispatcher\Event;
class CheckoutSubscriber implements EventSubscriberInterface
{
private EntityManagerInterface $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
public static function getSubscribedEvents(): array
{
return [
CheckoutTypeEvent::NAME => [
['setUserTypeInCheckout', 10]
],
];
}
public function setUserTypeInCheckout(CheckoutTypeEvent $event): void
{
$option = $event->getOptionType();
$cart = $event->getCart();
//TODO: look in to the method inside the CartController and refactor it here. then we can create another event with a timer
// to set the expiration of the cart and redirect the user to the main checkout page where he can start filling all the details
// ultimately ensure creating the order works the same way as well. change all the set guest and the other user types to the enums.
$this->entityManager->flush();
}
}