diff --git a/controllers/front/GuestTrackingController.php b/controllers/front/GuestTrackingController.php index bd8307d8f..4ab0a4dd0 100644 --- a/controllers/front/GuestTrackingController.php +++ b/controllers/front/GuestTrackingController.php @@ -608,31 +608,30 @@ class GuestTrackingControllerCore extends FrontController // load Google Maps library if configured if (!count($this->errors)) { - $ordersCollection = Order::getByReference(Tools::getValue('order_reference')); - if ($objOrder = $ordersCollection->getFirst()) { - if ($idHotel = HotelBookingDetail::getIdHotelByIdOrder($objOrder->id)) { - $objHotelBranchInformation = new HotelBranchInformation($idHotel, $this->context->language->id); - if (Validate::isLoadedObject($objHotelBranchInformation)) { - if (($apiKey = Configuration::get('PS_API_KEY')) - && Configuration::get('WK_GOOGLE_ACTIVE_MAP') - ) { - if (floatval($objHotelBranchInformation->latitude) != 0 - && floatval($objHotelBranchInformation->longitude) != 0 + if ($ordersCollection = Order::getByReference(Tools::getValue('order_reference'))) { + foreach ($ordersCollection as $objOrder) { + if ($idHotel = HotelBookingDetail::getIdHotelByIdOrder($objOrder->id)) { + $objHotelBranchInformation = new HotelBranchInformation($idHotel, $this->context->language->id); + if (Validate::isLoadedObject($objHotelBranchInformation)) { + if (($apiKey = Configuration::get('PS_API_KEY')) + && Configuration::get('WK_GOOGLE_ACTIVE_MAP') ) { - Media::addJsDef(array( - 'hotel_location' => array( - 'latitude' => $objHotelBranchInformation->latitude, - 'longitude' => $objHotelBranchInformation->longitude, - 'map_input_text' => $objHotelBranchInformation->map_input_text, - ), - 'hotel_name' => $objHotelBranchInformation->hotel_name, - 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')) - )); + if (floatval($objHotelBranchInformation->latitude) != 0 + && floatval($objHotelBranchInformation->longitude) != 0 + ) { + Media::addJsDef(array( + 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), + 'initiateMap' => 1, + )); - $this->addJS( - 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places&language='. - $this->context->language->iso_code.'®ion='.$this->context->country->iso_code - ); + $this->addJS( + 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places&language='. + $this->context->language->iso_code.'®ion='.$this->context->country->iso_code + ); + + // just need to load the map once for the first order with map details. So break the loop. + break; + } } } } diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php index 5e1da2853..3b15a99b6 100644 --- a/controllers/front/OrderDetailController.php +++ b/controllers/front/OrderDetailController.php @@ -805,13 +805,8 @@ class OrderDetailControllerCore extends FrontController && floatval($objHotelBranchInformation->longitude) != 0 ) { Media::addJsDef(array( - 'hotel_location' => array( - 'latitude' => $objHotelBranchInformation->latitude, - 'longitude' => $objHotelBranchInformation->longitude, - 'map_input_text' => $objHotelBranchInformation->map_input_text, - ), - 'hotel_name' => $objHotelBranchInformation->hotel_name, - 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')) + 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), + 'initiateMap' => 1, )); $this->addJS( diff --git a/themes/hotel-reservation-theme/js/order-detail.js b/themes/hotel-reservation-theme/js/order-detail.js index ff9f5c340..69aa98360 100644 --- a/themes/hotel-reservation-theme/js/order-detail.js +++ b/themes/hotel-reservation-theme/js/order-detail.js @@ -134,12 +134,11 @@ function initRefundDeniedTooltip() { } function initMap() { - const hotelLocation = { - lat: Number(hotel_location.latitude), - lng: Number(hotel_location.longitude), - }; - $('.booking-hotel-map-container').each(function (i, element) { + const hotelLocation = { + lat: Number($(this).attr('latitude')), + lng: Number($(this).attr('longitude')), + }; const map = new google.maps.Map(element, { zoom: 10, center: hotelLocation, @@ -150,16 +149,16 @@ function initMap() { const marker = new google.maps.Marker({ position: hotelLocation, map: map, - title: hotel_name, + title: $(this).attr('title'), icon: PS_STORES_ICON }); marker.addListener('click', function() { let query = ''; - if (hotel_location.map_input_text != '') { - query = hotel_location.map_input_text; + if ($(this).attr('query') != '') { + query = $(this).attr('query'); } else { - query = hotel_location.latitude + ',' + hotel_location.longitude; + query = $(this).attr('latitude') + ',' + $(this).attr('longitude'); } window.open('https://www.google.com/maps/search/?api=1&query='+encodeURIComponent(query), '_blank'); @@ -377,7 +376,8 @@ $(document).ready(function () { if (typeof google === 'object' && typeof google.maps === 'object' - && typeof hotel_location === 'object' + && typeof initiateMap !== 'undefined' + && initiateMap === 1 ) { initMap(); } diff --git a/themes/hotel-reservation-theme/order-detail.tpl b/themes/hotel-reservation-theme/order-detail.tpl index b2f89be2e..9ac445d81 100644 --- a/themes/hotel-reservation-theme/order-detail.tpl +++ b/themes/hotel-reservation-theme/order-detail.tpl @@ -177,7 +177,13 @@ {if ($obj_hotel_branch_information->latitude|floatval != 0 && $obj_hotel_branch_information->longitude|floatval != 0) && $view_on_map}
-
+
+
{/if} @@ -626,7 +632,13 @@ {if ($obj_hotel_branch_information->latitude|floatval != 0 && $obj_hotel_branch_information->longitude|floatval != 0) && $view_on_map}
-
+
+
{/if}