src/Controller/Frontend/CheckoutController.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Frontend;
  3. use App\Business\Cart\Session\CartSessionHandlerInterface;
  4. use App\Business\Sponsor\SponsorFacadeInterface;
  5. use App\Entity\Sponsor;
  6. use App\Form\Frontend\SponsorType;
  7. use App\Service\Utils\CustomerServiceInterface;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. class CheckoutController extends AbstractController
  13. {
  14.     private CartSessionHandlerInterface $cartSessionHandler;
  15.     private CustomerServiceInterface $customerService;
  16.     /**
  17.      * @param CartSessionHandlerInterface $cartSessionHandler
  18.      * @param CustomerServiceInterface $customerService
  19.      */
  20.     public function __construct(
  21.         CartSessionHandlerInterface $cartSessionHandler,
  22.         CustomerServiceInterface $customerService
  23.     ) {
  24.         $this->cartSessionHandler $cartSessionHandler;
  25.         $this->customerService $customerService;
  26.     }
  27.     #[Route('/checkout'name'app_frontend_checkout')]
  28.     public function checkout(Request $requestSponsorFacadeInterface $sponsorFacade): Response
  29.     {
  30.         $form $this->createForm(SponsorType::class, $sponsor = new Sponsor(), [
  31.             'customer' => $this->customerService->getCustomer(),
  32.         ])->handleRequest($request);
  33.         if ($form->isSubmitted() && $form->isValid()) {
  34.             if ($this->cartSessionHandler->getItems()->count() === 0) {
  35.                 $this->addFlash('danker''Bei der Buchung ist ein Fehler aufgetreten, bitte probieren Sie es erneut');
  36.                 return $this->redirectToRoute('app_frontend_index');
  37.             }
  38.             $sponsorFacade->frontendBooking($sponsor$form);
  39.             return $this->redirectToRoute('app_frontend_checkout_orderplaced');
  40.         }
  41.         return $this->render('frontend/checkout/checkout.html.twig', [
  42.             'form' => $form->createView(),
  43.             'areas' => $this->cartSessionHandler->getItems(true)
  44.         ]);
  45.     }
  46.     /**
  47.      * @return Response
  48.      */
  49.     #[Route('/checkout/order-placed'name'app_frontend_checkout_orderplaced')]
  50.     public function orderPlaced(): Response
  51.     {
  52.         return $this->render('frontend/checkout/order-placed.twig');
  53.     }
  54. }