<?php
namespace App\Form\EventListener;
use App\Entity\OrderItem;
use App\Entity\Orders;
use App\Manager\CartManager;
use App\Storage\CartSessionStorage;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\HttpFoundation\Response;
class ProcessToCheckoutListener implements EventSubscriberInterface
{
public EntityManagerInterface $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents(): array
{
return [FormEvents::POST_SUBMIT => 'postSubmit'];
}
/**
* Removes all items from the cart when the clear button is clicked.
*/
public function postSubmit(FormEvent $event): void
{
$form = $event->getForm();
$cart = $form->getData();
if (!$cart instanceof Orders) {
return;
}
// Is the clear button clicked?
if (!$form->get('save')->isClicked()) {
return;
}
}
}