From 316d80b442558a098577a44420d7c48377429c5c Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 15 Jul 2022 18:24:05 +0530 Subject: [PATCH 1/4] Add maps to search results and room type detail pages --- config/xml/themes/default.xml | 1 + controllers/front/ContactController.php | 6 ++- controllers/front/ProductController.php | 44 ++++++++++++++++ install/data/theme.sql | 18 +++++++ .../hotelreservationsystem.php | 39 ++++++++++++++- .../views/css/searchResultsMap.css | 26 ++++++++++ .../views/js/searchResultsMap.js | 50 +++++++++++++++++++ .../views/templates/hook/searchResultsMap.tpl | 34 +++++++++++++ .../hotel-reservation-theme/contact-form.tpl | 7 +-- .../css/contact-form.css | 21 ++++++++ .../hotel-reservation-theme/css/product.css | 50 ++++++++++++++++++- .../js/contact-form.js | 10 +++- themes/hotel-reservation-theme/js/product.js | 29 +++++++++-- themes/hotel-reservation-theme/product.tpl | 27 +++++++++- 14 files changed, 349 insertions(+), 13 deletions(-) create mode 100644 modules/hotelreservationsystem/views/css/searchResultsMap.css create mode 100644 modules/hotelreservationsystem/views/js/searchResultsMap.js create mode 100644 modules/hotelreservationsystem/views/templates/hook/searchResultsMap.tpl diff --git a/config/xml/themes/default.xml b/config/xml/themes/default.xml index 96567894c..a015afc46 100644 --- a/config/xml/themes/default.xml +++ b/config/xml/themes/default.xml @@ -119,6 +119,7 @@ + diff --git a/controllers/front/ContactController.php b/controllers/front/ContactController.php index 54c5dbe17..2c058ab34 100644 --- a/controllers/front/ContactController.php +++ b/controllers/front/ContactController.php @@ -268,6 +268,7 @@ class ContactControllerCore extends FrontController $objHotelInfo = new HotelBranchInformation(); if ($hotelsInfo = $objHotelInfo->hotelBranchesInfo(false, 1, 1)) { foreach ($hotelsInfo as &$hotel) { + $hotel['address_info'] = $objHotelInfo->getAddress($hotel['id']); if (isset($hotel['id_cover_img']) && $hotel['id_cover_img'] && Validate::isLoadedObject( @@ -287,7 +288,8 @@ class ContactControllerCore extends FrontController } } } - $contactKey = md5(uniqid(microtime(), true)); + + $contactKey = md5(uniqid(microtime(), true)); $this->context->cookie->__set('contactFormKey', $contactKey); $this->context->smarty->assign( array( @@ -297,7 +299,7 @@ class ContactControllerCore extends FrontController 'gblHtlAddress' => $gblHtlAddress, 'contacts' => Contact::getContacts($this->context->language->id), 'message' => html_entity_decode(Tools::getValue('message')), - 'contactKey' => $contactKey, + 'contactKey' => $contactKey, ) ); diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index ad80cf3ca..8105989da 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -63,6 +63,13 @@ class ProductControllerCore extends FrontController if (Configuration::get('PS_DISPLAY_JQZOOM') == 1) { $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.'®ion='.$this->context->country->iso_code + ); + } } public function canonicalRedirection($canonical_url = '') @@ -228,6 +235,7 @@ class ProductControllerCore extends FrontController } } + $this->assignHotel(); // Assign template vars related to the category + execute hooks related to the category $this->assignCategory(); // Assign template vars related to the price and tax @@ -451,6 +459,7 @@ class ProductControllerCore extends FrontController 'category-'.(isset($this->category) ? $this->category->getFieldByLang('link_rewrite') : ''), ), 'display_discount_price' => Configuration::get('PS_DISPLAY_DISCOUNT_PRICE'), + 'display_google_maps' => Configuration::get('WK_GOOGLE_ACTIVE_MAP'), ) ); } @@ -745,6 +754,41 @@ class ProductControllerCore extends FrontController ); } + /** + * Assign template vars related to hotel + */ + protected function assignHotel() + { + if ($idRoomType = $this->product->id) { + $objHotelRoomType = new HotelRoomType($idRoomType); + $objHotelBranchInfo = new HotelBranchInformation($objHotelRoomType->id_hotel, $this->context->language->id); + if (Validate::isLoadedObject($objHotelBranchInfo)) { + $hotelAddressInfo = $objHotelBranchInfo->getAddress($objHotelBranchInfo->id); + $hotelImageLink = null; + if ($coverImage = HotelImage::getCover($objHotelBranchInfo->id)) { + $hotelImagesBaseDir = _MODULE_DIR_.'hotelreservationsystem/views/img/hotel_img/'; + $hotelImageLink = $this->context->link->getMediaLink( + $hotelImagesBaseDir.$coverImage['hotel_image_id'].'.jpg' + ); + } + + $this->context->smarty->assign(array( + 'hotel' => $objHotelBranchInfo, + 'hotel_address' => $hotelAddressInfo, + 'id_hotel' => (int) $objHotelBranchInfo->id, + 'hotel_image_link' => $hotelImageLink, + )); + + Media::addJsDef(array( + 'hotel_loc' => array( + 'latitude' => $objHotelBranchInfo->latitude, + 'longitude' => $objHotelBranchInfo->longitude, + ) + )); + } + } + } + /** * Assign template vars related to category */ diff --git a/install/data/theme.sql b/install/data/theme.sql index 9785d6955..c9ad7811a 100644 --- a/install/data/theme.sql +++ b/install/data/theme.sql @@ -138,6 +138,24 @@ UPDATE `PREFIX_hook_module` SET position = 3 WHERE id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'blockbestsellers') AND id_hook IN (@id_hook, @id_hook2); +/* displayLeftColumn */ +SET @id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayLeftColumn'); +UPDATE `PREFIX_hook_module` SET position = 1 +WHERE id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'wkroomsearchblock') +AND id_hook = @id_hook; + +UPDATE `PREFIX_hook_module` SET position = 2 +WHERE id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'wkhotelfilterblock') +AND id_hook = @id_hook; + +UPDATE `PREFIX_hook_module` SET position = 3 +WHERE id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'blockmyaccount') +AND id_hook = @id_hook; + +UPDATE `PREFIX_hook_module` SET position = 4 +WHERE id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'hotelreservationsystem') +AND id_hook = @id_hook; + /* displayFooter */ SET @id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayFooter'); UPDATE `PREFIX_hook_module` SET position = 1 diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index 0d18ff40f..46fce4421 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -98,6 +98,42 @@ class hotelreservationsystem extends Module $this->context->controller->addJS($this->_path.'/views/js/HotelReservationFront.js'); } + public function hookDisplayLeftColumn() + { + if (Tools::getValue('controller') == 'category') { + if (!Configuration::get('PS_API_KEY')) { + return; + } + + $apiKey = Configuration::get('PS_API_KEY'); + $idCategory = Tools::getValue('id_category'); + $idHotel = HotelBranchInformation::getHotelIdByIdCategory($idCategory); + $objHotel = new HotelBranchInformation($idHotel, $this->context->language->id); + + if (floatval($objHotel->latitude) == 0 && floatval($objHotel->longitude) == 0) { + return; + } + + Media::addJsDef(array( + 'hotel_location' => array( + 'latitude' => $objHotel->latitude, + 'longitude' => $objHotel->longitude, + ), + 'hotel_name' => $objHotel->hotel_name, + )); + + $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 + ); + $this->context->controller->addJS($this->getPathUri().'views/js/searchResultsMap.js'); + $this->context->controller->addCSS($this->getPathUri().'views/css/searchResultsMap.css'); + + $this->context->smarty->assign('hotel', $objHotel); + return $this->display(__FILE__, 'searchResultsMap.tpl'); + } + } + public function hookDisplayAfterHookTop() { if (Tools::getValue('controller') == 'index') { @@ -514,7 +550,8 @@ class hotelreservationsystem extends Module 'actionObjectProfileAddAfter', 'actionObjectProfileDeleteBefore', 'actionObjectGroupDeleteBefore', - 'actionOrderStatusPostUpdate' + 'actionOrderStatusPostUpdate', + 'displayLeftColumn', ) ); } diff --git a/modules/hotelreservationsystem/views/css/searchResultsMap.css b/modules/hotelreservationsystem/views/css/searchResultsMap.css new file mode 100644 index 000000000..bd1fa6649 --- /dev/null +++ b/modules/hotelreservationsystem/views/css/searchResultsMap.css @@ -0,0 +1,26 @@ +/** +* 2010-2022 Webkul. +* +* NOTICE OF LICENSE +* +* All right is reserved, +* Please go through LICENSE.txt file inside our module +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade this module to newer +* versions in the future. If you wish to customize this module for your +* needs please refer to CustomizationPolicy.txt file inside our module for more information. +* +* @author Webkul IN +* @copyright 2010-2022 Webkul IN +* @license LICENSE.txt +*/ + +#search-results-wrap .map-wrap { + height: 200px; +} + +#search-results-wrap .lf_sub_cont { + max-height: none; +} diff --git a/modules/hotelreservationsystem/views/js/searchResultsMap.js b/modules/hotelreservationsystem/views/js/searchResultsMap.js new file mode 100644 index 000000000..29bd49c3e --- /dev/null +++ b/modules/hotelreservationsystem/views/js/searchResultsMap.js @@ -0,0 +1,50 @@ +/** +* 2010-2022 Webkul. +* +* NOTICE OF LICENSE +* +* All right is reserved, +* Please go through LICENSE.txt file inside our module +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade this module to newer +* versions in the future. If you wish to customize this module for your +* needs please refer to CustomizationPolicy.txt file inside our module for more information. +* +* @author Webkul IN +* @copyright 2010-2022 Webkul IN +* @license LICENSE.txt +*/ + +function initMap() { + const hotelLocation = { + lat: Number(hotel_location.latitude), + lng: Number(hotel_location.longitude), + }; + + const map = new google.maps.Map($($('#search-results-wrap .map-wrap')).get(0), { + zoom: 10, + center: hotelLocation, + disableDefaultUI: true, + fullscreenControl: true, + }); + + const marker = new google.maps.Marker({ + position: hotelLocation, + map: map, + title: hotel_name, + }); + + marker.addListener('click', function() { + const directionsLink = 'https://www.google.com/maps/dir/?api=1&destination='+ + hotelLocation.lat+','+hotelLocation.lng; + window.open(directionsLink, '_blank'); + }); +} + +$(document).ready(function() { + if (typeof google == 'object' && typeof hotel_location == 'object') { + initMap(); + } +}); diff --git a/modules/hotelreservationsystem/views/templates/hook/searchResultsMap.tpl b/modules/hotelreservationsystem/views/templates/hook/searchResultsMap.tpl new file mode 100644 index 000000000..445244bdd --- /dev/null +++ b/modules/hotelreservationsystem/views/templates/hook/searchResultsMap.tpl @@ -0,0 +1,34 @@ +{** +* 2010-2022 Webkul. +* +* NOTICE OF LICENSE +* +* All right is reserved, +* Please go through LICENSE.txt file inside our module +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade this module to newer +* versions in the future. If you wish to customize this module for your +* needs please refer to CustomizationPolicy.txt file inside our module for more information. +* +* @author Webkul IN +* @copyright 2010-2022 Webkul IN +* @license LICENSE.txt +*} + +
+
+
+
+ {l s='Directions' mod='hotelreservationsystem'} +
+
+
+
+
+ {if ($hotel->latitude|floatval != 0 && $hotel->longitude|floatval != 0)} +
+ {/if} +
+
diff --git a/themes/hotel-reservation-theme/contact-form.tpl b/themes/hotel-reservation-theme/contact-form.tpl index 435b4047d..8f541bf70 100644 --- a/themes/hotel-reservation-theme/contact-form.tpl +++ b/themes/hotel-reservation-theme/contact-form.tpl @@ -183,7 +183,7 @@

{$hotel['hotel_name']}

-

{$hotel['address']}, {$hotel['city']}, {if {$hotel['state_name']}}{$hotel['state_name']},{/if} {$hotel['country_name']}, {$hotel['zipcode']}

+

{$hotel['address_info']['address1']}, {$hotel['address_info']['city']}, {if {$hotel['address_info']['state']}}{$hotel['address_info']['state']},{/if} {$hotel['address_info']['country']}, {$hotel['address_info']['postcode']}

{if $hotel['latitude'] != 0 || $hotel['longitude'] != 0}

@@ -192,7 +192,7 @@

{/if}

- {$hotel['phone']} + {$hotel['address_info']['phone']}

{$hotel['email']} @@ -217,6 +217,7 @@ {strip} {addJsDefL name='contact_fileDefaultHtml'}{l s='No file selected' js=1}{/addJsDefL} {addJsDefL name='contact_fileButtonHtml'}{l s='Choose File' js=1}{/addJsDefL} + {addJsDefL name='contact_map_get_dirs'}{l s='Get Directions' js=1}{/addJsDefL} {/strip} {if isset($hotelLocationArray)} {strip} @@ -226,4 +227,4 @@ {strip} {addJsDef hotelLocationArray = 0} {/strip} -{/if} \ No newline at end of file +{/if} diff --git a/themes/hotel-reservation-theme/css/contact-form.css b/themes/hotel-reservation-theme/css/contact-form.css index ca81ab3b9..5ffae05e0 100644 --- a/themes/hotel-reservation-theme/css/contact-form.css +++ b/themes/hotel-reservation-theme/css/contact-form.css @@ -126,6 +126,7 @@ float: left; padding: 15px 0px; width: 100%; + height: 90%; } .htl-contact-page .hotel-city-container>span { font-size: 24px; @@ -253,3 +254,23 @@ width: 100%; height: 100%; } + +#map .view-link { + padding-top: 4px; +} + +.gm-btn-get-directions { + text-decoration: none; + color: #427fed; + font-weight: bold; +} + +.gm-btn-get-directions:hover { + text-decoration: underline; + color: #427fed; +} + +.gm-btn-get-directions:focus { + outline: none; + color: #427fed; +} diff --git a/themes/hotel-reservation-theme/css/product.css b/themes/hotel-reservation-theme/css/product.css index e3694e19f..837dd5a7f 100644 --- a/themes/hotel-reservation-theme/css/product.css +++ b/themes/hotel-reservation-theme/css/product.css @@ -1469,4 +1469,52 @@ Quick View Styles #rooms_extra_demands .accordion-section-content { display:none; border-top: 1px solid #eee; - padding-top: 15px;} */ \ No newline at end of file + padding-top: 15px;} */ + +#room_type_map_tab .map-wrap { + min-height: 500px; +} + +#room_type_map_tab .hotel-info-wrap { + max-width: 300px; + background-color: #fff; + padding: 12px; + margin: 0 0 20px 10px; + border-radius: 2px; + box-shadow: 0 2px 6px rgba(0,0,0,.3); + display: flex; +} + +#room_type_map_tab .hotel-info-wrap .hotel-image-wrap { + padding-right: 8px; +} + +#room_type_map_tab .hotel-info-wrap .hotel-image-wrap img { + max-width: 70px; + max-height: 70px; +} + +#room_type_map_tab .hotel-info-wrap .name { + font-size: 14px; + font-weight: bold; + color: #1a73e8; + margin-bottom: 6px; +} + +#room_type_map_tab .hotel-info-wrap .address, +#room_type_map_tab .hotel-info-wrap .contact { + font-size: 13px; + font-weight: normal; + color: #555; +} + +#room_type_map_tab .hotel-info-wrap .address { + margin-bottom: 6px; +} + +#room_type_map_tab .hotel-info-wrap .get-directions { + background-color: #186bd7; + border-radius: 2px; + color: #fff; + padding: 5px 10px; +} diff --git a/themes/hotel-reservation-theme/js/contact-form.js b/themes/hotel-reservation-theme/js/contact-form.js index 0023a18a8..cade7f70c 100644 --- a/themes/hotel-reservation-theme/js/contact-form.js +++ b/themes/hotel-reservation-theme/js/contact-form.js @@ -94,7 +94,13 @@ function initMap() { // Allow each marker to have an info window google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { - infoWindow.setContent(location.map_formated_address); + var directionsLink = 'https://www.google.com/maps/dir/?api=1&destination='+ + location.latitude+','+location.longitude; + var content = '

'+location.hotel_name+'
'+ + location.map_formated_address+ + '
'; + infoWindow.setContent(content); infoWindow.open(map, marker); } })(marker, i)); @@ -108,4 +114,4 @@ function initMap() { // this.setZoom(8); google.maps.event.removeListener(boundsListener); }); -} \ No newline at end of file +} diff --git a/themes/hotel-reservation-theme/js/product.js b/themes/hotel-reservation-theme/js/product.js index 01ecd1ec4..66577af24 100644 --- a/themes/hotel-reservation-theme/js/product.js +++ b/themes/hotel-reservation-theme/js/product.js @@ -113,7 +113,6 @@ if (typeof combinations !== 'undefined' && combinations) } combinations = combinationsJS; } -/* */ $(document).ready(function() { var url_found = checkUrl(); @@ -851,7 +850,6 @@ function serialScrollResizeThumbContainer() { } } - // Change the current product images regarding the combination selected function refreshProductImages(id_product_attribute) { id_product_attribute = parseInt(id_product_attribute); @@ -959,7 +957,6 @@ function colorPickerClick(elt) { $(elt).parent().parent().parent().children('.color_pick_hidden').val(id_attribute); } - function getProductAttribute() { // get every attributes values request = ''; @@ -1263,8 +1260,34 @@ $(document).ready(function() { } e.preventDefault(); }); + + if (typeof google === 'object') { + initMap(); + } }); +function initMap() { + const map = new google.maps.Map($('#room_type_map_tab .map-wrap').get(0), { + zoom: 10, + streetViewControl: false, + }); + + const hotelLatLng = { + lat: Number(hotel_loc.latitude), + lng: Number(hotel_loc.longitude), + }; + + map.setCenter(hotelLatLng); + + const marker = new google.maps.Marker({ + position: hotelLatLng, + map: map, + }); + + const uiContent = $('#room-info-map-ui-content .hotel-info-wrap').get(0); + map.controls[google.maps.ControlPosition.LEFT_TOP].push(uiContent); +} + function changeRoomTypeDemands() { var qty_wntd = $('#quantity_wanted').val(); if (qty_wntd == '' || !$.isNumeric(qty_wntd)) { diff --git a/themes/hotel-reservation-theme/product.tpl b/themes/hotel-reservation-theme/product.tpl index c7b91d609..1deb33990 100644 --- a/themes/hotel-reservation-theme/product.tpl +++ b/themes/hotel-reservation-theme/product.tpl @@ -182,7 +182,10 @@
@@ -275,6 +278,28 @@ {l s='Non Refundable'} {/if}
+ {if $display_google_maps && ($hotel->latitude|floatval != 0 && $hotel->longitude|floatval != 0)} +
+
+ +
+ {/if} {if isset($HOOK_PRODUCT_TAB_CONTENT) && $HOOK_PRODUCT_TAB_CONTENT}{$HOOK_PRODUCT_TAB_CONTENT}{/if}
From 2e438a4923052d7194534711708dd1d9159c0f69 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Mon, 18 Jul 2022 11:38:23 +0530 Subject: [PATCH 2/4] Update HotelBranchInformation::getMapFormatHotelsInfo() --- .../classes/HotelBranchInformation.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelBranchInformation.php b/modules/hotelreservationsystem/classes/HotelBranchInformation.php index 0d5f94312..de691e339 100644 --- a/modules/hotelreservationsystem/classes/HotelBranchInformation.php +++ b/modules/hotelreservationsystem/classes/HotelBranchInformation.php @@ -531,13 +531,15 @@ class HotelBranchInformation extends ObjectModel $idLang = $context->language->id; } - $sql = 'SELECT hbl.`hotel_name`, hbi.`phone`, hbi.`email`, hbi.`city`, cl.`name` AS country, hbi.`zipcode`, - hbi.`address`, hbi.`latitude`, hbi.`longitude`, hbi.`map_formated_address`, hbi.`map_input_text` + $sql = 'SELECT hbl.`hotel_name`, a.`phone`, hbi.`email`, a.`city`, cl.`name` AS country, a.`postcode`, + a.`address1`, hbi.`latitude`, hbi.`longitude`, hbi.`map_formated_address`, hbi.`map_input_text` FROM `'._DB_PREFIX_.'htl_branch_info` AS hbi INNER JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbl ON (hbl.`id` = hbi.`id` AND hbl.`id_lang` = '.(int)$idLang.') + INNER JOIN `'._DB_PREFIX_.'address` a + ON (a.`id_hotel` = hbi.`id`) INNER JOIN `'._DB_PREFIX_.'country_lang` AS cl - ON (cl.`id_country` = hbi.`country_id` AND cl.`id_lang` = '.(int)$idLang.") + ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)$idLang.") WHERE hbi.`latitude` != 0 AND hbi.`longitude` != 0"; if ($active !== false) { From 149af1f1ff19d6193633d272f3426d410ceeb4c4 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Mon, 26 Sep 2022 19:27:26 +0530 Subject: [PATCH 3/4] Fix extra data assignment and address access issues --- controllers/front/ContactController.php | 1 - controllers/front/ProductController.php | 57 +++++++------------ .../classes/HotelBranchInformation.php | 9 ++- .../hotel-reservation-theme/contact-form.tpl | 4 +- themes/hotel-reservation-theme/product.tpl | 12 ++-- 5 files changed, 33 insertions(+), 50 deletions(-) diff --git a/controllers/front/ContactController.php b/controllers/front/ContactController.php index 2c058ab34..f4cbe4680 100644 --- a/controllers/front/ContactController.php +++ b/controllers/front/ContactController.php @@ -268,7 +268,6 @@ class ContactControllerCore extends FrontController $objHotelInfo = new HotelBranchInformation(); if ($hotelsInfo = $objHotelInfo->hotelBranchesInfo(false, 1, 1)) { foreach ($hotelsInfo as &$hotel) { - $hotel['address_info'] = $objHotelInfo->getAddress($hotel['id']); if (isset($hotel['id_cover_img']) && $hotel['id_cover_img'] && Validate::isLoadedObject( diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index 8105989da..b491a1fbf 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -235,7 +235,6 @@ class ProductControllerCore extends FrontController } } - $this->assignHotel(); // Assign template vars related to the category + execute hooks related to the category $this->assignCategory(); // Assign template vars related to the price and tax @@ -351,9 +350,25 @@ class ProductControllerCore extends FrontController } /*End*/ + $hotelImageLink = null; + if ($coverImage = HotelImage::getCover($hotel_id)) { + $hotelImagesBaseDir = _MODULE_DIR_.'hotelreservationsystem/views/img/hotel_img/'; + $hotelImageLink = $this->context->link->getMediaLink( + $hotelImagesBaseDir.$coverImage['hotel_image_id'].'.jpg' + ); + } + + Media::addJsDef(array( + 'hotel_loc' => array( + 'latitude' => $hotel_branch_obj->latitude, + 'longitude' => $hotel_branch_obj->longitude, + ) + )); + if (Tools::getValue('error')) { $this->context->smarty->assign('error', Tools::getValue('error')); } + if (Module::isInstalled('productcomments')) { $this->context->smarty->assign( array( @@ -378,9 +393,14 @@ class ProductControllerCore extends FrontController 'hotel_check_in' => date('h:i a', strtotime($hotel_branch_obj->check_in)), 'hotel_check_out' => date('h:i a', strtotime($hotel_branch_obj->check_out)), 'hotel_location' => $hotel_location, + 'hotel_latitude' => $hotel_branch_obj->latitude, + 'hotel_longitude' => $hotel_branch_obj->longitude, + 'hotel_address1' => $addressInfo['address1'], + 'hotel_phone' => $addressInfo['phone'], 'hotel_name' => $hotel_name, 'hotel_policies' => $hotel_policies, 'hotel_features' => $htl_features, + 'hotel_image_link' => $hotelImageLink, 'ftr_img_src' => _PS_IMG_.'rf/', 'order_date_restrict' => $order_date_restrict ) @@ -754,41 +774,6 @@ class ProductControllerCore extends FrontController ); } - /** - * Assign template vars related to hotel - */ - protected function assignHotel() - { - if ($idRoomType = $this->product->id) { - $objHotelRoomType = new HotelRoomType($idRoomType); - $objHotelBranchInfo = new HotelBranchInformation($objHotelRoomType->id_hotel, $this->context->language->id); - if (Validate::isLoadedObject($objHotelBranchInfo)) { - $hotelAddressInfo = $objHotelBranchInfo->getAddress($objHotelBranchInfo->id); - $hotelImageLink = null; - if ($coverImage = HotelImage::getCover($objHotelBranchInfo->id)) { - $hotelImagesBaseDir = _MODULE_DIR_.'hotelreservationsystem/views/img/hotel_img/'; - $hotelImageLink = $this->context->link->getMediaLink( - $hotelImagesBaseDir.$coverImage['hotel_image_id'].'.jpg' - ); - } - - $this->context->smarty->assign(array( - 'hotel' => $objHotelBranchInfo, - 'hotel_address' => $hotelAddressInfo, - 'id_hotel' => (int) $objHotelBranchInfo->id, - 'hotel_image_link' => $hotelImageLink, - )); - - Media::addJsDef(array( - 'hotel_loc' => array( - 'latitude' => $objHotelBranchInfo->latitude, - 'longitude' => $objHotelBranchInfo->longitude, - ) - )); - } - } - } - /** * Assign template vars related to category */ diff --git a/modules/hotelreservationsystem/classes/HotelBranchInformation.php b/modules/hotelreservationsystem/classes/HotelBranchInformation.php index de691e339..20e69c5f7 100644 --- a/modules/hotelreservationsystem/classes/HotelBranchInformation.php +++ b/modules/hotelreservationsystem/classes/HotelBranchInformation.php @@ -309,7 +309,8 @@ class HotelBranchInformation extends ObjectModel if (!Cache::isStored($cache_id)) { $sql = 'SELECT hbi.*, hbl.`policies`, hbl.`hotel_name`, hbl.`description`, hbl.`short_description`'; if ($detailedInfo) { - $sql .= ', hi.id as id_cover_img, a.`city`, s.`name` as `state_name`, cl.`name` as country_name'; + $sql .= ', hi.id as id_cover_img, a.`address1` as address, a.`postcode`, a.`phone`, a.`city`, + s.`name` as `state_name`, cl.`name` as country_name'; } $sql .= ' FROM `'._DB_PREFIX_.'htl_branch_info` hbi'; $sql .= ' LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbl @@ -532,12 +533,11 @@ class HotelBranchInformation extends ObjectModel } $sql = 'SELECT hbl.`hotel_name`, a.`phone`, hbi.`email`, a.`city`, cl.`name` AS country, a.`postcode`, - a.`address1`, hbi.`latitude`, hbi.`longitude`, hbi.`map_formated_address`, hbi.`map_input_text` + a.`address1` as `address`, hbi.`latitude`, hbi.`longitude`, hbi.`map_formated_address`, hbi.`map_input_text` FROM `'._DB_PREFIX_.'htl_branch_info` AS hbi INNER JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbl ON (hbl.`id` = hbi.`id` AND hbl.`id_lang` = '.(int)$idLang.') - INNER JOIN `'._DB_PREFIX_.'address` a - ON (a.`id_hotel` = hbi.`id`) + LEFT JOIN `'._DB_PREFIX_.'address` a ON (a.`id_hotel` = hbi.`id`) INNER JOIN `'._DB_PREFIX_.'country_lang` AS cl ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)$idLang.") WHERE hbi.`latitude` != 0 AND hbi.`longitude` != 0"; @@ -550,7 +550,6 @@ class HotelBranchInformation extends ObjectModel return Db::getInstance()->executeS($sql); } - public function getAllHotels() { return Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'htl_branch_info`'); diff --git a/themes/hotel-reservation-theme/contact-form.tpl b/themes/hotel-reservation-theme/contact-form.tpl index 8f541bf70..6e7cbdc7e 100644 --- a/themes/hotel-reservation-theme/contact-form.tpl +++ b/themes/hotel-reservation-theme/contact-form.tpl @@ -183,7 +183,7 @@

{$hotel['hotel_name']}

-

{$hotel['address_info']['address1']}, {$hotel['address_info']['city']}, {if {$hotel['address_info']['state']}}{$hotel['address_info']['state']},{/if} {$hotel['address_info']['country']}, {$hotel['address_info']['postcode']}

+

{$hotel['address']}, {$hotel['city']}, {if {$hotel['state_name']}}{$hotel['state_name']},{/if} {$hotel['country_name']}, {$hotel['postcode']}

{if $hotel['latitude'] != 0 || $hotel['longitude'] != 0}

@@ -192,7 +192,7 @@

{/if}

- {$hotel['address_info']['phone']} + {$hotel['phone']}

{$hotel['email']} diff --git a/themes/hotel-reservation-theme/product.tpl b/themes/hotel-reservation-theme/product.tpl index 1deb33990..2e46ee2d5 100644 --- a/themes/hotel-reservation-theme/product.tpl +++ b/themes/hotel-reservation-theme/product.tpl @@ -183,7 +183,7 @@

- {if $display_google_maps && ($hotel->latitude|floatval != 0 && $hotel->longitude|floatval != 0)} + {if $display_google_maps && ($hotel_latitude|floatval != 0 && $hotel_longitude|floatval != 0)}
{/if}
-

{$hotel->hotel_name|escape:'html':'UTF-8'}

-

{$hotel_address.address1|escape:'html':'UTF-8'}

-

{l s='Contact:'} {$hotel_address.phone|escape:'html':'UTF-8'}

- +

{$hotel_name|escape:'html':'UTF-8'}

+

{$hotel_address1|escape:'html':'UTF-8'}

+

{l s='Contact:'} {$hotel_phone|escape:'html':'UTF-8'}

+
{l s='Get Directions'}
From debe480200422dd5b12de22008b55700f237491c Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 1 Dec 2022 16:18:28 +0530 Subject: [PATCH 4/4] Change maps URL --- controllers/front/ProductController.php | 1 + .../hotelreservationsystem.php | 56 +++++++++---------- .../views/js/searchResultsMap.js | 11 +++- .../hotel-reservation-theme/css/product.css | 2 +- themes/hotel-reservation-theme/product.tpl | 4 +- 5 files changed, 39 insertions(+), 35 deletions(-) diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index 0597aeedb..d1ed6a7dc 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -374,6 +374,7 @@ class ProductControllerCore extends FrontController 'hotel_location' => $hotel_location, 'hotel_latitude' => $hotel_branch_obj->latitude, 'hotel_longitude' => $hotel_branch_obj->longitude, + 'hotel_map_input_text' => $hotel_branch_obj->map_input_text, 'hotel_address1' => $addressInfo['address1'], 'hotel_phone' => $addressInfo['phone'], 'hotel_name' => $hotel_name, diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index 7fc494432..3e2e8801f 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -103,36 +103,34 @@ class HotelReservationSystem extends Module public function hookDisplayLeftColumn() { if (Tools::getValue('controller') == 'category') { - if (!Configuration::get('PS_API_KEY')) { - return; + if ($apiKey = Configuration::get('PS_API_KEY')) { + $idCategory = Tools::getValue('id_category'); + $idHotel = HotelBranchInformation::getHotelIdByIdCategory($idCategory); + $objHotel = new HotelBranchInformation($idHotel, $this->context->language->id); + + if (floatval($objHotel->latitude) != 0 + && floatval($objHotel->longitude) != 0 + ) { + Media::addJsDef(array( + 'hotel_location' => array( + 'latitude' => $objHotel->latitude, + 'longitude' => $objHotel->longitude, + 'map_input_text' => $objHotel->map_input_text, + ), + 'hotel_name' => $objHotel->hotel_name, + )); + + $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 + ); + $this->context->controller->addJS($this->getPathUri().'views/js/searchResultsMap.js'); + $this->context->controller->addCSS($this->getPathUri().'views/css/searchResultsMap.css'); + + $this->context->smarty->assign('hotel', $objHotel); + return $this->display(__FILE__, 'searchResultsMap.tpl'); + } } - - $apiKey = Configuration::get('PS_API_KEY'); - $idCategory = Tools::getValue('id_category'); - $idHotel = HotelBranchInformation::getHotelIdByIdCategory($idCategory); - $objHotel = new HotelBranchInformation($idHotel, $this->context->language->id); - - if (floatval($objHotel->latitude) == 0 && floatval($objHotel->longitude) == 0) { - return; - } - - Media::addJsDef(array( - 'hotel_location' => array( - 'latitude' => $objHotel->latitude, - 'longitude' => $objHotel->longitude, - ), - 'hotel_name' => $objHotel->hotel_name, - )); - - $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 - ); - $this->context->controller->addJS($this->getPathUri().'views/js/searchResultsMap.js'); - $this->context->controller->addCSS($this->getPathUri().'views/css/searchResultsMap.css'); - - $this->context->smarty->assign('hotel', $objHotel); - return $this->display(__FILE__, 'searchResultsMap.tpl'); } } diff --git a/modules/hotelreservationsystem/views/js/searchResultsMap.js b/modules/hotelreservationsystem/views/js/searchResultsMap.js index 29bd49c3e..59a6f4047 100644 --- a/modules/hotelreservationsystem/views/js/searchResultsMap.js +++ b/modules/hotelreservationsystem/views/js/searchResultsMap.js @@ -37,9 +37,14 @@ function initMap() { }); marker.addListener('click', function() { - const directionsLink = 'https://www.google.com/maps/dir/?api=1&destination='+ - hotelLocation.lat+','+hotelLocation.lng; - window.open(directionsLink, '_blank'); + let query = ''; + if (hotel_location.map_input_text != '') { + query = hotel_location.map_input_text; + } else { + query = hotel_location.latitude + ',' + hotel_location.longitude; + } + + window.open('https://www.google.com/maps/search/?api=1&query='+encodeURIComponent(query), '_blank'); }); } diff --git a/themes/hotel-reservation-theme/css/product.css b/themes/hotel-reservation-theme/css/product.css index 24229ba1d..f166a9b05 100644 --- a/themes/hotel-reservation-theme/css/product.css +++ b/themes/hotel-reservation-theme/css/product.css @@ -1512,7 +1512,7 @@ Quick View Styles margin-bottom: 6px; } -#room_type_map_tab .hotel-info-wrap .get-directions { +#room_type_map_tab .hotel-info-wrap .view-on-map { background-color: #186bd7; border-radius: 2px; color: #fff; diff --git a/themes/hotel-reservation-theme/product.tpl b/themes/hotel-reservation-theme/product.tpl index c5e094c98..69ec555e6 100644 --- a/themes/hotel-reservation-theme/product.tpl +++ b/themes/hotel-reservation-theme/product.tpl @@ -320,8 +320,8 @@

{$hotel_name|escape:'html':'UTF-8'}

{$hotel_address1|escape:'html':'UTF-8'}

{l s='Contact:'} {$hotel_phone|escape:'html':'UTF-8'}

- - {l s='Get Directions'} + + {l s='View on Map'}