src/Controller/Front/Product/HotelController.php line 591

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front\Product;
  3. use App\Config\ModuleEnum;
  4. use App\Entity\CustomerMoral;
  5. use App\Repository\CityRepository;
  6. use App\Repository\FrontThemeRepository;
  7. use App\Repository\HotelXmlPriceRepository;
  8. use App\Repository\HotelXmlRepository;
  9. use App\Repository\OrderLineRepository;
  10. use App\Repository\OrderRepository;
  11. use App\Service\Api3TAuthenticationService;
  12. use App\Service\CartService;
  13. use App\Service\CurrencyService;
  14. use App\Service\FrontRecentSearchService;
  15. use App\Service\FrontService;
  16. use App\Service\Helpers;
  17. use App\Service\HotelApiService;
  18. use App\Service\ParameterService;
  19. use DateTime;
  20. use Exception;
  21. use Gedmo\Translatable\TranslatableListener;
  22. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  23. use Symfony\Component\HttpClient\HttpClient;
  24. use Symfony\Component\HttpFoundation\JsonResponse;
  25. use Symfony\Component\HttpFoundation\RedirectResponse;
  26. use Symfony\Component\HttpFoundation\Request;
  27. use Symfony\Component\HttpFoundation\Response;
  28. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  29. use Symfony\Component\Routing\Annotation\Route;
  30. #[Route('/hotel')]
  31. class HotelController extends AbstractController
  32. {
  33.     public function __construct(
  34.         private readonly Api3TAuthenticationService $apiAuthenticationService,
  35.         private readonly HotelApiService            $hotelApiService,
  36.         private readonly CurrencyService            $currencyService,
  37.         private readonly FrontService               $frontService,
  38.         private readonly ParameterService           $parameterService,
  39.         private readonly Helpers                    $helpers,
  40.     )
  41.     {
  42.     }
  43.     #[Route('/hotelcity/{name}'name'app_front_hotel_city')]
  44.     public function hotelByCity(string                  $name,
  45.                                 CityRepository          $cityRepository,
  46.                                 HotelXmlPriceRepository $hotelXmlPriceRepository,
  47.                                 FrontService            $frontService): Response
  48.     {
  49.         $hotels = [];
  50.         $city $cityRepository->findOneBy(['name' => $name]);
  51.         $description "";
  52.         $country "";
  53.         if ($city) {
  54.             $description $city->getDescription();
  55.             $country $city->getCountry()->getName();
  56.         }
  57.         $hotelXmlPrices $hotelXmlPriceRepository->getHotelXmlPriceByCriterias(['cities' => [$name]]);
  58.         foreach ($hotelXmlPrices as $HotelXmlPrice) {
  59.             $hotels[] = $frontService->getItemHotel($HotelXmlPrice);
  60.         }
  61.         return $this->render('front/hotel/hotel_by_city.html.twig', [
  62.             'hotels' => $hotels,
  63.             'city' => $city,
  64.             'name' => $name,
  65.             'country' => $country,
  66.             'society' => $this->parameterService->getSocietyParameters(),
  67.             'social_networks' => $this->frontService->getSocialNetworks(),
  68.             'agencies' => $this->frontService->getAgencies(),
  69.             'currencies' => $this->frontService->getCurrencies(),
  70.             'currencySwitcher' => true,
  71.             'tracking_tools' => $this->frontService->getTrackingTools()
  72.         ]);
  73.     }
  74.     #[Route('/hoteltheme/{name}'name'app_front_hotel_theme')]
  75.     public function hotelByTheme(string                  $name,
  76.                                  FrontThemeRepository    $frontThemeRepository,
  77.                                  HotelXmlPriceRepository $hotelXmlPriceRepository,
  78.                                  FrontService            $frontService): Response
  79.     {
  80.         $hotels = [];
  81.         $theme $frontThemeRepository->findOneBy(['name' => $name]);
  82.         $description "";
  83.         if ($theme) {
  84.             $description $theme->getDescription();
  85.         }
  86.         $hotelXmlPrices $hotelXmlPriceRepository->getHotelXmlPriceByCriterias(['themes' => $name]);
  87.         foreach ($hotelXmlPrices as $HotelXmlPrice) {
  88.             $hotels[] = $frontService->getItemHotel($HotelXmlPrice);
  89.         }
  90.         return $this->render('front/hotel/hotel_by_theme.html.twig', [
  91.             'hotels' => $hotels,
  92.             'description' => $description,
  93.             'name' => $name,
  94.             'society' => $this->parameterService->getSocietyParameters(),
  95.             'social_networks' => $this->frontService->getSocialNetworks(),
  96.             'agencies' => $this->frontService->getAgencies(),
  97.             'currencies' => $this->frontService->getCurrencies(),
  98.             'tracking_tools' => $this->frontService->getTrackingTools()
  99.         ]);
  100.     }
  101.     #[Route('/search'name'hotel_search'methods: ['GET''POST'])]
  102.     public function hotelSearch(Request $requestFrontRecentSearchService $frontRecentSearchService): Response
  103.     {
  104.         $data $request->get("data"); // data : JSON request
  105.         $requestData json_decode($datatrue);
  106.         $date = new DateTime();
  107. // Output the date in default format
  108.         $currentDate $date->format('Y-m-d'); // Example: 2025-01-02 15:30:45
  109.         if ($requestData['checkIn'] < $currentDate || $requestData['checkOut'] < $currentDate) {
  110.             return $this->redirectToRoute('app_main');
  111.         }
  112.         $customer $this->apiAuthenticationService->getCustomer($this->getUser());
  113.         $hotel_search_history $frontRecentSearchService->updateHotelSearchHistory($requestData$data);
  114.         return $this->render('front/hotel/search.html.twig', [
  115.             'requestData' => $requestData,
  116.             'customer' => $customer,
  117.             'society' => $this->parameterService->getSocietyParameters(),
  118.             'social_networks' => $this->frontService->getSocialNetworks(),
  119.             'agencies' => $this->frontService->getAgencies(),
  120.             'currencies' => $this->frontService->getCurrencies(),
  121.             'hotel_search_history' => $hotel_search_history,
  122.             'currencySwitcher' => true,
  123.             'tracking_tools' => $this->frontService->getTrackingTools()
  124.         ]);
  125.     }
  126.     #[Route('/formsearch/{city_label}/{hotel_label}'name'hotel_form_search'methods: ['GET''POST'])]
  127.     public function hotelFormSearch(Request $requeststring $city_labelstring $hotel_label): Response
  128.     {
  129.         $requestData json_decode($request->get("data"), true);
  130.         return $this->render('front/hotel/form_search.html.twig', [
  131.             'requestData' => $requestData,
  132.             'hotel_label' => $hotel_label,
  133.             'city_label' => $city_label
  134.             /* 'society' => $this->parameterService->getSocietyParameters(),
  135.              'social_networks' => $this->frontService->getSocialNetworks(),
  136.              'agencies' => $this->frontService->getAgencies(),
  137.              'currencies' => $this->frontService->getCurrencies(),*/
  138.         ]);
  139.     }
  140.     #[Route('/search_json'name'hotel_search_json'methods: ['GET''POST'])]
  141.     public function hotelSearchJson(Request $requestHotelApiService $hotelApiService): JsonResponse
  142.     {
  143.         // ----- PREPARE the HttpRequestCall ----- //
  144.         // Get auth_data : user, timestamp, signature
  145.         $user $this->getUser();
  146.         $auth_data $this->apiAuthenticationService->getAuthenticationArray($user);
  147.         $customer $this->apiAuthenticationService->getCustomer($user);
  148.         $showResellingRates false;
  149.         if ($customer instanceof CustomerMoral) {
  150.             if ($customer->getResellerMargin() > && (in_array('ROLE_B2B_ADMIN'$user->getRoles()) || in_array('ROLE_B2B_AGENT'$user->getRoles()))) {
  151.                 $showResellingRates true;
  152.             }
  153.         }
  154.         $requestJson json_decode($request->getContent(), true);
  155.         $xmlSourceId $request->headers->get('xmlSourceId') ?? 0;
  156.         $base_uri $request->getSchemeAndHttpHost();
  157.         // ----- PERFORM the HttpRequestCall ----- //
  158.         $data $hotelApiService->query_ApiHotel_Availability($auth_data$requestJson$xmlSourceId$base_uritrue);
  159.         $today DateTime::createFromFormat("Y-m-d"date("Y-m-d"));
  160.         if (count($data['content']) > 0) { // Re-format data to fit the FRONT-B2C :::: VIEW_BY_BOARD ::::
  161.             $nbRooms count($requestJson['occupancies']);
  162.             $content_front = []; // prepare data to fit the front design
  163.             foreach ($data['content'] as $hotel) {
  164.                 $hotel_key strtoupper($hotel['hotel']['name']); // HOTEL_ITEM_IDENTIFIER TO GROUP MULTIPLE HOTELS WITH SAME NAME
  165.                 $hotel_offer_count 0;
  166.                 if (isset($content_front[$hotel_key]['offersCount'])) {
  167.                     $hotel_offer_count $content_front[$hotel_key]['offersCount'];
  168.                 }
  169.                 $content_front[$hotel_key]['hotel'] = $hotel['hotel'];
  170.                 $content_front[$hotel_key]['hotel']['customRating'] = $this->hotelApiService->getHotelCustomRating($hotel['hotel']['name']);
  171.                 // TODO Add function getReviewRating(hotelName, reviewsSource);
  172.                 $content_front[$hotel_key]['hotel']['reviewRating'] = rand(410); // TODO GET RATING FROM External src like Tripadvisor
  173.                 if (count($hotel['sources']) > 0) {
  174.                     $content_front[$hotel_key]['hotel']['facilities'] = $hotel['sources'][0]['facilities'];
  175.                 }
  176.                 $content_front[$hotel_key]['hotel']['promos'] = [];
  177.                 $content_front[$hotel_key]['hotel']['discounts'] = [];
  178.                 $content_front[$hotel_key]['hotel']['infos'] = [];
  179.                 foreach ($hotel['sources'] as $hotel_source) {
  180.                     $sourceKey $hotel['hotel']['id']; // considering the full-hotel-id as the sourceKey (string containing the end-source-id)
  181.                     $content_front[$hotel_key]['sources'][$sourceKey]['sourceKey'] = $sourceKey;
  182.                     $hotelSourcePrice 0;
  183.                     $hotelSourceAvailable false;
  184.                     $hotelSourceFreeCancellation false;
  185.                     $tab_boards = [];
  186.                     foreach ($hotel_source['rooms'] as $index => $index_hrts) { // room_index
  187.                         // SORT hrts for current hotel-source by salePromoRate
  188.                         usort($index_hrts, function ($a$b) {
  189.                             return $a['salePromoRate'] <=> $b['salePromoRate']; // Ascending
  190.                         });
  191.                         foreach ($index_hrts as $hrt) {
  192.                             // freeCancellation FLAG to use in React Filter (i.e. is there a possibility to cancel without fees )
  193.                             if ($hrt['NRF']) {
  194.                                 $hrt['freeCancellation'] = false;
  195.                             } else {
  196.                                 if (is_null($hrt['deadline'])) {
  197.                                     $hrt['freeCancellation'] = true;
  198.                                 } else {
  199.                                     $deadline = new DateTime($hrt['deadline']);
  200.                                     $difference date_diff($today$deadline); // Interval before deadline.
  201.                                     if ($difference->invert) { // deadline is exceeded
  202.                                         $hrt['freeCancellation'] = false;
  203.                                     } else {
  204.                                         $hrt['freeCancellation'] = true;
  205.                                     }
  206.                                 }
  207.                             }
  208.                             $hotelSourceFreeCancellation $hotelSourceFreeCancellation || $hrt['freeCancellation'];
  209.                             // END freeCancellation FLAG
  210.                             // SHOW SaleResellingRates rather thant saleRate applied to the customer
  211.                             if ($showResellingRates) {
  212.                                 $hrt['salePromoRate'] = $hrt['salePromoRate'] * (100.0 $customer->getResellerMargin()) / 100.0;
  213.                                 $hrt['saleRate'] = $hrt['saleRate'] * (100.0 $customer->getResellerMargin()) / 100.0;
  214.                             }
  215.                             $content_front[$hotel_key]['sources'][$sourceKey]['hrts'][$hrt['boardName']][$index][] = $hrt;
  216.                             $tab_boards[$hrt['boardName']] = $hrt['boardXmlName'];
  217.                             // Increment the number of available-offers
  218.                             if ($hrt['available']) {
  219.                                 $hotel_offer_count++;
  220.                                 $hotelSourceAvailable true;
  221.                             }
  222.                         }
  223.                     } // END Room Indexes
  224.                     // HOTEL BADGES (Promos, Discounts, Infos)
  225.                     foreach ($hotel_source['promos'] as $item) {
  226.                         $content_front[$hotel_key]['hotel']['promos'][] = $item;
  227.                     }
  228.                     foreach ($hotel_source['discounts'] as $item) {
  229.                         $content_front[$hotel_key]['hotel']['discounts'][] = $item;
  230.                     }
  231.                     foreach ($hotel_source['infos'] as $item) {
  232.                         $content_front[$hotel_key]['hotel']['infos'][] = $item;
  233.                     }
  234.                     $bestOffers $this->hotelApiService->getBestPriceBoard($content_front[$hotel_key], $sourceKey);
  235.                     $content_front[$hotel_key]['sources'][$sourceKey]['bestPrice'] = $bestOffers['bestPrice_currentSourceKey'];
  236.                     $content_front[$hotel_key]['bestPrice'] = $bestOffers['bestPrice'];
  237.                     $content_front[$hotel_key]['bestBoard'] = $bestOffers['bestBoard'];
  238.                     $content_front[$hotel_key]['bestRooms'] = $this->helpers->formatArrayCounts($bestOffers['bestRooms']);
  239.                     $content_front[$hotel_key]['offersCount'] = $hotel_offer_count;
  240.                     foreach ($content_front[$hotel_key]['sources'][$sourceKey]['hrts'] as $board_key => $board_hrts) {
  241.                         if (count($board_hrts) < $nbRooms) {
  242.                             unset($content_front[$hotel_key]['sources'][$sourceKey]['hrts'][$board_key]);
  243.                         }
  244.                     }
  245.                     foreach ($tab_boards as $board_key => $board_value) {
  246.                         $content_front[$hotel_key]['sources'][$sourceKey]['boards'][] =
  247.                             [
  248.                                 'key' => $board_value,
  249.                                 'value' => $board_value,
  250.                             ];
  251.                     }
  252.                     // set general stock
  253.                     $content_front[$hotel_key]['sources'][$sourceKey]['generalStock'] = $hotel_source['generalStock'];
  254.                     // set search code
  255.                     $content_front[$hotel_key]['sources'][$sourceKey]['searchCode'] = $hotel_source['searchCode'];
  256.                     // set source id
  257.                     $content_front[$hotel_key]['sources'][$sourceKey]['xmlSourceId'] = $hotel_source['xmlSourceId'];
  258.                     // set xml source name
  259.                     $content_front[$hotel_key]['sources'][$sourceKey]['xmlSourceName'] = $hotel_source['xmlSourceName'];
  260.                     // set hotel Source available
  261.                     $content_front[$hotel_key]['sources'][$sourceKey]['available'] = $hotelSourceAvailable;
  262.                     // set hotel Source available
  263.                     $content_front[$hotel_key]['sources'][$sourceKey]['freeCancellation'] = $hotelSourceFreeCancellation;
  264.                     // set hotel Source available
  265.                     $content_front[$hotel_key]['sources'][$sourceKey]['associationRequired'] = $hotel_source['associationRequired'];
  266.                 }
  267.             }
  268.             // array values hotels
  269.             $data['content'] = array_values($content_front);
  270.             // array values sources
  271.             foreach ($data['content'] as &$hotel) {
  272.                 usort($hotel['sources'], function ($a$b) {
  273.                     return $a['bestPrice'] <=> $b['bestPrice']; // Ascending
  274.                 });
  275.                 $hotel['sources'] = array_values($hotel['sources']);
  276.                 foreach ($hotel['sources'] as &$source) {
  277.                     $source['hrts'] = array_values($source['hrts']);
  278.                 }
  279.             }
  280.         }
  281.         return $this->json($data);
  282.     }
  283.     #[Route('/autocomplete'name'hotel_autocomplete'methods: ['GET'])]
  284.     public function autoComplete(Request $request): JsonResponse
  285.     {
  286.         $query $request->query->get('query');
  287.         if ($query == null) {
  288.             return $this->json([]);
  289.         }
  290.         $query_trim trim($query);
  291.         $headers = [
  292.             'Accept' => 'application/json',
  293.             'Content-Type' => 'application/json',
  294.         ];
  295.         try {
  296.             $httpClient HttpClient::create();
  297.             $response $httpClient->request('GET'$request->getSchemeAndHttpHost() . '/api/hotel/autocomplete', [
  298.                 'headers' => $headers,
  299.                 'query' => ['query' => $query_trim]
  300.             ]);
  301.             $data json_decode($response->getContent(), true);
  302.             return $this->json($data['response']);
  303.         } catch (Exception $e) {
  304.             return $this->json(['error' => $e->getMessage()]);
  305.         }
  306.     }
  307.     /**
  308.      * The detail of selected offer from the front : hotel search results page. --- Check-Rate ---
  309.      * Supposed to be called either from "hotel/search or "orderline_add_room"
  310.      */
  311.     #[Route('/offer-detail'name'hotel_offer_detail'methods: ['GET''POST'])]
  312.     public function hotelOfferDetail(Request             $request,
  313.                                      OrderLineRepository $orderLineRepository,
  314.                                      OrderRepository     $orderRepository,
  315.     ): Response
  316.     {
  317.         $guestData = [];
  318.         if ($request->isMethod('POST')) {
  319.             $guestData = [
  320.                 'first_name' => $request->request->get('first_name'),
  321.                 'last_name' => $request->request->get('last_name'),
  322.                 'phone' => $request->request->get('phone'),
  323.                 'email' => $request->request->get('email'),
  324.             ];
  325.             $request->getSession()->set('guestData'$guestData);
  326.         }
  327.         $customer $this->apiAuthenticationService->getCustomer($this->getUser());
  328.         $auth_data $this->apiAuthenticationService->getAuthenticationArray($this->getUser());
  329.         $rooms_rate_keys = [];
  330.         for ($i 0$i $request->get('nbRooms'); $i++) {
  331.             $rooms_rate_keys [] = ["rateKey" => $request->get("room-" $i)];
  332.         }
  333.         $checkRateRequest = [
  334.             'rooms' => $rooms_rate_keys,
  335.             'searchCode' => $request->get('searchCode')
  336.         ];
  337.         $saleCurrency $this->currencyService->getSessionCurrency();
  338.         $product_fee $this->frontService->getProductFee(ModuleEnum::hotel->getValue(), $customer);
  339.         /** call api/hotel/checkrate */
  340.         $httpClient HttpClient::create();
  341.         $response $httpClient->request(
  342.             'POST'$request->getUriForPath('/') . 'api/hotel/checkrate',
  343.             [
  344.                 'headers' => [
  345.                     'Accept' => 'application/json',
  346.                     'Content-Type' => 'application/json',
  347.                     'currency' => $saleCurrency,
  348.                     'user' => $auth_data['user'],
  349.                     'timestamp' => $auth_data['timestamp'],
  350.                     'signature' => hash('sha256'$auth_data['signature'])
  351.                 ],
  352.                 'json' => $checkRateRequest
  353.             ]
  354.         );
  355.         $responseData json_decode($response->getContent(), true);
  356.         $searchCriteriaArray json_decode($request->get("searchCriteria"), true);
  357.         $twig_parameters = [
  358.             'searchCriteriaArray' => $searchCriteriaArray,
  359.             'searchCode' => null,
  360.             'checkRateData' => null,
  361.             "social_networks" => $this->frontService->getSocialNetworks(),
  362.             "currencies" => $this->frontService->getCurrencies(),
  363.             "agencies" => $this->frontService->getAgencies(),
  364.             "society" => $this->parameterService->getSocietyParameters(),
  365.             "referenceCurrency" => $this->parameterService->getReferenceCurrency(),
  366.             'guestData' => $guestData,
  367.             'action' => '',
  368.             'customer' => $customer
  369.         ];
  370.         $template "";
  371.         if (is_null($responseData) or $responseData['error']) {
  372.             // CASE 0 : Template for Error
  373.             return $this->render("front/hotel/offer_error.html.twig"$twig_parameters);
  374.         } else {
  375.             $checkRateData reset($responseData['content']);
  376.             $checkRateData['available'] = $this->hotelApiService->isAvailable($checkRateData) ? "true" "false";
  377.             $rooms = [];
  378.             foreach ($checkRateData['sources'][0]['rooms'] as $room_index) {
  379.                 $rooms [] = $room_index[0]; // the selected room for the index.
  380.             }
  381.             //$checkRateData['cancellation'] = $this->hotelApiService->getDeadlineFromRooms($rooms);
  382.             $twig_parameters['checkRateData'] = $checkRateData;
  383.             $twig_parameters['searchCode'] = $responseData['searchCode'];
  384.             $twig_parameters['product_fee'] = $product_fee;
  385.             $twig_parameters['META_PIXEL_ID'] = $this->parameterService->getTrackerMetaId();
  386.             // CASE 1 : Template to add something to an existing orderline
  387.             if ($request->get('orderlineId')) {
  388.                 $orderlineID $request->get('orderlineId');
  389.                 $twig_parameters['orderLine'] = $orderLineRepository->find($orderlineID);
  390.                 $twig_parameters['action'] = $this->generateUrl("orderline_add_room", ['id' => $orderlineID]);
  391.             }
  392.             // CASE 2 : new Order and new OrderLine
  393.             if (empty($request->get('orderlineId')) && empty($request->get('orderId'))) { //
  394.                 $twig_parameters['action'] = $this->generateUrl("app_admin_add_cart_line_hotel");
  395.             }
  396.             // CASE 3 : Add new OrderLine into an existing Order
  397.             if (empty($request->get('orderlineId')) && $request->get('orderId')) { //
  398.                 $orderID $request->get('orderId');
  399.                 $twig_parameters ['order'] = $orderRepository->find($orderID);
  400.                 $twig_parameters['action'] = $this->generateUrl("order_add_orderline_hotel_book", ['id' => $orderID]);
  401.             }
  402.             return $this->render("front/hotel/offer_detail.html.twig"$twig_parameters);
  403.         }
  404.     }
  405.     /**
  406.      *  The detail of a given hotelId
  407.      */
  408.     #[Route('/{country_label}/{city_label}/{hotel_label}/{id}'name'hotel_detail'methods: ['GET'])]
  409.     public function hotelDetail(
  410.         Request            $request,
  411.                            $id,
  412.         string             $city_label,
  413.         string             $hotel_label,
  414.         ParameterService   $parameterService,
  415.         HotelXmlRepository $hotelXmlRepository): Response
  416.     {
  417.         $hotel_id_elements explode("|"$id);
  418.         $xmlSourceId $hotel_id_elements[0];
  419. //        dd($xmlSourceId);
  420.         $codeHotel $hotel_id_elements[1];
  421.         if ($xmlSourceId == 0) {
  422.             $hotelDetails $this->hotelApiService->hotelDetails($codeHotel$request->getLocale());
  423.         } else {
  424.             $hotelDetails $this->hotelApiService->hotelDetailsHUB($id);
  425.         }
  426.         $recommendedHotels $hotelXmlRepository->getRecommendedHotels($city_label$id);
  427.         $currentDateTime = new DateTime();
  428.         $arrivalDate $currentDateTime->format('Y-m-d');//
  429.         $departureDate = new DateTime("tomorrow");
  430.         $departureDate $departureDate->format('Y-m-d');
  431.         return $this->render('front/hotel/hotel_detail.html.twig', [
  432.             'hotel_data' => $hotelDetails,
  433.             'society' => $this->parameterService->getSocietyParameters(),
  434.             'social_networks' => $this->frontService->getSocialNetworks(),
  435.             'currencies' => $this->frontService->getCurrencies(),
  436.             'agencies' => $this->frontService->getAgencies(),
  437.             'menu_front' => $this->frontService->getFrontMenu(),
  438.             'recommendedHotels' => $recommendedHotels,
  439.             "arrivalDate" => $arrivalDate,
  440.             "departureDate" => $departureDate,
  441.             "city_label" => $city_label,
  442.             "hotel_label" => $hotel_label,
  443.             "META_PIXEL_ID" => $this->parameterService->getTrackerMetaId()
  444.         ]);
  445.     }
  446.     #[Route('/{id}/gallery'name'hotel_gallery_json'methods: ['GET'])]
  447.     public function hotelGallery(
  448.         Request $request,
  449.                 $id
  450.     ): JsonResponse
  451.     {
  452.         $auth_data $this->apiAuthenticationService->getAuthenticationArray($this->getUser());
  453.         // call hotel detail and get images
  454.         $hotelDetailsRequest = [
  455.             'hotelId' => $id
  456.         ];
  457.         $httpClient HttpClient::create();
  458.         $response $httpClient->request(
  459.             'POST'$request->getUriForPath('/') . 'api/hotel/details',
  460.             [
  461.                 'headers' => [
  462.                     'Accept' => 'application/json',
  463.                     'Content-Type' => 'application/json',
  464.                     'user' => $auth_data['user'],
  465.                     'timestamp' => $auth_data['timestamp'],
  466.                     'signature' => hash('sha256'$auth_data['signature'])
  467.                 ],
  468.                 'json' => $hotelDetailsRequest
  469.             ]
  470.         );
  471.         $responseData json_decode($response->getContent(), true);
  472.         if (is_null($responseData) || !key_exists('content'$responseData)) {
  473.             return $this->json([]);
  474.         }
  475.         $hotel_data_array $responseData['content']['images'];
  476.         return $this->json($hotel_data_array);
  477.     }
  478.     /**
  479.      * @throws Exception
  480.      */
  481.     #[Route('/promo'name'app_front_hotel_promo'methods: ['GET'])]
  482.     public function hotelPromo(HotelXmlPriceRepository $hotelXmlPriceRepository,
  483.                                FrontService            $frontService
  484.     ): Response
  485.     {
  486.         $hotels = [];
  487.         $hotelXmlPricesWithPromos $hotelXmlPriceRepository->getHotelXmlPriceWithPromos();
  488.         foreach ($hotelXmlPricesWithPromos as $hotelXmlPricesWithPromo) {
  489.             $hotels[] = $frontService->getItemHotel($hotelXmlPricesWithPromo);
  490.         }
  491.         return $this->render('front/hotel/hotel_promo.html.twig', [
  492.             'hotelsWithPromos' => $hotels,
  493.             'social_networks' => $this->frontService->getSocialNetworks(),
  494.             'currencies' => $this->frontService->getCurrencies(),
  495.             'agencies' => $this->frontService->getAgencies(),
  496.             'society' => $this->parameterService->getSocietyParameters(),
  497.             'currencySwitcher' => true,
  498.             'META_PIXEL_ID' => $this->parameterService->getTrackerMetaId()
  499.         ]);
  500.     }
  501.     #[Route('/cart/addProductHotel'name'app_admin_add_cart_line_hotel'methods: ['POST'])]
  502.     public function addProductHotel(Request          $request,
  503.                                     SessionInterface $session,
  504.                                     CartService      $cartService,
  505.     ): RedirectResponse
  506.     {
  507.         $cart_array $cartService->initCart($this->getUser(), $request);
  508.         /* 2- add a line into cart_array['products'] */
  509.         $nbRooms $request->get("nbRooms"); // quantity : nbRooms
  510.         $cart_line_label $request->get('product_label');
  511.         $cart_line_date $request->get('product_date');
  512.         $beneficiaryName $request->get('beneficiary_name');
  513.         $beneficiaryEmail $request->get('beneficiary_email');
  514.         $product_price $request->get("totalAmount");
  515.         $productFee $request->get('product_fee') ?? 0;
  516.         $dates explode('-'$cart_line_date);
  517.         $date1 DateTime::createFromFormat('d/m/Y'$dates[0]);
  518.         $date2 DateTime::createFromFormat('d/m/Y'$dates[1]);
  519.         $interval $date1->diff($date2);
  520.         $nbNights $interval->days;
  521.         $hotel_with_party false;
  522.         $product_elements null;
  523.         for ($room_idx 0$room_idx $nbRooms$room_idx++) {
  524.             /* guests */
  525.             $room_guests = [];
  526.             $room_adults_count $request->get("room_" $room_idx "_adults_count");
  527.             $room_children_count $request->get("room_" $room_idx "_children_count");
  528.             $room_guest_count $room_adults_count $room_children_count;
  529.             for ($guest_index 0$guest_index $room_guest_count$guest_index++) {
  530.                 // to keep the same structure, beneficiaries name are stored, but the same name as the primary_beneficiary
  531.                 $guest = [
  532.                     'civility' => '',
  533.                     'firstName' => $beneficiaryName,
  534.                     'lastName' => '-',
  535.                 ];
  536.                 $room_guests[] = $guest;
  537.             }
  538.             $room = [
  539.                 'rateKey' => $request->get("room_" $room_idx "_key"),
  540.                 'label' => $request->get("room_" $room_idx "_label"),
  541.                 'isAvailable' => $request->get("room_" $room_idx "_available"),
  542.                 'price' => $request->get("room_" $room_idx "_price"),
  543.                 'adultsCount' => $room_adults_count,
  544.                 'childrenCount' => $room_children_count,
  545.                 'guests' => $room_guests
  546.             ];
  547.             $room_nb_parties $request->get("room_" $room_idx "_nbParties");
  548.             $room_parties_zones = [];
  549.             if (!is_null($room_nb_parties)) { // if there is parties associated to the current room
  550.                 $hotel_with_party true;
  551.                 for ($party_index 0$party_index $room_nb_parties$party_index++) {
  552.                     $room_parties_zones [] = $request->get("room_" $room_idx "_party_" $party_index);
  553.                 }
  554.                 $room['parties'] = $room_parties_zones;
  555.                 //$product_price+= $request->get("partyPrice_".$party_index);
  556.             }
  557.             $product_elements[] = $room;
  558.         }
  559.         if ($request->isMethod('POST')) {
  560.             $guestData = [
  561.                 'first_name' => $request->request->get('first_name'),
  562.                 'last_name' => $request->request->get('last_name'),
  563.                 'phone' => $request->request->get('phone'),
  564.                 'email' => $request->request->get('email'),
  565.             ];
  566.             $request->getSession()->set('guestData'$guestData);
  567.         }
  568.         $cart_line_hotel = [
  569.             'module' => ModuleEnum::hotel->getValue(),
  570.             'elements' => $product_elements,
  571.             'label' => $cart_line_label,
  572.             'date' => $cart_line_date,
  573.             'checkIn' => $dates[0],
  574.             'checkOut' => $dates[1],
  575.             'nbNights' => $nbNights,
  576.             'quantity' => $nbRooms,
  577.             'options' => $request->get("options"),
  578.             'comment' => $request->get("comment"),
  579.             'price' => $product_price,
  580.             'fee' => $productFee,
  581.             'available' => $request->get('available'),
  582.             'searchCode' => $request->get('searchCode'),
  583.             'tokenForBook' => $request->get('tokenForBook'),
  584.             'beneficiary' => [
  585.                 'name' => $beneficiaryName,
  586.                 'email' => $beneficiaryEmail
  587.             ],
  588.             'image' => $request->get('hotel_image'),
  589.             'city' => $request->get('city'),
  590.             'rating' => $request->get('rating'),
  591.             'guestData' => $guestData,
  592.         ];
  593.         $cart_array ['products'][] = $cart_line_hotel// add a cart line ( a product )
  594.         $session->set("cart"$cart_array);
  595.         //return $this->redirectToRoute('app_shared_cart_index', [], Response::HTTP_SEE_OTHER);
  596.         return $this->redirectToRoute('app_shared_cart_hotel_product_index', [], Response::HTTP_SEE_OTHER);
  597.     }
  598. }