src/Form/EventListener/ClearCartListener.php line 25

  1. <?php
  2. namespace App\Form\EventListener;
  3. use App\Entity\Order;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\Form\FormEvent;
  6. use Symfony\Component\Form\FormEvents;
  7. class ClearCartListener implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * @inheritDoc
  11.      */
  12.     public static function getSubscribedEvents(): array
  13.     {
  14.         return [FormEvents::POST_SUBMIT => 'postSubmit'];
  15.     }
  16.     /**
  17.      * Removes all items from the cart when the clear button is clicked.
  18.      *
  19.      * @param FormEvent $event
  20.      */
  21.     public function postSubmit(FormEvent $event): void
  22.     {
  23.         $form $event->getForm();
  24.         $cart $form->getData();
  25.         if (!$cart instanceof Order) {
  26.             return;
  27.         }
  28.         // Is the clear button clicked?
  29.         //if (!$form->get('clear')->isClicked()) {
  30.          //   return;
  31.         //}
  32.         // Clears the cart
  33.        // $cart->removeOrderItems();
  34.         
  35.         
  36.     }
  37. }