src/Controller/Peaj/PeajController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Peaj;
  3. use App\Controller\BaseController;
  4. use App\Entity\Order\Order;
  5. use App\Entity\Peaj\Category;
  6. use App\Entity\Peaj\Peaj;
  7. use App\Manager\BitbagStatic\BlockManager;
  8. use App\Manager\Cart\CartManager;
  9. use App\Manager\CountryManager;
  10. use App\Manager\Partner\PartnerManager;
  11. use App\Manager\Peaj\PeajManager;
  12. use App\Service\AuthTokenService;
  13. use App\Service\StaticPagesBitbagService;
  14. use BitBag\SyliusCmsPlugin\Entity\Page;
  15. use Symfony\Component\HttpFoundation\JsonResponse;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  19. class PeajController extends BaseController
  20. {
  21.     public function indexAction(Request $request): Response
  22.     {
  23.         $locale $request->getLocale();
  24.         $categories $this->getEntityManager()->getRepository(Category::class)
  25.             ->findAllAsArray($this->getContainer()->get('translator'));
  26.         $countries CountryManager::getActiveCountriesForRoVignette($this->getEntityManager());
  27.         $pageRepository $this->getEntityManager()->getRepository(Page::class);
  28.         $companyServicesPeajPage $pageRepository->findOneEnabledByCode('company-services-peaj'$locale);
  29.         $aboutPeaj StaticPagesBitbagService::getAllFilteredBlocks($this->getEntityManager(), BlockManager::BLOCK_ACCORDION_TEXT_PEAJ_CODE_PATTERN);
  30.         return $this->render('@templates/Front/Peaj/index.html.twig', [
  31.             'categories' => $categories,
  32.             'countries' => $countries,
  33.             'accordionBlocksAboutPeaj' => $aboutPeaj,
  34.             'companyServicesPeajPage' => $companyServicesPeajPage,
  35.             'number_of_passes' => $this->getContainer()->get('app.service.peaj.peaj')->getDefaultNumberOfPasses(),
  36.         ]);
  37.     }
  38.     public function submitData(Request $request): Response
  39.     {
  40.         $peajService $this->getContainer()->get('app.service.peaj.peaj');
  41.         if ($errors $peajService->validate($request->request->all())) {
  42.             return $this->json(['violations' => $errors]);
  43.         }
  44.         $response $peajService->storeNewPeajInCart($requestPeaj::FLAG_SOURCE_PRODUCT_PAGE);
  45.         $params = [];
  46.         if ($request->get('publicToken')) {
  47.             $params['publicToken'] = $request->get('publicToken');
  48.         }
  49.         $response['redirectUrl'] = $this->generateUrl('app_shop_customer_info'$params);
  50.         return new JsonResponse($response);
  51.     }
  52.     public function iframeAction(Request $request): Response
  53.     {
  54.         $partnerService $this->getContainer()->get('app.service.partner.partner');
  55.         $partnerService->verifyToken($requestPartnerManager::CAN_ISSUE_PEAJ_INDEX);
  56.         $partner $partnerService->retrievePartner($request->get('partnerPublicToken'));
  57.         $request->getSession()->set('iframeSourceLink'$this->generateUrl('app_shop_peaj_iframe', [
  58.             'partnerPublicToken' => $partner->getPublicToken()
  59.         ]));
  60.         PartnerManager::checkQRCodeFlow($request);
  61.         $categories $this->getEntityManager()->getRepository(Category::class)
  62.             ->findAllAsArray($this->getContainer()->get('translator'));
  63.         $countries CountryManager::getActiveCountriesForRoVignette($this->getEntityManager());
  64.         return $this->render('@templates/Front/Peaj/iframe.html.twig', [
  65.             'iframe' => true,
  66.             'publicToken' => $partner->getPublicToken(),
  67.             'categories' => $categories,
  68.             'countries' => $countries,
  69.             'number_of_passes' => $this->getContainer()->get('app.service.peaj.peaj')->getDefaultNumberOfPasses(),
  70.         ]);
  71.     }
  72.     public function addToCartById(Order $orderRequest $request): Response
  73.     {
  74.         $clientIp $request->getClientIp();
  75.         $session $request->getSession();
  76.         foreach ($order->getPeaj() as $peaj) {
  77.             if (!PeajManager::isPeajAlreadyInCart($session$peaj->getRegistrationPlate())) {
  78.                 $cartItem PeajManager::constructPeajForCartFromObject(
  79.                     $peaj$clientIpPeaj::FLAG_SOURCE_REMARKETING
  80.                 );
  81.                 CartManager::setToCart($sessionCartManager::PEAJ_PRODUCT_NAME, [$cartItem]);
  82.             }
  83.         }
  84.         $authTokenService = new AuthTokenService();
  85.         if ($token $authTokenService->authenticateUserWithToken($request$this->getEntityManager())) {
  86.             $this->get('security.token_storage')->setToken($token);
  87.             $event = new InteractiveLoginEvent($request$token);
  88.             $this->dispatcher->dispatch($event'security.interactive_login');
  89.             $session $request->getSession();
  90.             $session->set('_sylius.cart.FASHION_WEB'180);
  91.             $session->save();
  92.         }
  93.         $utm = [
  94.             'utm_source' => $request->get('utm_source'),
  95.             'utm_medium' => $request->get('utm_medium'),
  96.             'utm_campaign' => $request->get('utm_campaign'),
  97.             'utm_term' => $request->get('utm_term'),
  98.             'utm_content' => $request->get('utm_content'),
  99.             'utm_id' => $request->get('utm_id')
  100.         ];
  101.         return $this->render('@templates/ShopCustom/Redirect/wait_to_be_redirected.html.twig', [
  102.             'url' => $this->generateUrl('app_shop_customer_info'$utm)
  103.         ]);
  104.     }
  105.     public function removeFromCart(Request $request): Response
  106.     {
  107.         $peajService $this->getContainer()->get('app.service.peaj.peaj');
  108.         $result $peajService->removePeajFromCartSessionByRegistrationPlate($request$request->get('registrationPlate'));
  109.         return new Response(json_encode(array('result' => $result)));
  110.     }
  111.     public function findNumberOfPassesByCategory(Request $request): JsonResponse
  112.     {
  113.         $categoryRepo $this->getEntityManager()->getRepository(Category::class);
  114.         if (!($categoryId $request->get('category_id')) || !($category $categoryRepo->find($categoryId))) {
  115.             return $this->json(['success' => false]);
  116.         }
  117.         $prices $category->getPrices();
  118.         $numberOfPasses = [];
  119.         foreach ($prices as $key => $price) {
  120.             $availability $price->getAvailability();
  121.             $numberOfPasses[$key] = [
  122.                 'name' => str_replace(' pod Fetesti'''$availability->getName()),
  123.                 'price_id' => $price->getId(),
  124.                 'price' => $price->getCustomerPrice(),
  125.                 'currency' => $price->getCustomerCurrency(),
  126.                 'quantity' => $availability->getQuantity(),
  127.                 'available' => $availability->getMonthsAvailable(),
  128.                 'availability_id' => $availability->getId(),
  129.             ];
  130.         }
  131.         return $this->json(['success' => true'number_of_passes' => $numberOfPasses]);
  132.     }
  133. }