src/Form/EventListener/ProcessToCheckoutListener.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Form\EventListener;
  3. use App\Entity\OrderItem;
  4. use App\Entity\Orders;
  5. use App\Manager\CartManager;
  6. use App\Storage\CartSessionStorage;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\Form\FormEvent;
  10. use Symfony\Component\Form\FormEvents;
  11. use Symfony\Component\HttpFoundation\Response;
  12. class ProcessToCheckoutListener implements EventSubscriberInterface
  13. {
  14.     public EntityManagerInterface $em;
  15.     public function __construct(EntityManagerInterface $em)
  16.     {
  17.         $this->em $em;
  18.     }
  19.     /**
  20.      * {@inheritDoc}
  21.      */
  22.     public static function getSubscribedEvents(): array
  23.     {
  24.         return [FormEvents::POST_SUBMIT => 'postSubmit'];
  25.     }
  26.     /**
  27.      * Removes all items from the cart when the clear button is clicked.
  28.      */
  29.     public function postSubmit(FormEvent $event): void
  30.     {
  31.         $form $event->getForm();
  32.         $cart $form->getData();
  33.         if (!$cart instanceof Orders) {
  34.             return;
  35.         }
  36.         // Is the clear button clicked?
  37.         if (!$form->get('save')->isClicked()) {
  38.             return;
  39.         }
  40.     }
  41. }