From 4068f9526b29dcac141538e32274e8b0ed2e764b Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Wed, 1 Feb 2023 16:09:44 +0530 Subject: [PATCH 1/3] updated location field data in search panel --- .../classes/HotelBookingDetail.php | 3 ++ .../classes/HotelBranchInformation.php | 2 +- .../classes/WkRoomSearchHelper.php | 34 ++++++++++++++----- .../controllers/front/autocompletesearch.php | 14 ++++---- .../views/js/wk-room-search-block.js | 8 ++--- .../views/templates/hook/searchForm.tpl | 3 +- .../wkroomsearchblock/wkroomsearchblock.php | 4 +++ 7 files changed, 46 insertions(+), 22 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index cfb26c1db..968dc3427 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -1565,6 +1565,9 @@ class HotelBookingDetail extends ObjectModel if ($occupancy) { $urlData['occupancy'] = $occupancy; } + if ($location = Tools::getValue('location')) { + $urlData['location'] = $location; + } if (Configuration::get('PS_REWRITING_SETTINGS')) { $bookingData['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($product).'?'.http_build_query($urlData); diff --git a/modules/hotelreservationsystem/classes/HotelBranchInformation.php b/modules/hotelreservationsystem/classes/HotelBranchInformation.php index 2fc5ed567..1775f8c6c 100644 --- a/modules/hotelreservationsystem/classes/HotelBranchInformation.php +++ b/modules/hotelreservationsystem/classes/HotelBranchInformation.php @@ -504,7 +504,7 @@ class HotelBranchInformation extends ObjectModel ON (hbl.`id` = hbi.`id` AND hbl.`id_lang` = '.(int)$idLang.') WHERE hbi.`id_category` = '.(int)$cat_id.' AND `active` = 1'; - return Db::getInstance()->executeS($sql); + return Db::getInstance()->getRow($sql); } /** diff --git a/modules/wkroomsearchblock/classes/WkRoomSearchHelper.php b/modules/wkroomsearchblock/classes/WkRoomSearchHelper.php index 1a46cb512..2398ee475 100644 --- a/modules/wkroomsearchblock/classes/WkRoomSearchHelper.php +++ b/modules/wkroomsearchblock/classes/WkRoomSearchHelper.php @@ -98,6 +98,7 @@ class WkRoomSearchHelper public function assignSearchPanelVariables() { $smartyVars = array(); + $context = Context::getContext(); // send if page is landing or not $smartyVars['is_index_page'] = 0; if (Tools::getValue('controller') == 'index') { @@ -136,6 +137,8 @@ class WkRoomSearchHelper $smartyVars['date_from'] = $dateFrom; $smartyVars['date_to'] = $dateTo; + $locationCategoryId = Tools::getValue('location'); + if (Validate::isLoadedObject($objCategory = new Category((int) $idHotelCategory))) { $idHotel = HotelBranchInformation::getHotelIdByIdCategory($idHotelCategory); $htlCategoryInfo = $objHotelInfo->getCategoryDataByIdCategory((int) $objCategory->id_parent); @@ -148,11 +151,18 @@ class WkRoomSearchHelper $searchedData['date_to'] = $dateTo; $searchedData['htl_dtl'] = $objHotelInfo->hotelBranchesInfo(0, 1, 1, $idHotel); - $searchedData['location'] = $searchedData['htl_dtl']['city']; - if (isset($searchedData['htl_dtl']['state_name'])) { - $searchedData['location'] .= ', '.$searchedData['htl_dtl']['state_name']; + if ($locationCategoryId) { + $objLocationCategory = new Category($locationCategoryId, $context->language->id); + $searchedData['location'] = $objLocationCategory->name; + } else { + $locationCategoryId = $objCategory->id_parent; + $searchedData['location'] = $searchedData['htl_dtl']['city']; + if (isset($searchedData['htl_dtl']['state_name'])) { + $searchedData['location'] .= ', '.$searchedData['htl_dtl']['state_name']; + } + $searchedData['location'] .= ', '.$searchedData['htl_dtl']['country_name']; } - $searchedData['location'] .= ', '.$searchedData['htl_dtl']['country_name']; + $searchedData['location_category_id'] = $locationCategoryId; $searchedData['order_date_restrict'] = false; $max_order_date = HotelOrderRestrictDate::getMaxOrderDate($idHotel); @@ -184,16 +194,22 @@ class WkRoomSearchHelper // if location is enabled the send hotels of the selected location only if ($locationEnabled) { - $hotelsInfo = $objHotelInfo->hotelBranchInfoByCategoryId($idHotelCategory); + $hotelsInfo = Category::getAllCategoriesName($locationCategoryId); } } $totalActiveHotels = count($hotelsInfo); // set hotels order restrict date on all hotels - foreach ($hotelsInfo as &$hotel) { - $maxOrderDate = HotelOrderRestrictDate::getMaxOrderDate($hotel['id']); - $hotel['max_order_date'] = date('Y-m-d', strtotime($maxOrderDate)); - $hotel['preparation_time'] = (int) HotelOrderRestrictDate::getPreparationTime($hotel['id']); + foreach ($hotelsInfo as $key => $hotel) { + if ($hotel_info = $objHotelInfo->hotelBranchInfoByCategoryId($hotel['id_category'])) { + $maxOrderDate = HotelOrderRestrictDate::getMaxOrderDate($hotel_info['id']); + $hotelsInfo[$key]['id'] = $hotel_info['id']; + $hotelsInfo[$key]['hotel_name'] = $hotel_info['hotel_name']; + $hotelsInfo[$key]['max_order_date'] = date('Y-m-d', strtotime($maxOrderDate)); + $hotelsInfo[$key]['preparation_time'] = (int) HotelOrderRestrictDate::getPreparationTime($hotel_info['id']); + } else { + unset($hotelsInfo[$key]); + } } $smartyVars['location_enabled'] = $locationEnabled; $smartyVars['total_active_hotels'] = $totalActiveHotels; diff --git a/modules/wkroomsearchblock/controllers/front/autocompletesearch.php b/modules/wkroomsearchblock/controllers/front/autocompletesearch.php index d8aa6ad59..4a051c103 100644 --- a/modules/wkroomsearchblock/controllers/front/autocompletesearch.php +++ b/modules/wkroomsearchblock/controllers/front/autocompletesearch.php @@ -26,7 +26,7 @@ class WkRoomSearchBlockAutoCompleteSearchModuleFrontController extends ModuleFro $this->display_column_left = false; $this->display_column_right = false; $search_data = Tools::getValue('to_search_data'); - $city_cat_id = Tools::getValue('hotel_city_cat_id'); + $location_category_id = Tools::getValue('location_category_id'); $obj_htl_info = new HotelBranchInformation(); if (isset($search_data) && $search_data) { $return_data = $obj_htl_info->getHotelCategoryTree($search_data); @@ -39,17 +39,17 @@ class WkRoomSearchBlockAutoCompleteSearchModuleFrontController extends ModuleFro $result['status'] = 'success'; $result['data'] = $html; } - } elseif (isset($city_cat_id) && $city_cat_id) { - $cat_ids = Category::getAllCategoriesName($city_cat_id); + } elseif (isset($location_category_id) && $location_category_id) { + $cat_ids = Category::getAllCategoriesName($location_category_id); if ($cat_ids) { $html = ''; foreach ($cat_ids as $value) { if ($hotel_info = $obj_htl_info->hotelBranchInfoByCategoryId($value['id_category'])) { - $maxOrderDate = HotelOrderRestrictDate::getMaxOrderDate($hotel_info[0]['id']); + $maxOrderDate = HotelOrderRestrictDate::getMaxOrderDate($hotel_info['id']); $maxOrderDate = date('Y-m-d', strtotime($maxOrderDate)); - $html .= '
  • '. - $hotel_info[0]['hotel_name'].'
  • '; + $html .= '
  • '. + $hotel_info['hotel_name'].'
  • '; } } $result['status'] = 'success'; diff --git a/modules/wkroomsearchblock/views/js/wk-room-search-block.js b/modules/wkroomsearchblock/views/js/wk-room-search-block.js index b60e3a77b..960416064 100644 --- a/modules/wkroomsearchblock/views/js/wk-room-search-block.js +++ b/modules/wkroomsearchblock/views/js/wk-room-search-block.js @@ -184,14 +184,14 @@ $(document).ready(function() { // set data on clicking the searched location on dropdown $(document).on('click', '.location_search_results_ul li', function(e) { $('#hotel_location').attr('value', $(this).html()); - $('#hotel_location').attr('city_cat_id', $(this).val()); + $('#location_category_id').val($(this).val()); $('.location_search_results_ul').empty().hide(); $.ajax({ url: autocomplete_search_url, data: { - hotel_city_cat_id: $('#hotel_location').attr('city_cat_id'), + location_category_id: $('#location_category_id').val(), }, method: 'POST', dataType: 'json', @@ -280,12 +280,12 @@ $(document).ready(function() { var max_order_date = $("#max_order_date").val(); var error = false; - var locationCatId = $('#hotel_location').attr('city_cat_id'); + var location_category_id = $('#location_category_id').val(); var hotelCatId = $('#hotel_cat_id').val(); $('.header-rmsearch-input').removeClass("error_border"); if (hotelCatId == '') { - if (typeof(locationCatId) == 'undefined' || locationCatId == '') { + if (typeof(location_category_id) == 'undefined' || location_category_id == '') { $("#hotel_location").addClass("error_border"); error = true; } diff --git a/modules/wkroomsearchblock/views/templates/hook/searchForm.tpl b/modules/wkroomsearchblock/views/templates/hook/searchForm.tpl index 6f5dae6c9..0f8a337de 100644 --- a/modules/wkroomsearchblock/views/templates/hook/searchForm.tpl +++ b/modules/wkroomsearchblock/views/templates/hook/searchForm.tpl @@ -1,7 +1,8 @@
    {if isset($location_enabled) && $location_enabled}
    - + + diff --git a/modules/wkroomsearchblock/wkroomsearchblock.php b/modules/wkroomsearchblock/wkroomsearchblock.php index c30f04129..6bb730efc 100644 --- a/modules/wkroomsearchblock/wkroomsearchblock.php +++ b/modules/wkroomsearchblock/wkroomsearchblock.php @@ -169,6 +169,10 @@ class WkRoomSearchBlock extends Module } } + if ($locationCategoryId = Tools::getValue('location_category_id')) { + $urlData['location'] = $locationCategoryId; + } + $objSearchHelper = new WkRoomSearchHelper(); $this->context->controller->errors = array_merge( $this->context->controller->errors, From e617ff233eec14837e13b9a092d50ab31b404ad7 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Thu, 16 Mar 2023 06:21:39 +0000 Subject: [PATCH 2/3] fix syntax error --- modules/wkroomsearchblock/classes/WkRoomSearchHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/wkroomsearchblock/classes/WkRoomSearchHelper.php b/modules/wkroomsearchblock/classes/WkRoomSearchHelper.php index 381d2a625..ea14b1bca 100644 --- a/modules/wkroomsearchblock/classes/WkRoomSearchHelper.php +++ b/modules/wkroomsearchblock/classes/WkRoomSearchHelper.php @@ -147,8 +147,8 @@ class WkRoomSearchHelper $htlCategoryInfo = $objHotelInfo->getCategoryDataByIdCategory((int) $objCategory->id_parent); $objBookingDetail = new HotelBookingDetail(); - $searchedData['num_days'] = $objBookingDetail->getNumberOfDays($dateFrom, $dateTo);\ - + $searchedData['num_days'] = $objBookingDetail->getNumberOfDays($dateFrom, $dateTo); + $searchedData['parent_data'] = $htlCategoryInfo; $searchedData['date_from'] = $dateFrom; $searchedData['date_to'] = $dateTo; From 9a3e566dcd97f69f62771a9092dc44359daa6fd7 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Sun, 19 Mar 2023 15:24:29 +0530 Subject: [PATCH 3/3] fix city not available in location search --- .../hotelreservationsystem/classes/HotelBranchInformation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/hotelreservationsystem/classes/HotelBranchInformation.php b/modules/hotelreservationsystem/classes/HotelBranchInformation.php index 60da88cb3..4482606ae 100644 --- a/modules/hotelreservationsystem/classes/HotelBranchInformation.php +++ b/modules/hotelreservationsystem/classes/HotelBranchInformation.php @@ -537,7 +537,7 @@ class HotelBranchInformation extends ObjectModel FROM `'._DB_PREFIX_.'category_lang` AS cl INNER JOIN `'._DB_PREFIX_.'category` AS c ON (cl.`id_category` = c.`id_category`) WHERE cl.`name` LIKE \'%'.pSQL($searchData).'%\' - AND c.`level_depth` NOT IN (0, 1, 5) and cl.`id_lang`='.(int)$context->language->id.' + AND c.`level_depth` NOT IN (0, 1, 6) and cl.`id_lang`='.(int)$context->language->id.' AND c.`nleft` > '.(int)$locationCategory->nleft.' AND c.`nright` < '.(int)$locationCategory->nright.' GROUP BY cl.`name`' );