Fixed: Same location is showing on map for all hotels at order detail page of guest order tracking

This commit is contained in:
Rohit Jain
2025-02-19 15:25:34 +05:30
committed by GitHub
4 changed files with 48 additions and 42 deletions

View File

@@ -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.'&region='.$this->context->country->iso_code
);
$this->addJS(
'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places&language='.
$this->context->language->iso_code.'&region='.$this->context->country->iso_code
);
// just need to load the map once for the first order with map details. So break the loop.
break;
}
}
}
}

View File

@@ -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(

View File

@@ -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();
}

View File

@@ -177,7 +177,13 @@
{if ($obj_hotel_branch_information->latitude|floatval != 0 && $obj_hotel_branch_information->longitude|floatval != 0) && $view_on_map}
<div class="hotel-location-map">
<div class="booking-hotel-map-container"></div>
<div
class="booking-hotel-map-container"
latitude="{$obj_hotel_branch_information->latitude|escape:'html':'UTF-8'}"
longitude="{$obj_hotel_branch_information->longitude|escape:'html':'UTF-8'}"
query="{$obj_hotel_branch_information->map_input_text|escape:'html':'UTF-8'}"
title="{$obj_hotel_branch_information->hotel_name|escape:'html':'UTF-8'}">
</div>
</div>
{/if}
@@ -626,7 +632,13 @@
{if ($obj_hotel_branch_information->latitude|floatval != 0 && $obj_hotel_branch_information->longitude|floatval != 0) && $view_on_map}
<div class="hotel-location-map">
<div class="booking-hotel-map-container"></div>
<div
class="booking-hotel-map-container"
latitude="{$obj_hotel_branch_information->latitude|escape:'html':'UTF-8'}"
longitude="{$obj_hotel_branch_information->longitude|escape:'html':'UTF-8'}"
query="{$obj_hotel_branch_information->map_input_text|escape:'html':'UTF-8'}"
title="{$obj_hotel_branch_information->hotel_name|escape:'html':'UTF-8'}">
</div>
</div>
{/if}