src/Controller/LicenseRecovery/LicenseRecoveryController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller\LicenseRecovery;
  3. use App\Controller\BaseController;
  4. use App\Entity\LicenseRecovery\LicenseRecovery;
  5. use App\Entity\Order\Order;
  6. use App\Entity\VignetteInvoice\VignetteInvoice;
  7. use App\Manager\BitbagStatic\BlockManager;
  8. use App\Manager\Cart\CartManager;
  9. use App\Manager\LicenseRecovery\LicenseRecoveryManager;
  10. use App\Manager\Partner\PartnerManager;
  11. use App\Service\AuthTokenService;
  12. use App\Service\InvoiceApiService;
  13. use App\Service\InvoiceService;
  14. use App\Service\StaticPagesBitbagService;
  15. use App\Service\SystemService;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  19. class LicenseRecoveryController extends BaseController
  20. {
  21.     public function indexAction(): Response
  22.     {
  23.         return $this->render('@templates/Front/LicenseRecovery/license-recovery.html.twig', [
  24.             'accordionBlocksFaq' => StaticPagesBitbagService::getAllFilteredBlocks($this->getEntityManager(), BlockManager::BLOCK_ACCORDION_TEXT_LICENSE_RECOVERY_CODE_PATTERN),
  25.             'keywordsForSeo' => StaticPagesBitbagService::getFirstFilteredBlocks($this->getEntityManager(), BlockManager::BLOCK_SEO_META_LICENSE_RECOVERY_KEYWORD_CODE_PATTERN),
  26.             'descriptionForSeo' => StaticPagesBitbagService::getFirstFilteredBlocks($this->getEntityManager(), BlockManager::BLOCK_SEO_META_LICENSE_RECOVERY_DESCRIPTION_CODE_PATTERN)
  27.         ]);
  28.     }
  29.     public function submitData(): Response
  30.     {
  31.         $licenseRecoveryResponse $this->getContainer()->get('app.service.license_recovery.license_recovery')
  32.             ->storeNewLicenseRecoveryInCart(LicenseRecovery::FLAG_SOURCE_PRODUCT_PAGE);
  33.         return new Response(json_encode($licenseRecoveryResponse));
  34.     }
  35.     public function removeFromCart(Request $request): Response
  36.     {
  37.         $licenseRecoveryService $this->getContainer()->get('app.service.license_recovery.license_recovery');
  38.         $result $licenseRecoveryService->removeLicenseRecoveryFromCartSessionByCnp($request->get('cnp'));
  39.         return new Response(json_encode(['result' => $result]));
  40.     }
  41.     public function iframe(Request $request): Response
  42.     {
  43.         $partnerService $this->getContainer()->get('app.service.partner.partner');
  44.         $partnerService->verifyToken($requestPartnerManager::CAN_ISSUE_LICENSE_RECOVERY_INDEX);
  45.         $token['partnerPublicToken'] = $request->get(PartnerManager::SESSION_PARTNER_PUBLIC_TOKEN_NAME);
  46.         $request->getSession()->set('iframeSourceLink'$this->generateUrl('app_shop_lr_iframe'$token));
  47.         $partner $partnerService->retrievePartner($token['partnerPublicToken']);
  48.         if ($partner->getWithoutLocalStorage()) {
  49.             CartManager::removeAllProductsFromCartBySession($request->getSession());
  50.         }
  51.         PartnerManager::checkQRCodeFlow($request);
  52.         return $this->render('@templates/Front/LicenseRecovery/iframe.html.twig', [
  53.             'guid' => $request->get('guid'),
  54.             'publicToken' => $partner->getPublicToken()
  55.         ]);
  56.     }
  57.     public function addToCartById(Order $orderRequest $request)
  58.     {
  59.         $clientIp $request->getClientIp();
  60.         $session $request->getSession();
  61.         foreach ($order->getLicenseRecovery() as $licenseRecovery) {
  62.             if (!LicenseRecoveryManager::isLicenseRecoveryAlreadyInCart($session)) {
  63.                 $cartItem LicenseRecoveryManager::constructLicenseRecoveryForCartFromObject(
  64.                     $licenseRecovery$clientIpLicenseRecovery::FLAG_SOURCE_REMARKETING
  65.                 );
  66.                 LicenseRecoveryManager::addNewLicenseRecoveryInCart($session$cartItem);
  67.             }
  68.         }
  69.         $authTokenService = new AuthTokenService();
  70.         if ($token $authTokenService->authenticateUserWithToken($request$this->getEntityManager())) {
  71.             $this->get('security.token_storage')->setToken($token);
  72.             $event = new InteractiveLoginEvent($request$token);
  73.             $this->dispatcher->dispatch($event'security.interactive_login');
  74.             $session $request->getSession();
  75.             $session->set('_sylius.cart.FASHION_WEB'180);
  76.             $session->save();
  77.         }
  78.         $utm = [
  79.             'utm_source' => $request->get('utm_source'),
  80.             'utm_medium' => $request->get('utm_medium'),
  81.             'utm_campaign' => $request->get('utm_campaign'),
  82.             'utm_term' => $request->get('utm_term'),
  83.             'utm_content' => $request->get('utm_content'),
  84.             'utm_id' => $request->get('utm_id')
  85.         ];
  86.         return $this->render('@templates/ShopCustom/Redirect/wait_to_be_redirected.html.twig',[
  87.             'url' => $this->generateUrl('app_shop_customer_info'$utm)
  88.         ]);
  89.     }
  90.     public function showPolicyForPartner(Request $request): Response
  91.     {
  92.         $id base64_decode($request->get('order_id'));
  93.         $em $this->getEntityManager();
  94.         /** @var Order $order */
  95.         $order $em->getRepository(Order::class)->find($id);
  96.         if (!$order->hasLicenseRecovery()) {
  97.             return new Response('error');
  98.         }
  99.         $apiInvoiceService = new InvoiceApiService();
  100.         $invoice $em->getRepository(VignetteInvoice::class)
  101.             ->findOneBy(['order' => $id'productType' => VignetteInvoice::PRODUCT_LICENSE_RECOVERY]);
  102.         $pdfContent $apiInvoiceService->getInvoicePDFViaBillingService($invoice->getApiInvoiceId());
  103.         if (!$pdfContent) {
  104.             return new Response('error');
  105.         }
  106.         $invoiceFileName SystemService::retrieveMessage('invoice'$this->getContainer()->get('translator'));
  107.         $filename "{$invoiceFileName} {$invoice->getSeries()} {$invoice->getNumber()}";
  108.         InvoiceService::openPDFContent($pdfContent$filename);
  109.         return new Response();
  110.     }
  111. }