<?php
namespace App\Controller\RoadAssistance;
use App\Controller\BaseController;
use App\Entity\RoadAssistance\RoadAssistance;
use App\Manager\Partner\PartnerManager;
use App\Entity\Order\Order;
use App\Manager\Cart\CartManager;
use App\Service\AuthTokenService;
use App\Manager\RoadAssistance\RoadAssistanceManager;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
class RoadAssistanceController extends BaseController
{
public function indexAction(): Response
{
return $this->render('@templates/Front/RoadAssistance/index.html.twig', [
'productPrice' => RoadAssistance::SELL_PRICE
]);
}
public function submitData(Request $request): Response
{
$response = $this->getContainer()->get('app.service.road_assistance.road_assistance')
->storeNewRoadAssistanceInCart(RoadAssistance::FLAG_SOURCE_PRODUCT_PAGE);
return new JsonResponse($response);
}
/**
* @param Request $request
* @return Response
*/
public function removeFromCart(Request $request): Response
{
$roadAssistanceService = $this->getContainer()->get('app.service.road_assistance.road_assistance');
$result = $roadAssistanceService->removeRoadAssistanceFromCartSessionByRegistrationPlate($request->get('registrationPlate'));
return new Response(json_encode(array('result' => $result)));
}
public function checkAlreadyActive(Request $request): Response
{
$roadAssistanceService = $this->getContainer()->get('app.service.road_assistance.road_assistance');
return new Response(json_encode(array('isActive' => $roadAssistanceService->isAlreadyActiveForRegistrationPlateAndValidFrom($request->request->all()))));
}
public function iframe(Request $request): Response
{
$partnerService = $this->getContainer()->get('app.service.partner.partner');
$partnerService->verifyToken($request, PartnerManager::CAN_ISSUE_ROAD_ASSISTANCE_INDEX);
$partner = $partnerService->retrievePartner($request->get('partnerPublicToken'));
$request->getSession()->set('iframeSourceLink', $this->generateUrl('app_shop_road_assistance_iframe', [
'partnerPublicToken' => $partner->getPublicToken()
]));
PartnerManager::checkQRCodeFlow($request);
return $this->render('@templates/Front/RoadAssistance/iframe.html.twig', [
'productPrice' => RoadAssistance::SELL_PRICE,
'publicToken' => $partner->getPublicToken()
]);
}
public function addToCartById(Order $order, Request $request): Response
{
$clientIp = $request->getClientIp();
$session = $request->getSession();
foreach ($order->getRoadAssistance() as $roadAssistance) {
if (!RoadAssistanceManager::isRoadAssistanceAlreadyInCart($session, $roadAssistance->getRegistrationPlate())) {
$cartItem = RoadAssistanceManager::constructRoadAssistanceForCartFromObject(
$roadAssistance, $clientIp, RoadAssistance::FLAG_SOURCE_REMARKETING
);
CartManager::setToCart($session, CartManager::ROAD_ASSISTANCE_PRODUCT_NAME, [$cartItem]);
}
}
$authTokenService = new AuthTokenService();
if ($token = $authTokenService->authenticateUserWithToken($request, $this->getEntityManager())) {
$this->get('security.token_storage')->setToken($token);
$event = new InteractiveLoginEvent($request, $token);
$this->dispatcher->dispatch($event, 'security.interactive_login');
$session = $request->getSession();
$session->set('_sylius.cart.FASHION_WEB', 180);
$session->save();
}
$utm = [
'utm_source' => $request->get('utm_source'),
'utm_medium' => $request->get('utm_medium'),
'utm_campaign' => $request->get('utm_campaign'),
'utm_term' => $request->get('utm_term'),
'utm_content' => $request->get('utm_content'),
'utm_id' => $request->get('utm_id')
];
return $this->render('@templates/ShopCustom/Redirect/wait_to_be_redirected.html.twig',[
'url' => $this->generateUrl('app_shop_customer_info', $utm)
]);
}
}