Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: JS issue due to map if Google Maps API key is set and hotel location is not set #931

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions controllers/front/ContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,12 @@ public function setMedia()
$this->addJS(_PS_JS_DIR_.'validate.js');

// GOOGLE MAP
$language = $this->context->language;
$country = $this->context->country;
$PS_API_KEY = Configuration::get('PS_API_KEY');
$this->addJs("https://maps.googleapis.com/maps/api/js?key=$PS_API_KEY&libraries=places&language=$language->iso_code&region=$country->iso_code");
if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) {
$this->addJS(
'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY.
'&libraries=places&language='.$this->context->language->iso_code.'&region='.$this->context->country->iso_code
);
}
}

/**
Expand Down Expand Up @@ -303,7 +305,7 @@ public function initContent()
);

//By webkul to send hotels Map Informations for google Map.
if (Configuration::get('WK_GOOGLE_ACTIVE_MAP')) {
if (Configuration::get('PS_API_KEY') && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) {
$hotelLocationArray = $objHotelInfo->getMapFormatHotelsInfo(Configuration::get('WK_MAP_HOTEL_ACTIVE_ONLY'));
if ($hotelLocationArray) {
$this->context->smarty->assign('hotelLocationArray', json_encode($hotelLocationArray));
Expand Down
33 changes: 21 additions & 12 deletions controllers/front/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,27 @@ public function setMedia()
$this->addJqueryPlugin('jqzoom');
}

if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) {
$this->addJS(
'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY.'&libraries=places&language='.
$this->context->language->iso_code.'&region='.$this->context->country->iso_code
);
if (($PS_API_KEY = Configuration::get('PS_API_KEY'))) {
$objHotelRoomType = new HotelRoomType();
$roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($this->product->id);
if ($roomTypeInfo) {
$objHotelBranchInformation = new HotelBranchInformation($roomTypeInfo['id_hotel']);
if (floatval($objHotelBranchInformation->latitude) != 0
&& floatval($objHotelBranchInformation->longitude) != 0
) {
Media::addJsDef(array(
'hotel_location' => array(
'latitude' => $objHotelBranchInformation->latitude,
'longitude' => $objHotelBranchInformation->longitude,
)
));

$this->addJS(
'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY.'&libraries=places&language='.
$this->context->language->iso_code.'&region='.$this->context->country->iso_code
);
}
}
}
}

Expand Down Expand Up @@ -375,13 +391,6 @@ public function initContent()
}
}

Media::addJsDef(array(
'hotel_loc' => array(
'latitude' => $hotel_branch_obj->latitude,
'longitude' => $hotel_branch_obj->longitude,
)
));

$this->context->smarty->assign(
array(
'id_hotel' => $hotel_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function renderForm()
}

$smartyVars['state_var'] = $stateOptions;
$smartyVars['enabledDisplayMap'] = 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/';

$this->context->smarty->assign($smartyVars);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,9 @@ $(document).on('click', 'button.gm-ui-hover-effect', function () {

function initGoogleMaps() {
if (typeof enabledDisplayMap != 'undefined'
&& typeof google === 'object'
&& $('#googleMapContainer').length
&& typeof google == 'object'
&& typeof google.maps == 'object'
) {
GoogleMapsManager.init($('#map'));
GoogleMapsManager.initMap();
Expand Down
8 changes: 6 additions & 2 deletions modules/hotelreservationsystem/views/js/searchResultsMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function initMap() {
lng: Number(hotel_location.longitude),
};

const map = new google.maps.Map($($('#search-results-wrap .map-wrap')).get(0), {
const map = new google.maps.Map($('#search-results-wrap .map-wrap').get(0), {
zoom: 10,
center: hotelLocation,
disableDefaultUI: true,
Expand All @@ -49,7 +49,11 @@ function initMap() {
}

$(document).ready(function() {
if (typeof google == 'object' && typeof hotel_location == 'object') {
if (typeof hotel_location == 'object'
&& $('#search-results-wrap .map-wrap').length
&& typeof google == 'object'
&& typeof google.maps == 'object'
) {
initMap();
}
});
6 changes: 5 additions & 1 deletion themes/hotel-reservation-theme/js/contact-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ $(document).ready(function() {
showProductSelect($('select[name=id_order]').attr('value'));

//By Webkul JS for Map locations of the hotels on google Map
if (hotelLocationArray) {
if (typeof hotelLocationArray != 'undefined'
&& $('#map').length
&& typeof google == 'object'
&& typeof google.maps == 'object'
) {
initMap();
}
});
Expand Down
10 changes: 7 additions & 3 deletions themes/hotel-reservation-theme/js/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,11 @@ $(document).ready(function() {
e.preventDefault();
});

if (typeof google === 'object') {
if (typeof hotel_location == 'object'
&& $('#room_type_map_tab .map-wrap').length
&& typeof google == 'object'
&& typeof google.maps == 'object'
) {
initMap();
}

Expand Down Expand Up @@ -1291,8 +1295,8 @@ function initMap() {
});

const hotelLatLng = {
lat: Number(hotel_loc.latitude),
lng: Number(hotel_loc.longitude),
lat: Number(hotel_location.latitude),
lng: Number(hotel_location.longitude),
};

map.setCenter(hotelLatLng);
Expand Down