fixed : make map id optional

This commit is contained in:
azhar bhat
2026-08-18 19:26:25 +05:30
parent a1ceb1b2a9
commit ed6bc80e37
15 changed files with 144 additions and 79 deletions

View File

@@ -237,11 +237,11 @@ class ContactControllerCore extends FrontController
$this->addJS(_PS_JS_DIR_.'validate.js');
// GOOGLE MAP
if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) {
if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && 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,
'PS_MAP_ID' => Configuration::get('PS_MAP_ID'),
)
);
$this->addJS(

View File

@@ -639,7 +639,6 @@ 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
@@ -647,7 +646,7 @@ 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,
'PS_MAP_ID' => Configuration::get('PS_MAP_ID'),
));
$this->addJS(

View File

@@ -884,7 +884,6 @@ 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
@@ -892,7 +891,7 @@ 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,
'PS_MAP_ID' => Configuration::get('PS_MAP_ID'),
));
$this->addJS(
'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places,marker&loading=async&callback=initMap&language='.

View File

@@ -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') && Configuration::get('PS_MAP_ID')) {
if ($displayHotelMap && Configuration::get('PS_API_KEY') && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) {
if ($hotelLocations = $objHotelInfo->getMapFormatHotelsInfo(Configuration::get('WK_MAP_HOTEL_ACTIVE_ONLY'))) {
$hotelLocationArray = str_replace(array('\n', '\r'), '', json_encode($hotelLocations));
}
@@ -144,11 +144,11 @@ 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')) && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) {
if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && 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
'PS_MAP_ID' => Configuration::get('PS_MAP_ID')
)
);

View File

@@ -66,9 +66,7 @@ class ProductControllerCore extends FrontController
$this->addJqueryPlugin('jqzoom');
}
if (($PS_API_KEY = Configuration::get('PS_API_KEY'))
&& ($PS_MAP_ID = Configuration::get('PS_MAP_ID'))
) {
if ($PS_API_KEY = Configuration::get('PS_API_KEY')) {
$objHotelRoomType = new HotelRoomType();
if ($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($this->product->id)) {
$objHotelBranchInformation = new HotelBranchInformation($roomTypeInfo['id_hotel']);
@@ -81,7 +79,7 @@ class ProductControllerCore extends FrontController
'longitude' => $objHotelBranchInformation->longitude,
),
'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')),
'PS_MAP_ID' => $PS_MAP_ID
'PS_MAP_ID' => Configuration::get('PS_MAP_ID')
));
$this->addJS(

View File

@@ -55,8 +55,8 @@ class HotelBranchInformation extends ObjectModel
'check_in' => array('type' => self::TYPE_STRING, 'required' => true),
'check_out' => array('type' => self::TYPE_STRING, 'required' => true),
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'latitude' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
'longitude' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
'latitude' => array('type' => self::TYPE_FLOAT, 'validate' => 'isCoordinate'),
'longitude' => array('type' => self::TYPE_FLOAT, 'validate' => 'isCoordinate'),
'map_formated_address' => array('type' => self::TYPE_HTML, 'validate' => 'isCleanHtml'),
'map_input_text' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
'active_refund' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),

View File

@@ -211,7 +211,7 @@ class AdminAddHotelController extends ModuleAdminController
}
$smartyVars['state_var'] = $stateOptions;
$smartyVars['enabledDisplayMap'] = Configuration::get('PS_API_KEY') && Configuration::get('PS_MAP_ID') && Configuration::get('WK_GOOGLE_ACTIVE_MAP');
$smartyVars['enabledDisplayMap'] = Configuration::get('PS_API_KEY') && 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');
@@ -258,8 +258,8 @@ class AdminAddHotelController extends ModuleAdminController
$maxCheckoutOffset = trim(Tools::getValue('max_checkout_offset'));
$enableUseGlobalMinBookingOffset = Tools::getValue('enable_use_global_min_booking_offset');
$minBookingOffset = trim(Tools::getValue('min_booking_offset'));
$latitude = Tools::getValue('loclatitude');
$longitude = Tools::getValue('loclongitude');
$latitude = number_format((float) Tools::getValue('loclatitude'), 8, '.', '');
$longitude = number_format((float) Tools::getValue('loclongitude'), 8, '.', '');
$map_formated_address = Tools::getValue('locformatedAddr');
$map_input_text = Tools::getValue('googleInputField');
$hotelAmenities = Tools::getValue('id_amenities', array());
@@ -610,8 +610,8 @@ class AdminAddHotelController extends ModuleAdminController
$objHotelBranch->check_in = $check_in;
$objHotelBranch->check_out = $check_out;
$objHotelBranch->rating = $rating;
$objHotelBranch->latitude = Validate::isFloat($latitude) ? Tools::ps_round($latitude, 8) : $latitude;
$objHotelBranch->longitude = Validate::isFloat($longitude) ? Tools::ps_round($longitude, 8) : $longitude;
$objHotelBranch->latitude = Validate::isCoordinate($latitude) ? Tools::ps_round($latitude, 8) : $latitude;
$objHotelBranch->longitude = Validate::isCoordinate($longitude) ? Tools::ps_round($longitude, 8) : $longitude;
$objHotelBranch->map_formated_address = $map_formated_address;
$objHotelBranch->map_input_text = $map_input_text;
$objHotelBranch->save();
@@ -994,7 +994,7 @@ class AdminAddHotelController extends ModuleAdminController
// GOOGLE MAP
$language = $this->context->language;
$country = $this->context->country;
if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && $PS_MAP_ID) {
if ($PS_API_KEY = Configuration::get('PS_API_KEY')) {
$this->addJS(
'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY.'&libraries=places,marker&loading=async&language='.
$language->iso_code.'&region='.$country->iso_code.'&callback=initGoogleMaps'

View File

@@ -398,13 +398,15 @@ class AdminHotelGeneralSettingsController extends ModuleAdminController
'PS_API_KEY' => array(
'title' => $this->l('Google Maps API Key'),
'hint' => $this->l('Unique API key for Google Maps.'),
'validation' => 'isGenericName',
'type' => 'text',
),
'PS_MAP_ID' => array(
'title' => $this->l('Google Map ID'),
'hint' => $this->l('Map Id for Google Maps.'),
'hint' => $this->l('Map Id for Google Maps (optional).'),
'validation' => 'isGenericName',
'type' => 'text',
'desc' => $this->l('Google Maps API Key and Google Map ID is required to display Google Maps.')
'desc' => $this->l('Google Maps API Key is required to display Google Maps. Google Map ID is optional.')
),
'WK_GOOGLE_ACTIVE_MAP' => array(
'title' => $this->l('Display Google Maps For Hotel Location'),
@@ -621,9 +623,6 @@ class AdminHotelGeneralSettingsController extends ModuleAdminController
if (!Tools::getValue('PS_API_KEY')) {
$this->errors[] = $this->l('Please enter Google API key.');
}
if (!Tools::getValue('PS_MAP_ID')) {
$this->errors[] = $this->l('Please enter Google Map Id.');
}
}
if (!trim(Tools::getValue('PS_SHOP_NAME'))) {
$this->errors[] = $this->l('Website name field is required');

View File

@@ -288,8 +288,8 @@ 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'))
) {
$PS_MAP_ID = Configuration::get('PS_MAP_ID');
$idCategory = Tools::getValue('id_category');
$idHotel = HotelBranchInformation::getHotelIdByIdCategory($idCategory);
$objHotel = new HotelBranchInformation($idHotel, $this->context->language->id);

View File

@@ -84,11 +84,15 @@ var GoogleMapsManager = {
if (!this.map) {
var that = this;
that.setDefaultLatLng(function() {
that.map = new google.maps.Map($(that.mapDiv).get(0), {
var mapOptions = {
zoom: that.defaultZoom,
clickableIcons: true,
mapId: PS_MAP_ID
});
};
if (PS_MAP_ID) {
mapOptions.mapId = PS_MAP_ID;
}
that.map = new google.maps.Map($(that.mapDiv).get(0), mapOptions);
google.maps.event.trigger(that.map, 'resize');
that.map.setCenter(that.defaultLatLng);
if (that.defaultLatLng && that.formattedAddress) {
that.addMarker(that.defaultLatLng, null, that.formattedAddress);
@@ -171,12 +175,22 @@ var GoogleMapsManager = {
icon.style.width = '24px';
icon.style.height = '24px';
var marker = new google.maps.marker.AdvancedMarkerElement({
position: latLng,
map: that.map,
content: icon,
draggable: true,
});
var marker;
if (PS_MAP_ID) {
marker = new google.maps.marker.AdvancedMarkerElement({
position: latLng,
map: that.map,
content: icon,
draggable: true,
});
} else {
marker = new google.maps.Marker({
position: latLng,
map: that.map,
icon: PS_STORES_ICON,
draggable: true,
});
}
that.markers.push(marker);
marker.addListener('dragend', function(e) {
var latLng = {
@@ -234,10 +248,10 @@ var GoogleMapsManager = {
that.clearAllMarkers();
});
var latLng = marker.position;
var latLng = marker.position ? marker.position : marker.getPosition();
that.setFormVars({
lat: latLng.lat,
lng: latLng.lng,
lat: typeof latLng.lat === 'function' ? latLng.lat() : latLng.lat,
lng: typeof latLng.lng === 'function' ? latLng.lng() : latLng.lng,
formattedAddress: content,
inputText: $('#pac-input').val(),
});

View File

@@ -26,25 +26,38 @@ function initMap() {
lng: Number(hotel_location.longitude),
};
const map = new google.maps.Map($('#search-results-wrap .map-wrap').get(0), {
const mapOptions = {
zoom: 10,
center: hotelLocation,
disableDefaultUI: true,
fullscreenControl: true,
mapId: PS_MAP_ID
});
};
if (PS_MAP_ID) {
mapOptions.mapId = PS_MAP_ID;
}
const map = new google.maps.Map($('#search-results-wrap .map-wrap').get(0), mapOptions);
let icon = document.createElement('img');
icon.src = PS_STORES_ICON;
icon.style.width = '24px';
icon.style.height = '24px';
const marker = new google.maps.marker.AdvancedMarkerElement({
map: map,
position: hotelLocation,
title: location.hotel_name,
content: icon,
});
let marker;
if (PS_MAP_ID) {
marker = new google.maps.marker.AdvancedMarkerElement({
map: map,
position: hotelLocation,
title: location.hotel_name,
content: icon,
});
} else {
marker = new google.maps.Marker({
map: map,
position: hotelLocation,
title: location.hotel_name,
icon: PS_STORES_ICON,
});
}
marker.query = location.query || null;
marker.latitude = hotelLocation.lat;

View File

@@ -66,7 +66,7 @@ function initMap() {
hotelLocationArray = JSON.parse(hotelLocationArray);
// Display a map on the page
map = new google.maps.Map(document.getElementById("map"), {mapId: PS_MAP_ID});
map = new google.maps.Map(document.getElementById("map"), PS_MAP_ID ? {mapId: PS_MAP_ID} : {});
google.maps.event.trigger(map, 'resize');
map.setTilt(45);
@@ -84,12 +84,21 @@ function initMap() {
icon.style.width = '24px';
icon.style.height = '24px';
marker = new google.maps.marker.AdvancedMarkerElement({
map: map,
position: position,
title: location.hotel_name,
content: icon,
});
if (PS_MAP_ID) {
marker = new google.maps.marker.AdvancedMarkerElement({
map: map,
position: position,
title: location.hotel_name,
content: icon,
});
} else {
marker = new google.maps.Marker({
map: map,
position: position,
title: location.hotel_name,
icon: PS_STORES_ICON,
});
}
// Allow each marker to have an info window
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {

View File

@@ -139,25 +139,38 @@ function initMap() {
lat: Number($(this).attr('latitude')),
lng: Number($(this).attr('longitude')),
};
const map = new google.maps.Map(element, {
const mapOptions = {
zoom: 10,
center: hotelLocation,
disableDefaultUI: true,
fullscreenControl: true,
mapId: PS_MAP_ID
});
};
if (PS_MAP_ID) {
mapOptions.mapId = PS_MAP_ID;
}
const map = new google.maps.Map(element, mapOptions);
let icon = document.createElement('img');
icon.src = PS_STORES_ICON;
icon.style.width = '24px';
icon.style.height = '24px';
const marker = new google.maps.marker.AdvancedMarkerElement({
position: hotelLocation,
map: map,
title: location.hotel_name,
content: icon,
});
let marker;
if (PS_MAP_ID) {
marker = new google.maps.marker.AdvancedMarkerElement({
position: hotelLocation,
map: map,
title: location.hotel_name,
content: icon,
});
} else {
marker = new google.maps.Marker({
position: hotelLocation,
map: map,
title: location.hotel_name,
icon: PS_STORES_ICON,
});
}
marker.query = location.query || null;
marker.latitude = hotelLocation.lat;

View File

@@ -34,7 +34,7 @@ function initMap() {
hotelLocationArray = JSON.parse(hotelLocationArray);
// Display a map on the page
map = new google.maps.Map(document.getElementById("map"), {mapId: PS_MAP_ID});
map = new google.maps.Map(document.getElementById("map"), PS_MAP_ID ? {mapId: PS_MAP_ID} : {});
google.maps.event.trigger(map, 'resize');
map.setTilt(45);
@@ -52,12 +52,21 @@ function initMap() {
icon.style.width = '24px';
icon.style.height = '24px';
marker = new google.maps.marker.AdvancedMarkerElement({
map: map,
position: position,
title: location.hotel_name,
content: icon,
});
if (PS_MAP_ID) {
marker = new google.maps.marker.AdvancedMarkerElement({
map: map,
position: position,
title: location.hotel_name,
content: icon,
});
} else {
marker = new google.maps.Marker({
map: map,
position: position,
title: location.hotel_name,
icon: PS_STORES_ICON,
});
}
// Allow each marker to have an info window
google.maps.event.addListener(marker, 'click', (function(marker, i) {

View File

@@ -1310,11 +1310,14 @@ function updateRoomServiceQuantity(that) {
function initMap() {
const map = new google.maps.Map($('#room_type_map_tab .map-wrap').get(0), {
const mapOptions = {
zoom: 10,
streetViewControl: false,
mapId: PS_MAP_ID
});
};
if (PS_MAP_ID) {
mapOptions.mapId = PS_MAP_ID;
}
const map = new google.maps.Map($('#room_type_map_tab .map-wrap').get(0), mapOptions);
const hotelLatLng = {
lat: Number(hotel_location.latitude),
@@ -1326,11 +1329,20 @@ function initMap() {
icon.src = PS_STORES_ICON;
icon.style.width = '24px';
icon.style.height = '24px';
let marker = new google.maps.marker.AdvancedMarkerElement({
position: hotelLatLng,
map: map,
content: icon,
});
let marker;
if (PS_MAP_ID) {
marker = new google.maps.marker.AdvancedMarkerElement({
position: hotelLatLng,
map: map,
content: icon,
});
} else {
marker = new google.maps.Marker({
position: hotelLatLng,
map: map,
icon: PS_STORES_ICON,
});
}
const uiContent = $('#room-info-map-ui-content .hotel-info-wrap').get(0);
map.controls[google.maps.ControlPosition.LEFT_TOP].push(uiContent);