<?php
namespace App\Controller\Frontend;
use App\Business\Cart\Session\CartSessionHandlerInterface;
use App\Business\Sponsor\SponsorFacadeInterface;
use App\Entity\Sponsor;
use App\Form\Frontend\SponsorType;
use App\Service\Utils\CustomerServiceInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class CheckoutController extends AbstractController
{
private CartSessionHandlerInterface $cartSessionHandler;
private CustomerServiceInterface $customerService;
/**
* @param CartSessionHandlerInterface $cartSessionHandler
* @param CustomerServiceInterface $customerService
*/
public function __construct(
CartSessionHandlerInterface $cartSessionHandler,
CustomerServiceInterface $customerService
) {
$this->cartSessionHandler = $cartSessionHandler;
$this->customerService = $customerService;
}
#[Route('/checkout', name: 'app_frontend_checkout')]
public function checkout(Request $request, SponsorFacadeInterface $sponsorFacade): Response
{
$form = $this->createForm(SponsorType::class, $sponsor = new Sponsor(), [
'customer' => $this->customerService->getCustomer(),
])->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if ($this->cartSessionHandler->getItems()->count() === 0) {
$this->addFlash('danker', 'Bei der Buchung ist ein Fehler aufgetreten, bitte probieren Sie es erneut');
return $this->redirectToRoute('app_frontend_index');
}
$sponsorFacade->frontendBooking($sponsor, $form);
return $this->redirectToRoute('app_frontend_checkout_orderplaced');
}
return $this->render('frontend/checkout/checkout.html.twig', [
'form' => $form->createView(),
'areas' => $this->cartSessionHandler->getItems(true)
]);
}
/**
* @return Response
*/
#[Route('/checkout/order-placed', name: 'app_frontend_checkout_orderplaced')]
public function orderPlaced(): Response
{
return $this->render('frontend/checkout/order-placed.twig');
}
}