Merge pull request #518 from shreesh-webkul/gli-1136

Fixed: User input in location field in search panel get replaced by hotel location
This commit is contained in:
Rohit Jain
2023-03-21 19:13:24 +05:30
committed by GitHub
7 changed files with 46 additions and 23 deletions

View File

@@ -1583,6 +1583,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);

View File

@@ -518,7 +518,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);
}
/**
@@ -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`'
);

View File

@@ -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') {
@@ -127,6 +128,7 @@ class WkRoomSearchHelper
// if category page
$idHotelCategory = Tools::getValue('id_category');
}
$locationCategoryId = Tools::getValue('location');
if ($idHotelCategory) {
if (Validate::isLoadedObject($objCategory = new Category((int) $idHotelCategory))) {
if ($objCategory->hasParent(Configuration::get('PS_LOCATIONS_CATEGORY'))) {
@@ -152,11 +154,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);
@@ -191,16 +200,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;

View File

@@ -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 .= '<li tabindex="-1" class="search_result_li" data-id-hotel="'.$hotel_info[0]['id'].'" data-hotel-cat-id="'.
$hotel_info[0]['id_category'].'" data-max_order_date="'.$maxOrderDate.'">'.
$hotel_info[0]['hotel_name'].'</li>';
$html .= '<li tabindex="-1" class="search_result_li" data-id-hotel="'.$hotel_info['id'].'" data-hotel-cat-id="'.
$hotel_info['id_category'].'" data-max_order_date="'.$maxOrderDate.'">'.
$hotel_info['hotel_name'].'</li>';
}
}
$result['status'] = 'success';

View File

@@ -186,14 +186,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',
@@ -282,12 +282,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;
}

View File

@@ -1,7 +1,8 @@
<form method="POST" id="search_hotel_block_form" class="grid">
{if isset($location_enabled) && $location_enabled}
<div class="form-group area-{$column_widths['location']}">
<input type="text" class="form-control header-rmsearch-input input-location" id="hotel_location" name="hotel_location" autocomplete="off" placeholder="{l s='Hotel location' mod='wkroomsearchblock'}" {if isset($search_data)}value="{$search_data['location']|escape:'htmlall':'UTF-8'}" city_cat_id="{$search_data['parent_data']['id_category']}"{/if}>
<input type="text" class="form-control header-rmsearch-input input-location" id="hotel_location" name="hotel_location" autocomplete="off" placeholder="{l s='Hotel location' mod='wkroomsearchblock'}" {if isset($search_data)}value="{$search_data['location']|escape:'htmlall':'UTF-8'}"{/if}>
<input hidden="hidden" name="location_category_id" id="location_category_id" {if isset($search_data)}value="{$search_data['location_category_id']|escape:'htmlall':'UTF-8'}"{/if}>
<div class="dropdown">
<ul class="location_search_results_ul dropdown-menu"></ul>
</div>

View File

@@ -174,6 +174,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,