src/Controller/RoadAssistance/RoadAssistanceController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller\RoadAssistance;
  3. use App\Controller\BaseController;
  4. use App\Entity\RoadAssistance\RoadAssistance;
  5. use App\Manager\Partner\PartnerManager;
  6. use App\Entity\Order\Order;
  7. use App\Manager\Cart\CartManager;
  8. use App\Service\AuthTokenService;
  9. use App\Manager\RoadAssistance\RoadAssistanceManager;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  14. class RoadAssistanceController extends BaseController
  15. {
  16.     public function indexAction(): Response
  17.     {
  18.         return $this->render('@templates/Front/RoadAssistance/index.html.twig', [
  19.             'productPrice' => RoadAssistance::SELL_PRICE
  20.         ]);
  21.     }
  22.     public function submitData(Request $request): Response
  23.     {
  24.         $response $this->getContainer()->get('app.service.road_assistance.road_assistance')
  25.             ->storeNewRoadAssistanceInCart(RoadAssistance::FLAG_SOURCE_PRODUCT_PAGE);
  26.         return new JsonResponse($response);
  27.     }
  28.     /**
  29.      * @param Request $request
  30.      * @return Response
  31.      */
  32.     public function removeFromCart(Request $request): Response
  33.     {
  34.         $roadAssistanceService $this->getContainer()->get('app.service.road_assistance.road_assistance');
  35.         $result $roadAssistanceService->removeRoadAssistanceFromCartSessionByRegistrationPlate($request->get('registrationPlate'));
  36.         return new Response(json_encode(array('result' => $result)));
  37.     }
  38.     public function checkAlreadyActive(Request $request): Response
  39.     {
  40.         $roadAssistanceService $this->getContainer()->get('app.service.road_assistance.road_assistance');
  41.         
  42.         return new Response(json_encode(array('isActive' => $roadAssistanceService->isAlreadyActiveForRegistrationPlateAndValidFrom($request->request->all()))));
  43.     }
  44.     public function iframe(Request $request): Response
  45.     {
  46.         $partnerService $this->getContainer()->get('app.service.partner.partner');
  47.         $partnerService->verifyToken($requestPartnerManager::CAN_ISSUE_ROAD_ASSISTANCE_INDEX);
  48.         $partner $partnerService->retrievePartner($request->get('partnerPublicToken'));
  49.         $request->getSession()->set('iframeSourceLink'$this->generateUrl('app_shop_road_assistance_iframe', [
  50.             'partnerPublicToken' => $partner->getPublicToken()
  51.         ]));
  52.         PartnerManager::checkQRCodeFlow($request);
  53.         return $this->render('@templates/Front/RoadAssistance/iframe.html.twig', [
  54.             'productPrice' => RoadAssistance::SELL_PRICE,
  55.             'publicToken' => $partner->getPublicToken()
  56.         ]);
  57.     }
  58.     public function addToCartById(Order $orderRequest $request): Response
  59.     {
  60.         $clientIp $request->getClientIp();
  61.         $session $request->getSession();
  62.         foreach ($order->getRoadAssistance() as $roadAssistance) {
  63.             if (!RoadAssistanceManager::isRoadAssistanceAlreadyInCart($session$roadAssistance->getRegistrationPlate())) {
  64.                 $cartItem RoadAssistanceManager::constructRoadAssistanceForCartFromObject(
  65.                     $roadAssistance$clientIpRoadAssistance::FLAG_SOURCE_REMARKETING
  66.                 );
  67.                 CartManager::setToCart($sessionCartManager::ROAD_ASSISTANCE_PRODUCT_NAME, [$cartItem]);
  68.             }
  69.         }
  70.         $authTokenService = new AuthTokenService();
  71.         if ($token $authTokenService->authenticateUserWithToken($request$this->getEntityManager())) {
  72.             $this->get('security.token_storage')->setToken($token);
  73.             $event = new InteractiveLoginEvent($request$token);
  74.             $this->dispatcher->dispatch($event'security.interactive_login');
  75.             $session $request->getSession();
  76.             $session->set('_sylius.cart.FASHION_WEB'180);
  77.             $session->save();
  78.         }
  79.         $utm = [
  80.             'utm_source' => $request->get('utm_source'),
  81.             'utm_medium' => $request->get('utm_medium'),
  82.             'utm_campaign' => $request->get('utm_campaign'),
  83.             'utm_term' => $request->get('utm_term'),
  84.             'utm_content' => $request->get('utm_content'),
  85.             'utm_id' => $request->get('utm_id')
  86.         ];
  87.         return $this->render('@templates/ShopCustom/Redirect/wait_to_be_redirected.html.twig',[
  88.             'url' => $this->generateUrl('app_shop_customer_info'$utm)
  89.         ]);
  90.     }
  91. }