From af4c6d375d526b07f42dbf2b975c5d2755b818f3 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 29 Apr 2022 16:30:49 +0530 Subject: [PATCH] Change booking form update using tpl on room type detail page --- controllers/front/CategoryController.php | 8 +- controllers/front/ProductController.php | 183 ++++++++- .../views/js/wkhotelfilterblock.js | 21 +- .../_partials/booking-form.tpl | 126 ++++++ .../js/modules/blockcart/ajax-cart.js | 6 +- themes/hotel-reservation-theme/js/product.js | 385 +++++------------- themes/hotel-reservation-theme/product.tpl | 100 +---- 7 files changed, 417 insertions(+), 412 deletions(-) create mode 100644 themes/hotel-reservation-theme/_partials/booking-form.tpl diff --git a/controllers/front/CategoryController.php b/controllers/front/CategoryController.php index dccf500f8..f0de6ae71 100644 --- a/controllers/front/CategoryController.php +++ b/controllers/front/CategoryController.php @@ -218,6 +218,8 @@ class CategoryControllerCore extends FrontController public function displayAjaxFilterResults() { + $response = array('status' => 'ko'); + $this->display_header = false; $this->display_footer = false; @@ -286,9 +288,13 @@ class CategoryControllerCore extends FrontController array_multisort($indi_arr, $direction, $booking_data['rm_data']); } + $this->context->smarty->assign(array('booking_data' => $booking_data)); + $html = $this->context->smarty->fetch('_partials/room_type_list.tpl'); + $response['status'] = 'ok'; + $response['html_room_type_list'] = $html; } - die($this->context->smarty->fetch(_PS_THEME_DIR_.'_partials/room_type_list.tpl')); + die(json_encode($response)); } /** diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index ad80cf3ca..01b8d565a 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -304,19 +304,6 @@ class ProductControllerCore extends FrontController $date_to = date('Y-m-d', strtotime('+1 day', strtotime($date_from))); } - $obj_htl_cart_booking_data = new HotelCartBookingData(); - $obj_booking_detail = new HotelBookingDetail(); - $num_days = $obj_booking_detail->getNumberOfDays($date_from, $date_to); - //$price_tax_incl = Product::getPriceStatic($this->product->id, HotelBookingDetail::useTax()); - //$total_price = $price_tax_incl * $num_days; - //// By webkul New way to calculate product prices with feature Prices - $roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice($this->product->id, $date_from, $date_to); - if ($useTax) { - $total_price = $roomTypeDateRangePrice['total_price_tax_incl']; - } else { - $total_price = $roomTypeDateRangePrice['total_price_tax_excl']; - } - //END $obj_booking_dtl = new HotelBookingDetail(); $hotel_room_data = $obj_booking_dtl->DataForFrontSearch($date_from, $date_to, $hotel_id, $this->product->id, 1); @@ -324,12 +311,6 @@ class ProductControllerCore extends FrontController $total_available_rooms = $hotel_room_data['stats']['num_avail']; } $hotel_branch_obj = new HotelBranchInformation($hotel_id); - if (isset($this->context->cart->id)) { - $num_cart_rooms = $obj_htl_cart_booking_data->getCountRoomsByIdCartIdProduct($this->context->cart->id, $this->product->id, $date_from, $date_to); - if ($num_cart_rooms) { - $total_available_rooms = $total_available_rooms - $num_cart_rooms; - } - } /*Max date of ordering for order restrict*/ $order_date_restrict = false; $max_order_date = HotelOrderRestrictDate::getMaxOrderDate($hotel_id); @@ -362,9 +343,7 @@ class ProductControllerCore extends FrontController 'warning_num' => Configuration::get('WK_ROOM_LEFT_WARNING_NUMBER'), 'ratting_img_path' => _MODULE_DIR_.'hotelreservationsystem/views/img/Slices/icons-sprite.png', 'total_available_rooms' => $total_available_rooms, - 'total_price' => $total_price, 'product_controller_url' => $this->context->link->getPageLink('product'), - 'num_days' => $num_days, 'date_from' => $date_from, 'date_to' => $date_to, 'hotel_check_in' => date('h:i a', strtotime($hotel_branch_obj->check_in)), @@ -377,6 +356,9 @@ class ProductControllerCore extends FrontController 'order_date_restrict' => $order_date_restrict ) ); + + $this->assignBookingFormVars($this->product->id, $date_from, $date_to); + // product price after imposing feature prices... if ($useTax) { $priceProduct = Product::getPriceStatic($this->product->id, true); @@ -457,6 +439,138 @@ class ProductControllerCore extends FrontController $this->setTemplate(_PS_THEME_DIR_.'product.tpl'); } + public function assignBookingFormVars( + $idProduct, + $dateFrom, + $dateTo, + $quantity = 1, + $jsonDemands = '' + ) { + $objProduct = new Product($idProduct, true, $this->context->language->id, $this->context->shop->id); + if (!Validate::isLoadedObject($objProduct)) { + return false; + } + + $smartyVars = array(); + $objHotelRoomType = new HotelRoomType(); + $objHotel = new HotelBranchInformation(); + $objHotelCartBookingData = new HotelCartBookingData(); + $objBookingDetail = new HotelBookingDetail(); + $objHRTDemand = new HotelRoomTypeDemand(); + $objHRTDemandPrice = new HotelRoomTypeDemandPrice(); + + $idCart = (int) $this->context->cart->id; + $idGuest = (int) $this->context->cart->id_guest; + $warningCount = (int) Configuration::get('WK_ROOM_LEFT_WARNING_NUMBER'); + + $roomType = $objHotelRoomType->getRoomTypeInfoByIdProduct($idProduct); + $idHotel = $roomType['id_hotel']; + $hotel = $objHotel->hotelBranchesInfo(false, 2, 1, $idHotel); + $hotelLocation = $hotel['city'].', '.(isset($hotel['state_name']) ? ' '.$hotel['state_name'].', ' : ''). + ' '.$hotel['country_name']; + + $orderDateRestrict = false; + $maxOrderDate = HotelOrderRestrictDate::getMaxOrderDate($idHotel); + if ($maxOrderDate) { + $maxOrderDate = date('Y-m-d', strtotime($maxOrderDate)); + if (strtotime('-1 day', strtotime($maxOrderDate)) < strtotime($dateFrom) + || strtotime($maxOrderDate) < strtotime($dateTo) + ) { + $orderDateRestrict = true; + } + } + + $numDays = $objBookingDetail->getNumberOfDays($dateFrom, $dateTo); + + $hotelRoomData = $objBookingDetail->DataForFrontSearch( + $dateFrom, + $dateTo, + $idHotel, + $idProduct, + 1, + 0, + 0, + -1, + 0, + 0, + $idCart, + $idGuest + ); + + if ($hotelRoomData) { + $totalAvailableRooms = $hotelRoomData['stats']['num_avail']; + $quantity = ($quantity > $totalAvailableRooms) ? $totalAvailableRooms : $quantity; + } + + // calculate room type price first + $useTax = HotelBookingDetail::useTax(); + $totalPrice = 0; + $productPriceWithoutReduction = $objProduct->getPriceWithoutReduct(!$useTax); + $roomTypeDateRangePrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice( + $idProduct, + $dateFrom, + $dateTo + ); + + $featurePrice = 0; + if ($useTax) { + $featurePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( + $idProduct, + $dateFrom, + $dateTo, + true + ); + $roomTypeDateRangePrice = $roomTypeDateRangePrice['total_price_tax_incl']; + } else { + $featurePrice = HotelRoomTypeFeaturePricing::getRoomTypeFeaturePricesPerDay( + $idProduct, + $dateFrom, + $dateTo, + false + ); + $roomTypeDateRangePrice = $roomTypeDateRangePrice['total_price_tax_excl']; + } + $featurePriceDiff = (float) ($productPriceWithoutReduction - $featurePrice); + + $totalRoomPrice = $roomTypeDateRangePrice * $quantity; + + // calculate demand price now + $demandsPrice = 0; + $roomTypeDemands = $objHRTDemand->getRoomTypeDemands($idProduct); + if ($jsonDemands !== '') { + $cartDemands = json_decode($jsonDemands, true); + $demandsPrice = $objHRTDemandPrice->getRoomTypeDemandsTotalPrice( + $idProduct, + $cartDemands, + $useTax, + $dateFrom, + $dateTo + ); + + $demandsPrice *= $quantity; + } + + // calculate total price + $totalPrice = $totalRoomPrice + $demandsPrice; + + $smartyVars['hotel_location'] = $hotelLocation; + $smartyVars['order_date_restrict'] = $orderDateRestrict; + $smartyVars['max_order_date'] = $maxOrderDate; + $smartyVars['date_from'] = $dateFrom; + $smartyVars['date_to'] = $dateTo; + $smartyVars['allow_oosp'] = $objProduct->isAvailableWhenOutOfStock((int) $objProduct->out_of_stock); + $smartyVars['quantity'] = $quantity; + $smartyVars['num_days'] = $numDays; + $smartyVars['warning_count'] = $warningCount; + $smartyVars['total_available_rooms'] = $totalAvailableRooms; + $smartyVars['has_room_type_demands'] = $roomTypeDemands ? true : false; // whether to show price breakup + $smartyVars['rooms_price'] = $totalRoomPrice; + $smartyVars['demands_price'] = $demandsPrice; + $smartyVars['total_price'] = $totalPrice; + $this->context->smarty->assign($smartyVars); + return true; + } + /** * Assign price and tax to the template */ @@ -922,6 +1036,33 @@ class ProductControllerCore extends FrontController return $this->category; } + public function displayAjaxRefreshBookingForm() + { + $response = array('status' => 'ko'); + $idProduct = (int) Tools::getValue('id_product'); + $dateFrom = Tools::getValue('date_from'); + $dateTo = Tools::getValue('date_to'); + $quantity = (int) Tools::getValue('quantity'); + $roomTypeDemands = Tools::getValue('room_type_demands'); + + $dateFrom = date('Y-m-d', strtotime($dateFrom)); + $dateTo = date('Y-m-d', strtotime($dateTo)); + + if ($this->assignBookingFormVars( + $idProduct, + $dateFrom, + $dateTo, + $quantity, + $roomTypeDemands + )) { + $html = $this->context->smarty->fetch('_partials/booking-form.tpl'); + $response['status'] = 'ok'; + $response['html_booking_form'] = $html; + } + + die(json_encode($response)); + } + public function displayAjaxCheckRoomAvailabilityAndRate() { $result = array(); diff --git a/modules/wkhotelfilterblock/views/js/wkhotelfilterblock.js b/modules/wkhotelfilterblock/views/js/wkhotelfilterblock.js index 8db2a1a01..2415b6f4c 100644 --- a/modules/wkhotelfilterblock/views/js/wkhotelfilterblock.js +++ b/modules/wkhotelfilterblock/views/js/wkhotelfilterblock.js @@ -178,19 +178,14 @@ $(document).ready(function() data.sort_value = sort_value; } - filter_ajax = $.ajax( - { - url: cat_link, - type: 'POST', - dataType: 'html', - data: data, - success: function (result) - { - if (result) { - $('#category_data_cont').html(result); - } else { - var html = '
'+noRoomAvailTxt+'
'; - $('#category_data_cont').html(html); + filter_ajax = $.ajax({ + url: cat_link, + type: 'POST', + dataType: 'JSON', + data: data, + success: function (response) { + if (response.status == 'ok') { + $('#category_data_cont').html(response.html_room_type_list); } } }); diff --git a/themes/hotel-reservation-theme/_partials/booking-form.tpl b/themes/hotel-reservation-theme/_partials/booking-form.tpl new file mode 100644 index 000000000..708a46fb9 --- /dev/null +++ b/themes/hotel-reservation-theme/_partials/booking-form.tpl @@ -0,0 +1,126 @@ +{* +* 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 +*} + +
+
+
+
+ +

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

+
+ {if $product->show_price && !isset($restricted_country_mode) && !$PS_CATALOG_MODE && !$order_date_restrict} +
+
+ + +
+
+ + +
+
+
+ {if $total_available_rooms > 0} +
+
quantity <= 0) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: none;"{/if}> + +
+
+ + + + +
+ +
+ +
+
+ {if isset($has_room_type_demands) && $has_room_type_demands} +
+
+
+ +

+ {convertPrice price=$rooms_price|floatval} + + +

+
+
+ +

+ {if isset($demands_price)}{convertPrice price=$demands_price}{else}{convertPrice price=0}{/if} +

+
+
+
+ {/if} +
+
+
+ +

{convertPrice price=$total_price|floatval}

+
+ {if $total_available_rooms <= $warning_count} +
+ + {$total_available_rooms|escape:'html':'UTF-8'} + + {if $total_available_rooms > 1} {l s='rooms left!'} {else} {l s='room left!'} {/if} +
+ {/if} +
+ +
+ {if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || (isset($restricted_country_mode) && $restricted_country_mode) || $PS_CATALOG_MODE || $order_date_restrict} + {else} +

+ +

+ {/if} +
+ {else} +
+ {l s='All rooms sold out!'} +
+ {/if} + {/if} + {if $order_date_restrict} +
+ {l s='You can\'t book rooms after %s.' sprintf=[{dateFormat date=$max_order_date full=0}]} +
+ {/if} +
+
+
\ No newline at end of file diff --git a/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js b/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js index 0e6fb787c..f4c04381c 100644 --- a/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js +++ b/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js @@ -507,11 +507,6 @@ var ajaxCart = { var date_checkIn = $('#room_check_in').val(); var date_checkOut = $('#room_check_out').val(); var product_page_id_product = $('#product_page_product_id').val(); - console.log(idProduct == product_page_id_product); - console.log(dateFrom); - console.log(date_checkOut); - console.log(dateTo); - console.log(date_checkIn); if (idProduct == product_page_id_product && dateFrom < date_checkOut && dateTo >= date_checkIn) { if (jsonData.avail_rooms <= room_warning_num) { $('.num_quantity_alert').show(); @@ -528,6 +523,7 @@ var ajaxCart = { $('.unvail_rooms_cond_display').hide(); } } + BookingForm.refresh(); } if (pagename == 'category') { diff --git a/themes/hotel-reservation-theme/js/product.js b/themes/hotel-reservation-theme/js/product.js index 01ecd1ec4..880716b28 100644 --- a/themes/hotel-reservation-theme/js/product.js +++ b/themes/hotel-reservation-theme/js/product.js @@ -1096,130 +1096,23 @@ $(document).ready(function() { } } - $("#room_check_in").datepicker({ - showOtherMonths: true, - dateFormat: 'dd-mm-yy', - minDate: 0, - beforeShow: function (input, instance) { - // So that on translating page date is translated to NaN-NaN-NaN - $('.ui-datepicker').addClass('notranslate'); - }, - beforeShowDay: function (date) { - // highlight dates of the selected date range - return highlightSelectedDateRange(date, $("#room_check_in").val(), $("#room_check_out").val()); - }, - onClose: function() { - var checkOut = $("#room_check_out").val(); - var selectedDate = $("#room_check_in").val(); - - var date_from_format = selectedDate.split("-"); - var selectedDate = new Date($.datepicker.formatDate('yy-mm-dd', new Date(date_from_format[2], date_from_format[1] - 1, date_from_format[0]))); - var date_in = $.datepicker.formatDate('yy-mm-dd', selectedDate); - - var date_to_format = $('#room_check_out').val().split("-"); - var selectedDateTo = new Date($.datepicker.formatDate('yy-mm-dd', new Date(date_to_format[2], date_to_format[1] - 1, date_to_format[0]))); - - var date_out = $.datepicker.formatDate('yy-mm-dd', selectedDateTo); - - if (date_in >= date_out) { - selectedDate.setDate(selectedDate.getDate() + 1); - $("#room_check_out").datepicker("option", "minDate", selectedDate); - $("#room_check_out").val($.datepicker.formatDate('dd-mm-yy', selectedDate)); - var date_out = $.datepicker.formatDate('yy-mm-dd', selectedDate); - } - - /* open datepicker of chechout date only if - checkout date is empty or checkin selected is equal or more than check out date */ - if (checkOut == '') { - $("#room_check_out").datepicker( "show" ); - } else { - // Lets make the date in the required format - var currentDate = selectedDate.getDate(); - var currentMonth = selectedDate.getMonth() + 1; - if (currentMonth < 10) { - currentMonth = '0' + currentMonth; - } - if (currentDate < 10) { - currentDate = '0' + currentDate; - } - - dmy = selectedDate.getFullYear() + "-" + currentMonth + "-" + currentDate; - checkOut = checkOut.split("-"); - checkOut = (checkOut[2]) + '-' + (checkOut[1]) + '-' + (checkOut[0]); - - if (checkOut <= dmy) { - $("#room_check_out").datepicker('show'); - } - } - - changeRoomDate(date_in, date_out); - } - }); - - $("#room_check_out").datepicker({ - showOtherMonths: true, - dateFormat: 'dd-mm-yy', - beforeShow: function (input, instance) { - // So that on translating page date is translated to NaN-NaN-NaN - $('.ui-datepicker').addClass('notranslate'); - - var date_to = $('#room_check_in').val(); - if (typeof date_to != 'undefined' && date_to != '') { - var date_format = date_to.split("-"); - var selectedDate = new Date($.datepicker.formatDate('yy-mm-dd', new Date(date_format[2], date_format[1] - 1, date_format[0]))); - selectedDate.setDate(selectedDate.getDate()+1); - $("#room_check_out").datepicker("option", "minDate", selectedDate); - } else { - var date_format = new Date(); - var selectedDate = new Date($.datepicker.formatDate('yy-mm-dd', new Date())); - selectedDate.setDate(selectedDate.getDate()+1); - $("#room_check_out").datepicker("option", "minDate", selectedDate); - } - }, - beforeShowDay: function (date) { - // highlight dates of the selected date range - return highlightSelectedDateRange(date, $("#room_check_in").val(), $("#room_check_out").val()); - }, - onSelect: function(dateText, inst) { - var date_from_format = $('#room_check_in').val().split("-"); - var selectedDateFrom = new Date($.datepicker.formatDate('yy-mm-dd', new Date(date_from_format[2], date_from_format[1] - 1, date_from_format[0]))); - var date_in = $.datepicker.formatDate('yy-mm-dd', selectedDateFrom); - var date_to_format = $('#room_check_out').val().split("-"); - var selectedDateTo = new Date($.datepicker.formatDate('yy-mm-dd', new Date(date_to_format[2], date_to_format[1] - 1, date_to_format[0]))); - var date_out = $.datepicker.formatDate('yy-mm-dd', selectedDateTo); - - if (date_in >= date_out) { - $(this).val(inst.lastVal); - $('.room_unavailability_date_error_div').text(correct_date_cond); - $('.room_unavailability_date_error_div').css('display', 'block'); - - setTimeout(function() { - $('.room_unavailability_date_error_div').css('display', 'none'); - }, - 3000); - } else { - changeRoomDate(date_in, date_out); - } - } - }); - + BookingForm.initDatepicker(); $(document).on('focusout', '#quantity_wanted', function(e) { - changeRoomTypeDemands(); + BookingForm.refresh(); }); $('.id_room_type_demand').on('click', function() { - changeRoomTypeDemands(); + BookingForm.refresh(); }); $(document).on('change', '.room_demand_block .id_option', function(e) { - var option_selected = $(this).find('option:selected'); - var extra_demand_price = option_selected.attr("optionPrice") - extra_demand_price = parseFloat(extra_demand_price); - extra_demand_price = formatCurrency(extra_demand_price, currency_format, currency_sign, currency_blank); - - $(this).closest('.room_demand_block').find('.extra_demand_option_price').text(extra_demand_price); - changeRoomTypeDemands(); + var optionSelected = $(this).find('option:selected'); + var extraDemandPrice = optionSelected.attr("optionPrice") + extraDemandPrice = parseFloat(extraDemandPrice); + extraDemandPrice = formatCurrency(extraDemandPrice, currency_format, currency_sign, currency_blank); + $(this).closest('.room_demand_block').find('.extra_demand_option_price').text(extraDemandPrice); + BookingForm.refresh(); }); /*Set maxDate for Order resrict date*/ @@ -1265,169 +1158,115 @@ $(document).ready(function() { }); }); -function changeRoomTypeDemands() { - var qty_wntd = $('#quantity_wanted').val(); - if (qty_wntd == '' || !$.isNumeric(qty_wntd)) { - $('#quantity_wanted').val(1); - qty_wntd = $('#quantity_wanted').val(); - } - $('#quantity_wanted').val(parseInt(qty_wntd)); - if ((parseInt(qty_wntd) < 1 || parseInt(qty_wntd) > $('#max_avail_type_qty').val()) - && $('#max_avail_type_qty').val() > 0 - ) { - $('#quantity_wanted').val($('#max_avail_type_qty').val()); - setTimeout(function() { - $('.room_unavailability_qty_error_div').hide(); - }, - 2000); - } else if (qty_wntd <= $('#max_avail_type_qty').val() && qty_wntd >= 1) { - // get the selected extra demands by customer - var roomDemands = getRoomsExtraDemands(); - $.ajax({ - type: 'POST', - headers: { - "cache-control": "no-cache" +var BookingForm = { + init: function() { + BookingForm.initDatepicker(); + }, + initDatepicker: function() { + // date from + $("#room_check_in").datepicker({ + showOtherMonths: true, + dateFormat: 'dd-mm-yy', + minDate: 0, + beforeShow: function (input, instance) { + // So that on translating page date is translated to NaN-NaN-NaN + $('.ui-datepicker').addClass('notranslate'); }, - url: product_controller_url, - dataType: 'JSON', - cache: false, - data: { - date_from: $('#room_check_in').val(), - date_to: $('#room_check_out').val(), - product_quantity_down: 1, - qty: qty_wntd, - id_product: $('#product_page_product_id').val(), - room_demands: JSON.stringify(roomDemands), - action: 'checkRoomAvailabilityAndRate', - ajax: true + beforeShowDay: function (date) { + // highlight dates of the selected date range + return highlightSelectedDateRange(date, $("#room_check_in").val(), $("#room_check_out").val()); }, - success: function(result) { - if (result.msg == 'success') { - total_price = result.total_price; - total_price = parseFloat(total_price); - total_price = formatCurrency(total_price, currency_format, currency_sign, currency_blank); - $('.total_price_block p').text(total_price); - total_room_price = result.total_room_price; - total_room_price = parseFloat(total_room_price); - total_room_price = formatCurrency(total_room_price, currency_format, currency_sign, currency_blank); - $('.total_rooms_price_block').text(total_room_price); - extra_demand_price = result.extra_demand_price; - extra_demand_price = parseFloat(extra_demand_price); - extra_demand_price = formatCurrency(extra_demand_price, currency_format, currency_sign, currency_blank); - $('.extra_demands_price_block').text(extra_demand_price); + onClose: function() { + var selectedDate = $("#room_check_in").val(); - $('#num_days').val(result.num_days); - $("#max_avail_type_qty").val(result.avail_rooms); - } else if (result.msg == 'unavailable_quantity') { - $('#quantity_wanted').val(result.avail_rooms); - $('.room_unavailability_qty_error_div').text(unavail_qty_text); - $('.room_unavailability_qty_error_div').show(); + var date_from_format = selectedDate.split("-"); + var selectedDate = new Date($.datepicker.formatDate('yy-mm-dd', new Date(date_from_format[2], date_from_format[1] - 1, date_from_format[0]))); + var date_in = $.datepicker.formatDate('yy-mm-dd', selectedDate); - setTimeout(function() { - $('.room_unavailability_qty_error_div').hide(); - }, - 2000); + var date_to_format = $('#room_check_out').val().split("-"); + var selectedDateTo = new Date($.datepicker.formatDate('yy-mm-dd', new Date(date_to_format[2], date_to_format[1] - 1, date_to_format[0]))); + + var date_out = $.datepicker.formatDate('yy-mm-dd', selectedDateTo); + + if (date_in >= date_out) { + selectedDate.setDate(selectedDate.getDate() + 1); + $("#room_check_out").datepicker("option", "minDate", selectedDate); + $("#room_check_out").val($.datepicker.formatDate('dd-mm-yy', selectedDate)); + } + BookingForm.refresh(); + } + }); + + // date to + $("#room_check_out").datepicker({ + showOtherMonths: true, + dateFormat: 'dd-mm-yy', + beforeShow: function (input, instance) { + // So that on translating page date is translated to NaN-NaN-NaN + $('.ui-datepicker').addClass('notranslate'); + + var date_to = $('#room_check_in').val(); + if (typeof date_to != 'undefined' && date_to != '') { + var date_format = date_to.split("-"); + var selectedDate = new Date($.datepicker.formatDate('yy-mm-dd', new Date(date_format[2], date_format[1] - 1, date_format[0]))); + selectedDate.setDate(selectedDate.getDate()+1); + $("#room_check_out").datepicker("option", "minDate", selectedDate); } else { - alert(some_error_cond); + var date_format = new Date(); + var selectedDate = new Date($.datepicker.formatDate('yy-mm-dd', new Date())); + selectedDate.setDate(selectedDate.getDate()+1); + $("#room_check_out").datepicker("option", "minDate", selectedDate); + } + }, + beforeShowDay: function (date) { + // highlight dates of the selected date range + return highlightSelectedDateRange(date, $("#room_check_in").val(), $("#room_check_out").val()); + }, + onSelect: function(dateText, instance) { + var date_from_format = $('#room_check_in').val().split("-"); + var selectedDateFrom = new Date($.datepicker.formatDate('yy-mm-dd', new Date(date_from_format[2], date_from_format[1] - 1, date_from_format[0]))); + var date_in = $.datepicker.formatDate('yy-mm-dd', selectedDateFrom); + var date_to_format = $('#room_check_out').val().split("-"); + var selectedDateTo = new Date($.datepicker.formatDate('yy-mm-dd', new Date(date_to_format[2], date_to_format[1] - 1, date_to_format[0]))); + var date_out = $.datepicker.formatDate('yy-mm-dd', selectedDateTo); + + if (date_out > date_in) { + BookingForm.refresh(); } } }); - } -} - -function changeRoomDate(date_in, date_out){ - // get the selected extra demands by customer - var roomDemands = getRoomsExtraDemands(); - - /*by webkul to manage quantity of rooms*/ - $.ajax({ - type: 'POST', - headers: { - "cache-control": "no-cache" - }, - url: product_controller_url, - cache: false, - dataType: 'JSON', - data: { - date_from: date_in, - date_to: date_out, - change_date: 1, - qty: $('#quantity_wanted').val(), - id_product: $('#product_page_product_id').val(), - room_demands: JSON.stringify(roomDemands), - action: 'checkRoomAvailabilityAndRate', - ajax: true - }, - success: function(result) { - if (result.msg == 'success') { - if (result.avail_rooms <= room_warning_num) { - $('.num_quantity_alert').show(); - } else { - $('.num_quantity_alert').hide(); - } - - $('.num_searched_avail_rooms').text(result.avail_rooms); - $("#max_avail_type_qty").val(result.avail_rooms); - $('.room_unavailability_date_error_div').hide(); - $('.unvail_rooms_cond_display').show(); - $('.sold_out_alert').hide(); - disableRoomTypeDemands(0); - - total_price = result.total_price; - total_price = parseFloat(total_price); - total_price = formatCurrency(total_price, currency_format, currency_sign, currency_blank); - total_room_price = result.total_room_price; - total_room_price = parseFloat(total_room_price); - total_room_price = formatCurrency(total_room_price, currency_format, currency_sign, currency_blank); - $('.total_price_block p').text(total_price); - $('.total_rooms_price_block').text(total_room_price); - - extra_demand_price = parseFloat(result.extra_demand_price); - extra_demand_price = formatCurrency(extra_demand_price, currency_format, currency_sign, currency_blank); - $('.extra_demands_price_block').text(extra_demand_price); - - feature_price = parseFloat(result.feature_price); - original_product_price = parseFloat(result.original_product_price); - feature_price_diff = parseFloat(result.feature_price_diff); - if (feature_price_diff > 0) { - $('.room_type_current_price').text(formatCurrency(feature_price, currency_format, currency_sign, currency_blank)); - $('.room_type_current_price').show(); - $('.product_original_price').addClass('room_type_old_price'); - } else if (feature_price_diff < 0) { - $('.room_type_current_price').text(formatCurrency(feature_price, currency_format, currency_sign, currency_blank)); - $('.room_type_current_price').show(); - $('.product_original_price').hide(); - } else { - $('.room_type_current_price').hide(); - $('.product_original_price').removeClass('room_type_old_price'); - $('.product_original_price').show(); - } - - $('#num_days').val(result.num_days); - } else if (result.msg == 'unavailable_quantity') { - if (result.avail_rooms > 0) { - $('.room_unavailability_date_error_div').text(unavail_qty_text); - $('.num_searched_avail_rooms').text(result.avail_rooms); - $("#max_avail_type_qty").val(result.avail_rooms); - $('.room_unavailability_date_error_div').show(); - $('#quantity_wanted').val(result.avail_rooms); - $('.unvail_rooms_cond_display').show(); - $('.sold_out_alert').hide(); - disableRoomTypeDemands(0); - - setTimeout(function() { - $('.room_unavailability_date_error_div').css('display', 'none'); - }, - 3000); - } else { - $('.num_quantity_alert').hide(); - $('.unvail_rooms_cond_display').hide(); - $('.sold_out_alert').show(); - disableRoomTypeDemands(1); - } - } else { - alert(some_error_cond); - } - } - }); + }, + getFormData: function () { + var data = { + id_product: parseInt($('#product_page_product_id').val()), + date_from: $('#room_check_in').val(), + date_to: $('#room_check_out').val(), + quantity: parseInt($('#quantity_wanted').val()), + room_type_demands: JSON.stringify(getRoomsExtraDemands()), + }; + return data; + }, + refresh: function() { + $.ajax({ + url: product_controller_url, + type: 'POST', + headers: { 'cache-control': 'no-cache' }, + dataType: 'JSON', + cache: false, + data: $.extend({ + ajax: true, + action: 'refreshBookingForm', + }, BookingForm.getFormData()), + success: function(response) { + if (response.status == 'ok') { + $('.booking-form').animate({opacity: 0}, 250, 'linear', function() { + $('.booking-form').replaceWith(response.html_booking_form); + $('.booking-form').animate({opacity: 1}, 250, 'linear', function() { + BookingForm.init(); + }); + }) + } + } + }); + }, } diff --git a/themes/hotel-reservation-theme/product.tpl b/themes/hotel-reservation-theme/product.tpl index c7b91d609..9b24bbf7b 100644 --- a/themes/hotel-reservation-theme/product.tpl +++ b/themes/hotel-reservation-theme/product.tpl @@ -289,106 +289,8 @@

-
-
-
-
- -

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

-
- {if $product->show_price && !isset($restricted_country_mode) && !$PS_CATALOG_MODE && !$order_date_restrict} -
-
- - -
-
- - -
-
-
-
-
quantity <= 0) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: none;"{/if}> - -
-
- - - -
- -
- -
-
- {if isset($room_type_demands) && $room_type_demands} -
-
-
- -

- {convertPrice price=$total_price|floatval} - + -

-
-
- -

{convertPrice price=0}

-
-
-
- {/if} -
-
-
- -

- {convertPrice price=$total_price|floatval} -

-
-
- {$total_available_rooms|escape:'html':'UTF-8'} {l s='Room(s) Left !'} -
-
- - -
- {l s='Rooms Sold Out !'} -
- {/if} - {if $order_date_restrict} -
- {l s='You can\'t book for rooms after date'} {$max_order_date|date_format:"%d-%m-%Y"} -
- {/if} -
- {if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || (isset($restricted_country_mode) && $restricted_country_mode) || $PS_CATALOG_MODE || $order_date_restrict} - {else} -

- -

- {/if} -
-
-
-
+ {include file='./_partials/booking-form.tpl'} {* extra room type demands *} {if isset($room_type_demands) && $room_type_demands}