diff --git a/controllers/front/ContactController.php b/controllers/front/ContactController.php index 06e8b0759..1014a8b5f 100644 --- a/controllers/front/ContactController.php +++ b/controllers/front/ContactController.php @@ -237,15 +237,16 @@ class ContactControllerCore extends FrontController $this->addJS(_PS_JS_DIR_.'validate.js'); // GOOGLE MAP - if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) { + if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) { Media::addJsDef( array( 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), + 'PS_MAP_ID' => $PS_MAP_ID, ) ); $this->addJS( 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY. - '&libraries=places&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code + '&libraries=places,marker&loading=async&callback=initMap&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); } } diff --git a/controllers/front/GuestTrackingController.php b/controllers/front/GuestTrackingController.php index 9a9df2490..596d54185 100644 --- a/controllers/front/GuestTrackingController.php +++ b/controllers/front/GuestTrackingController.php @@ -639,6 +639,7 @@ class GuestTrackingControllerCore extends FrontController if (Validate::isLoadedObject($objHotelBranchInformation)) { if (($apiKey = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP') + && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) ) { if (floatval($objHotelBranchInformation->latitude) != 0 && floatval($objHotelBranchInformation->longitude) != 0 @@ -646,10 +647,11 @@ class GuestTrackingControllerCore extends FrontController Media::addJsDef(array( 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), 'initiateMap' => 1, + 'PS_MAP_ID' => $PS_MAP_ID, )); $this->addJS( - 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places&language='. + 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places,marker&loading=async&callback=initMap&language='. $this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php index 6be63643b..40f3edaf6 100644 --- a/controllers/front/OrderDetailController.php +++ b/controllers/front/OrderDetailController.php @@ -871,6 +871,7 @@ class OrderDetailControllerCore extends FrontController if (Validate::isLoadedObject($objHotelBranchInformation)) { if (($apiKey = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP') + && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) ) { if (floatval($objHotelBranchInformation->latitude) != 0 && floatval($objHotelBranchInformation->longitude) != 0 @@ -878,10 +879,10 @@ class OrderDetailControllerCore extends FrontController Media::addJsDef(array( 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), 'initiateMap' => 1, + 'PS_MAP_ID' => $PS_MAP_ID, )); - $this->addJS( - 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places&language='. + 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places,marker&loading=async&callback=initMap&language='. $this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); } diff --git a/controllers/front/OurPropertiesController.php b/controllers/front/OurPropertiesController.php index cb651ba1b..52fd94a86 100644 --- a/controllers/front/OurPropertiesController.php +++ b/controllers/front/OurPropertiesController.php @@ -111,7 +111,7 @@ class OurPropertiesControllerCore extends FrontController $hotelsInfo = array_slice($hotelsInfo, $page * 10, 10); } - if ($displayHotelMap && Configuration::get('PS_API_KEY') && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) { + if ($displayHotelMap && Configuration::get('PS_API_KEY') && Configuration::get('WK_GOOGLE_ACTIVE_MAP') && Configuration::get('PS_MAP_ID')) { if ($hotelLocations = $objHotelInfo->getMapFormatHotelsInfo(Configuration::get('WK_MAP_HOTEL_ACTIVE_ONLY'))) { $hotelLocationArray = str_replace(array('\n', '\r'), '', json_encode($hotelLocations)); } @@ -144,16 +144,17 @@ class OurPropertiesControllerCore extends FrontController $this->addJS(_THEME_JS_DIR_.'our-properties.js'); $this->addCSS(_THEME_CSS_DIR_.'our-properties.css'); // GOOGLE MAP - if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) { + if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) { Media::addJsDef( array( 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), + 'PS_MAP_ID' => $PS_MAP_ID ) ); $this->addJS( 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY. - '&libraries=places&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code + '&libraries=places,marker&loading=async&callback=initMap&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); } } diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index 24cc682af..67627e5ac 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -66,10 +66,11 @@ class ProductControllerCore extends FrontController $this->addJqueryPlugin('jqzoom'); } - if (($PS_API_KEY = Configuration::get('PS_API_KEY'))) { + if (($PS_API_KEY = Configuration::get('PS_API_KEY')) + && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) + ) { $objHotelRoomType = new HotelRoomType(); - $roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($this->product->id); - if ($roomTypeInfo) { + if ($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($this->product->id)) { $objHotelBranchInformation = new HotelBranchInformation($roomTypeInfo['id_hotel']); if (floatval($objHotelBranchInformation->latitude) != 0 && floatval($objHotelBranchInformation->longitude) != 0 @@ -79,12 +80,13 @@ class ProductControllerCore extends FrontController 'latitude' => $objHotelBranchInformation->latitude, 'longitude' => $objHotelBranchInformation->longitude, ), - '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')), + 'PS_MAP_ID' => $PS_MAP_ID )); $this->addJS( - 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY.'&libraries=places&language='. - $this->context->language->iso_code.'®ion='.$this->context->country->iso_code + 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY. + '&libraries=places,marker&loading=async&callback=initMap&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); } } diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index 08813efcb..75feb0dd4 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -214,7 +214,7 @@ class AdminAddHotelController extends ModuleAdminController } $smartyVars['state_var'] = $stateOptions; - $smartyVars['enabledDisplayMap'] = Configuration::get('PS_API_KEY') && Configuration::get('WK_GOOGLE_ACTIVE_MAP'); + $smartyVars['enabledDisplayMap'] = Configuration::get('PS_API_KEY') && Configuration::get('PS_MAP_ID') && Configuration::get('WK_GOOGLE_ACTIVE_MAP'); $smartyVars['ps_img_dir'] = _PS_IMG_.'l/'; $smartyVars['PS_MAX_CHECKOUT_OFFSET'] = (int) Configuration::get('PS_MAX_CHECKOUT_OFFSET'); $smartyVars['PS_MIN_BOOKING_OFFSET'] = (int) Configuration::get('PS_MIN_BOOKING_OFFSET'); @@ -605,8 +605,8 @@ class AdminAddHotelController extends ModuleAdminController $objHotelBranch->check_in = $check_in; $objHotelBranch->check_out = $check_out; $objHotelBranch->rating = $rating; - $objHotelBranch->latitude = $latitude; - $objHotelBranch->longitude = $longitude; + $objHotelBranch->latitude = Tools::ps_round($latitude, 8); + $objHotelBranch->longitude = Tools::ps_round($longitude, 8); $objHotelBranch->map_formated_address = $map_formated_address; $objHotelBranch->map_input_text = $map_input_text; $objHotelBranch->save(); @@ -984,15 +984,16 @@ class AdminAddHotelController extends ModuleAdminController 'primaryHotelId' => Configuration::get('WK_PRIMARY_HOTEL'), 'disableHotelMsg' => $this->l('Primary hotel for website will be updated to first available active hotel.', null, true), 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), + 'PS_MAP_ID' => ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) ) ); // GOOGLE MAP $language = $this->context->language; $country = $this->context->country; - if ($PS_API_KEY = Configuration::get('PS_API_KEY')) { + if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && $PS_MAP_ID) { $this->addJS( - 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY.'&libraries=places&language='. - $language->iso_code.'®ion='.$country->iso_code + 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY.'&libraries=places,marker&loading=async&language='. + $language->iso_code.'®ion='.$country->iso_code.'&callback=initGoogleMaps' ); } //tinymce diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php index ca6e55912..9cc4d589a 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php @@ -397,6 +397,11 @@ class AdminHotelGeneralSettingsController extends ModuleAdminController 'hint' => $this->l('Unique API key for Google Maps.'), 'type' => 'text', ), + 'PS_MAP_ID' => array( + 'title' => $this->l('Google Maps Id'), + 'hint' => $this->l('Map Id for Google Maps.'), + 'type' => 'text' + ), 'WK_GOOGLE_ACTIVE_MAP' => array( 'title' => $this->l('Display Google Maps For Hotel Location'), 'cast' => 'intval', diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index 8da3931ea..41b38b695 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -285,6 +285,7 @@ class HotelReservationSystem extends Module if (Tools::getValue('controller') == 'category') { if (($apiKey = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP') + && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) ) { $idCategory = Tools::getValue('id_category'); $idHotel = HotelBranchInformation::getHotelIdByIdCategory($idCategory); @@ -299,13 +300,14 @@ class HotelReservationSystem extends Module 'longitude' => $objHotel->longitude, 'map_input_text' => $objHotel->map_input_text, ), + 'PS_MAP_ID' => $PS_MAP_ID, 'hotel_name' => $objHotel->hotel_name, 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), )); $this->context->controller->addJS( - 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places&language='. - $this->context->language->iso_code.'®ion='.$this->context->country->iso_code + 'https://maps.googleapis.com/maps/api/js?key='.$apiKey. + '&libraries=places,marker&loading=async&callback=initMap&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); $this->context->controller->addJS($this->getPathUri().'views/js/searchResultsMap.js'); $this->context->controller->addCSS($this->getPathUri().'views/css/searchResultsMap.css'); diff --git a/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css b/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css index 5dd54412f..b27f73368 100644 --- a/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css +++ b/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css @@ -472,10 +472,7 @@ p.room_cat_data } #pac-input { - background-color: #fff; - height: 38px; width: 300px; - font-size: 14px; text-overflow: ellipsis; } diff --git a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js index c6e6a80a2..24d0ea886 100644 --- a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js +++ b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js @@ -22,17 +22,12 @@ var GoogleMapsManager = { defaultZoom: 10, map: null, markers: [], - placesService: null, + placeService: null, init: function(jQDiv) { this.mapDiv = jQDiv; this.geocoder = new google.maps.Geocoder(); }, - setPlacesService: function() { - if (!this.placesService && this.map) { - this.placesService = new google.maps.places.PlacesService(this.map); - } - }, setDefaultLatLng: function(cb) { if (!this.defaultLatLng) { var latitude = Number($("#loclatitude").val()); @@ -64,6 +59,24 @@ var GoogleMapsManager = { } } }, + fetchFields: async function(request) { + if (!request.placeId) return; + const place = new google.maps.places.Place({ + id: request.placeId + }); + + const fieldsRequest = { + fields: ["displayName", "formattedAddress", "location"] + }; + + try { + await place.fetchFields(fieldsRequest); + this.placeService = place; + return place; + } catch (error) { + console.log(error); + } + }, initMap: function(cb) { if (!this.map) { var that = this; @@ -71,85 +84,26 @@ var GoogleMapsManager = { that.map = new google.maps.Map($(that.mapDiv).get(0), { zoom: that.defaultZoom, clickableIcons: true, + mapId: PS_MAP_ID }); that.map.setCenter(that.defaultLatLng); if (that.defaultLatLng && that.formattedAddress) { that.addMarker(that.defaultLatLng, null, that.formattedAddress); } - that.setPlacesService(); - // register marker events that.map.addListener('click', function (e) { var latLng = e.latLng; - - var isInfoWindowNeeded = true; // if it is a Place Of Interest (POI), event contains the property 'placeId' if (Object.hasOwn(e, 'placeId')) { - isInfoWindowNeeded = false; - - that.geocoder.geocode({ location: latLng }, function (results, status) { - if (status == google.maps.GeocoderStatus.OK && results[0]) { - var request = { - placeId: e.placeId, - fields: ['name'], - }; - - that.placesService.getDetails(request, function(place, status) { - if (status === google.maps.places.PlacesServiceStatus.OK) { - var content = '
' + - results[0].formatted_address + '
' + - results[0].formatted_address + '
' + place.formatted_address + '
' + address.formatted_address + '
' + address.formatted_address + '