diff --git a/admin/themes/default/template/controllers/orders/_product_line.tpl b/admin/themes/default/template/controllers/orders/_product_line.tpl index 720d82ef2..59c3de95f 100644 --- a/admin/themes/default/template/controllers/orders/_product_line.tpl +++ b/admin/themes/default/template/controllers/orders/_product_line.tpl @@ -231,27 +231,34 @@
- - - + {if isset($refundReqBookings) && $refundReqBookings && $data.id|in_array:$refundReqBookings && $data.is_cancelled} + + {else} + + + + {/if}
{/if} diff --git a/admin/themes/default/template/controllers/orders/modals/_edit_room_tab_content.tpl b/admin/themes/default/template/controllers/orders/modals/_edit_room_tab_content.tpl index 932b0bc19..edcae99c0 100644 --- a/admin/themes/default/template/controllers/orders/modals/_edit_room_tab_content.tpl +++ b/admin/themes/default/template/controllers/orders/modals/_edit_room_tab_content.tpl @@ -33,17 +33,25 @@
- -
+ {if isset($refundReqBookings) && $refundReqBookings && $data.id|in_array:$refundReqBookings && $data.is_refunded} + {dateFormat date=$data.date_from} + {else} + +
+ {/if}
- -
+ {if isset($refundReqBookings) && $refundReqBookings && $data.id|in_array:$refundReqBookings && $data.is_refunded} + {dateFormat date=$data.date_to} + {else} + +
+ {/if}
diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index 6d36f953e..c466fb02a 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -2313,6 +2313,7 @@ class AdminControllerCore extends Controller public function ajaxProcessRefreshModuleList($force_reload_cache = false) { $this->status = Module::refreshModuleList($force_reload_cache); + $this->ajaxDie(json_encode(array('status' => $this->status))); } /** diff --git a/classes/order/Order.php b/classes/order/Order.php index 53aa3fff1..74fc0a450 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -2688,4 +2688,133 @@ class OrderCore extends ObjectModel { $this->transaction_id = $transactionId; } + + /** + * Validate and change order status + * @return array of status, errors, has_mail_error(if order status is changes but mail error occurs while sending mail) + */ + public function ChangeOrderStatus() + { + $result = array(); + $result['status'] = false; + $result['has_mail_error'] = false; + $result['errors'] = array(); + $objNewOrderState = new OrderState(Tools::getValue('id_order_state')); + if (!Validate::isLoadedObject($objNewOrderState)) { + $result['errors'][] = Tools::displayError('The new order status is invalid.'); + } else { + $objHotelBooking = new HotelBookingDetail(); + $objCurrentOrderState = $this->getCurrentOrderState(); + + if ($objCurrentOrderState->id == Configuration::get('PS_OS_REFUND')) { + $result['errors'][] = Tools::displayError('Order status can not be changed once order status is set to Refunded.'); + } elseif ($objCurrentOrderState->id == Configuration::get('PS_OS_CANCELED')) { + $result['errors'][] = Tools::displayError('Order status can not be changed once order status is set to Cancelled.'); + } elseif (in_array($objNewOrderState->id, array (Configuration::get('PS_OS_OVERBOOKING_PAID'), Configuration::get('PS_OS_OVERBOOKING_UNPAID'), Configuration::get('PS_OS_OVERBOOKING_PARTIAL_PAID')))) { + if (!$objHotelBooking->getOverbookedRooms($this->id)) { + $result['errors'][] = Tools::displayError('Order status can not be changed to any overbooking status as there are no overbooked rooms in the order.'); + } + } elseif ($objNewOrderState->id == Configuration::get('PS_OS_REFUND') + && !$this->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG) + ) { + $result['errors'][] = Tools::displayError('Order status can not be set to Refunded until all bookings in the order are completely refunded.'); + } elseif ($objNewOrderState->id == Configuration::get('PS_OS_CANCELED') + && !$this->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG) + ) { + $result['errors'][] = Tools::displayError('Order status can not be set to Cancelled until all bookings in the order are cancelled.'); + } elseif ($objCurrentOrderState->id == Configuration::get('PS_OS_ERROR') && !($objNewOrderState->id == Configuration::get('PS_OS_ERROR'))) { + // All rooms must be available before changing status from Payment Error to Other status in which rooms are getting blocked again + if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) { + foreach ($orderBookings as $orderBooking) { + // If booking is refunded then no need to check inventory + if ((OrderReturn::getOrdersReturnDetail($this->id, 0, $orderBooking['id']) && $orderBooking['is_refunded']) + || ($orderBooking['is_cancelled'] && $orderBooking['is_refunded']) + ) { + continue; + } else { + // if inventory is available for that booking + $bookingParams = array( + 'date_from' => $orderBooking['date_from'], + 'date_to' => $orderBooking['date_to'], + 'hotel_id' => $orderBooking['id_hotel'], + 'id_room_type' => $orderBooking['id_product'], + 'only_search_data' => 1 + ); + + $objHotelBookingDetail = new HotelBookingDetail($orderBooking['id']); + if ($searchRoomsInfo = $objHotelBooking->getBookingData($bookingParams)) { + if (isset($searchRoomsInfo['rm_data'][$orderBooking['id_product']]['data']['available']) + && $searchRoomsInfo['rm_data'][$orderBooking['id_product']]['data']['available'] + ) { + $availableRoomsInfo = $searchRoomsInfo['rm_data'][$orderBooking['id_product']]['data']['available']; + if ($roomIdsAvailable = array_column($availableRoomsInfo, 'id_room')) { + // Check If room is still there in the available rooms list + if (!in_array($orderBooking['id_room'], $roomIdsAvailable)) { + $result['errors'][] = Tools::displayError('You can not change the order status as some rooms are not available now in this order. You can reallocate/swap rooms with other rooms to make rooms available and then change the order status.'); + + break; + } else { + $objHotelBookingDetail->is_refunded = 0; + $objHotelBookingDetail->save(); + } + } else { + $result['errors'][] = Tools::displayError('You can not change the order status as some rooms are not available now in this order. You can reallocate/swap rooms with other rooms to make rooms available and then change the order status.'); + break; + } + } + } else { + $result['errors'][] = Tools::displayError('You can not change the order status as some rooms are not available now in this order. You can reallocate/swap rooms with other rooms to make rooms available and then change the order status.'); + + break; + } + } + } + } + } elseif ($objCurrentOrderState->id == $objNewOrderState->id) { + $result['errors'][] = Tools::displayError('The order has already been assigned this status.'); + } + } + + if (!count($result['errors'])) { + // Create new OrderHistory + $context = Context::getContext(); + $history = new OrderHistory(); + $history->id_order = $this->id; + $history->id_employee = (int)$context->employee->id; + + $useExistingsPayment = false; + if (!$this->hasInvoice()) { + $useExistingsPayment = true; + } + $history->changeIdOrderState((int)$objNewOrderState->id, $this, $useExistingsPayment); + + // Save all changes + $templateVars = array(); + if ($history->add(true)) { + if (!$history->sendEmail($this, $templateVars)) { + // if an error occurred while sending an email the set has_mail_error to true + $result['has_mail_error'] = true; + $result['errors'][] = Tools::displayError('We were unable to send an email to the customer while changing order status.'); + } + + // synchronizes quantities if needed.. + if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { + foreach ($this->getProducts() as $product) { + if (StockAvailable::dependsOnStock($product['product_id'])) { + StockAvailable::synchronize($product['product_id'], (int)$product['id_shop']); + } + } + } + } else { + $result['errors'][] = Tools::displayError('An error occurred while changing order status.'); + } + } + + // if no errors then return status true + if (!count($result['errors'])) { + $result['status'] = true; + } + + return $result; + } } diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 970e130f1..1760c6d34 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -285,11 +285,6 @@ class AdminOrdersControllerCore extends AdminController 'payment' => array( 'title' => $this->l('Payment') ), - 'currency' => array( - 'title' => $this->l('Order Currency'), - 'hint' => $this->l('This is the currency in which customer created the order.'), - 'havingFilter' => true, - ), 'order_source' => array( 'title' => $this->l('Order Source'), 'type' => 'select', @@ -951,6 +946,10 @@ class AdminOrdersControllerCore extends AdminController $smartyVars['roomTypeServiceProducts'] = $roomTypeServiceProducts; } + $objOrderReturn = new OrderReturn(); + $refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($objOrder->id, 0, 1); + $smartyVars['refundReqBookings'] = $refundReqBookings; + $this->context->smarty->assign($smartyVars); $modal = array( @@ -1081,28 +1080,13 @@ class AdminOrdersControllerCore extends AdminController if (!Validate::isLoadedObject($order)) { $this->errors[] = sprintf(Tools::displayError('Order #%d cannot be loaded'), $id_order); } else { - $current_order_state = $order->getCurrentOrderState(); - if ($current_order_state->id == $order_state->id) { - $this->errors[] = $this->displayWarning(sprintf('Order #%d has already been assigned this status.', $id_order)); - } else { - $history = new OrderHistory(); - $history->id_order = $order->id; - $history->id_employee = (int)$this->context->employee->id; - - $use_existings_payment = !$order->hasInvoice(); - $history->changeIdOrderState((int)$order_state->id, $order, $use_existings_payment); - - $carrier = new Carrier($order->id_carrier, $order->id_lang); - $templateVars = array(); - - if ($history->addWithemail(true, $templateVars)) { - if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { - foreach ($order->getProducts() as $product) { - if (StockAvailable::dependsOnStock($product['product_id'])) { - StockAvailable::synchronize($product['product_id'], (int)$product['id_shop']); - } - } - } + $result = $order->changeOrderStatus(); + if (!$result['status']) { + if (isset($result['has_mail_error']) && $result['has_mail_error']) { + $this->errors[] = sprintf( + Tools::displayError('Unable to send email to the customer while changing order status for order #%d.'), + $id_order + ); } else { $this->errors[] = sprintf(Tools::displayError('Cannot change status for order #%d.'), $id_order); } @@ -1111,6 +1095,7 @@ class AdminOrdersControllerCore extends AdminController } } } + if (!count($this->errors)) { Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token); } @@ -1316,115 +1301,11 @@ class AdminOrdersControllerCore extends AdminController /* Change order status, add a new entry in order history and send an e-mail to the customer if needed */ elseif (Tools::isSubmit('submitState') && isset($order)) { if ($this->tabAccess['edit'] === '1') { - $order_state = new OrderState(Tools::getValue('id_order_state')); - - if (!Validate::isLoadedObject($order_state)) { - $this->errors[] = Tools::displayError('The new order status is invalid.'); + $result = $order->changeOrderStatus(); + if ($result['status']) { + Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int)$order->id.'&conf=5&vieworder&token='.$this->token); } else { - $current_order_state = $order->getCurrentOrderState(); - - if ($current_order_state->id == Configuration::get('PS_OS_REFUND')) { - $this->errors[] = Tools::displayError('Order status can not be changed once order status is set to Refunded.'); - } elseif ($current_order_state->id == Configuration::get('PS_OS_CANCELED')) { - $this->errors[] = Tools::displayError('Order status can not be changed once order status is set to Cancelled.'); - } elseif (in_array($order_state->id, array (Configuration::get('PS_OS_OVERBOOKING_PAID'), Configuration::get('PS_OS_OVERBOOKING_UNPAID'), Configuration::get('PS_OS_OVERBOOKING_PARTIAL_PAID')))) { - $objHotelBooking = new HotelBookingDetail(); - if (!$objHotelBooking->getOverbookedRooms($order->id)) { - $this->errors[] = Tools::displayError('Order status can not be changed to any overbooking status as there are no overbooked rooms in the order.'); - } - } elseif ($order_state->id == Configuration::get('PS_OS_REFUND') - && !$order->hasCompletelyRefunded(Order::ORDER_COMPLETE_REFUND_FLAG) - ) { - $this->errors[] = Tools::displayError('Order status can not be set to Refunded until all bookings in the order are completely refunded.'); - } elseif ($order_state->id == Configuration::get('PS_OS_CANCELED') - && !$order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_FLAG) - ) { - $this->errors[] = Tools::displayError('Order status can not be set to Cancelled until all bookings in the order are cancelled.'); - } elseif ($current_order_state->id == Configuration::get('PS_OS_ERROR') && !($order_state->id == Configuration::get('PS_OS_ERROR'))) { - // All rooms must be available before changing status from Payment Error to Other status in which rooms are getting blocked again - $objHotelBooking = new HotelBookingDetail(); - if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($order->id)) { - foreach ($orderBookings as $orderBooking) { - // If booking is refunded then no need to check inventory - if ((OrderReturn::getOrdersReturnDetail($order->id, 0, $orderBooking['id']) && $orderBooking['is_refunded']) - || ($orderBooking['is_cancelled'] && $orderBooking['is_refunded']) - ) { - continue; - } else { - // if inventory is available for that booking - $bookingParams = array( - 'date_from' => $orderBooking['date_from'], - 'date_to' => $orderBooking['date_to'], - 'hotel_id' => $orderBooking['id_hotel'], - 'id_room_type' => $orderBooking['id_product'], - 'only_search_data' => 1 - ); - - $objHotelBookingDetail = new HotelBookingDetail($orderBooking['id']); - if ($searchRoomsInfo = $objHotelBooking->getBookingData($bookingParams)) { - if (isset($searchRoomsInfo['rm_data'][$orderBooking['id_product']]['data']['available']) - && $searchRoomsInfo['rm_data'][$orderBooking['id_product']]['data']['available'] - ) { - $availableRoomsInfo = $searchRoomsInfo['rm_data'][$orderBooking['id_product']]['data']['available']; - if ($roomIdsAvailable = array_column($availableRoomsInfo, 'id_room')) { - // Check If room is still there in the available rooms list - if (!in_array($orderBooking['id_room'], $roomIdsAvailable)) { - $this->errors[] = Tools::displayError('You can not change the order status as some rooms are not available now in this order. You can reallocate/swap rooms with other rooms to make rooms available and then change the order status.'); - - break; - } else { - $objHotelBookingDetail->is_refunded = 0; - $objHotelBookingDetail->save(); - } - } else { - $this->errors[] = Tools::displayError('You can not change the order status as some rooms are not available now in this order. You can reallocate/swap rooms with other rooms to make rooms available and then change the order status.'); - break; - } - } - } else { - $this->errors[] = Tools::displayError('You can not change the order status as some rooms are not available now in this order. You can reallocate/swap rooms with other rooms to make rooms available and then change the order status.'); - - break; - } - } - } - } - } elseif ($current_order_state->id == $order_state->id) { - $this->errors[] = Tools::displayError('The order has already been assigned this status.'); - } - - // If no errors then we change the order status - if (!count($this->errors)) { - // Create new OrderHistory - $history = new OrderHistory(); - $history->id_order = $order->id; - $history->id_employee = (int)$this->context->employee->id; - - $use_existings_payment = false; - if (!$order->hasInvoice()) { - $use_existings_payment = true; - } - $history->changeIdOrderState((int)$order_state->id, $order, $use_existings_payment); - - $carrier = new Carrier($order->id_carrier, $order->id_lang); - $templateVars = array(); - - // Save all changes - if ($history->addWithemail(true, $templateVars)) { - // synchronizes quantities if needed.. - if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { - foreach ($order->getProducts() as $product) { - if (StockAvailable::dependsOnStock($product['product_id'])) { - StockAvailable::synchronize($product['product_id'], (int)$product['id_shop']); - } - } - } - - Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int)$order->id.'&conf=5&vieworder&token='.$this->token); - } - - $this->errors[] = Tools::displayError('An error occurred while changing order status, or we were unable to send an email to the customer.'); - } + $this->errors = array_merge($this->errors, $result['errors']); } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); @@ -2063,6 +1944,41 @@ class AdminOrdersControllerCore extends AdminController } } + // update Order refund prices (order_return and order_return_detail) + if ($orderReturns = OrderReturn::getOrdersReturn($order->id_customer, $order->id)) { + $fields = array( + 'refunded_amount', + ); + foreach ($orderReturns as $orderReturn) { + $objOrderReturn = new OrderReturn($orderReturn['id_order_return']); + foreach ($fields as $field) { + $objOrderReturn->{$field} = Tools::convertPriceFull( + $objOrderReturn->{$field}, + $old_currency, + $currency + ); + } + $objOrderReturn->update(); + } + } + + if ($orderReturnDetails = OrderReturn::getOrdersReturnDetail($order->id)) { + $fields = array( + 'refunded_amount', + ); + foreach ($orderReturnDetails as $orderReturnDetail) { + $objOrderReturnDetail = new OrderReturnDetail($orderReturnDetail['id_order_return_detail']); + foreach ($fields as $field) { + $objOrderReturnDetail->{$field} = Tools::convertPriceFull( + $objOrderReturnDetail->{$field}, + $old_currency, + $currency + ); + } + $objOrderReturnDetail->update(); + } + } + // If everything is updated, then redirect to view order with success message Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token); } else { @@ -2143,7 +2059,7 @@ class AdminOrdersControllerCore extends AdminController switch (Tools::getValue('discount_type')) { // Percent type case 1: - if ($discount_value < 100) { + if ($discount_value <= 100) { if (isset($order_invoice)) { $cart_rules[$order_invoice->id]['value_tax_incl'] = Tools::ps_round($order_invoice->total_paid_tax_incl * $discount_value / 100, 2); $cart_rules[$order_invoice->id]['value_tax_excl'] = Tools::ps_round($order_invoice->total_paid_tax_excl * $discount_value / 100, 2); @@ -4587,103 +4503,6 @@ class AdminOrdersControllerCore extends AdminController $children = $occupancy['children']; $child_ages = $occupancy['child_ages']; - /*By webkul to validate fields before deleting the cart and order data form the tables*/ - if ($id_hotel == '') { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Hotel Id is mising.'), - ))); - } elseif ($id_room == '') { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Room Id is missing.'), - ))); - } elseif ($new_date_from == '') { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Please Enter Check In Date.'), - ))); - } elseif (!Validate::isDateFormat($new_date_from)) { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Please Enter a Valid Check In Date.'), - ))); - } elseif ($new_date_to == '') { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Please Enter Check Out Date.'), - ))); - } elseif (!Validate::isDateFormat($new_date_to)) { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Please Enter a valid Check out Date.'), - ))); - } elseif ($new_date_from < $curr_date) { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Check In date should not be after current date.'), - ))); - } elseif ($new_date_to <= $new_date_from) { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Check out Date Should be after Check In date.'), - ))); - } elseif ($room_unit_price == '') { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Please enter unit price.'), - ))); - } elseif (!Validate::isPrice($room_unit_price)) { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Please enter a valid unit price.'), - ))); - } elseif (!Validate::isUnsignedInt($product_quantity)) { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Invalid quantity.'), - ))); - } - - // validations if order is with occupancy - if (!isset($adults) || !$adults || !Validate::isUnsignedInt($adults)) { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Invalid number of adults.'), - ))); - } elseif (!Validate::isUnsignedInt($children)) { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Invalid number of children.'), - ))); - } - - if ($children > 0) { - if (!isset($child_ages) || ($children != count($child_ages))) { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Please provide all children age.'), - ))); - } else { - foreach($child_ages as $childAge) { - if (!Validate::isUnsignedInt($childAge)) { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Invalid children age.'), - ))); - } - } - } - } - - $rooms_booked = $obj_booking_detail->getRoomBookinInformationForDateRangeByOrder($id_room, $old_date_from, $old_date_to, $new_date_from, $new_date_to); - if ($rooms_booked) { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('This Room Unavailable For Selected Duration.'), - ))); - } - // By webkul to calculate rates of the product from hotelreservationsystem tables with feature prices.... // add feature price for updated price @@ -5629,8 +5448,48 @@ class AdminOrdersControllerCore extends AdminController { $this->doEditValidation($order_detail, $order, $order_invoice); + $id_hotel_booking = Tools::getValue('id_booking_detail'); $product_price_tax_incl = str_replace(',', '.', Tools::getValue('product_price_tax_incl')); $product_price_tax_excl = str_replace(',', '.', Tools::getValue('product_price_tax_excl')); + $product_informations = $_POST['edit_product']; + $new_date_from = trim(date('Y-m-d', strtotime($product_informations['date_from']))); + $new_date_to = trim(date('Y-m-d', strtotime($product_informations['date_to']))); + $old_date_from = date('Y-m-d', strtotime(trim(Tools::getValue('date_from')))); + $old_date_to = date('Y-m-d', strtotime(trim(Tools::getValue('date_to')))); + $id_hotel = trim(Tools::getValue('id_hotel')); + $id_room = trim(Tools::getValue('id_room')); + $id_product = trim(Tools::getValue('id_product')); + $room_unit_price = trim(Tools::getValue('room_unit_price')); + $obj_booking_detail = new HotelBookingDetail(); + $product_quantity = (int) $obj_booking_detail->getNumberOfDays($new_date_from, $new_date_to); + $old_product_quantity = (int) $obj_booking_detail->getNumberOfDays($old_date_from, $old_date_to); + $qty_diff = $product_quantity - $old_product_quantity; + $occupancy = array_shift(Tools::getValue('occupancy')); + $adults = $occupancy['adults']; + $children = $occupancy['children']; + $child_ages = $occupancy['child_ages']; + + // If order is refunded, the validate changes which are not allowed + $objOrderReturn = new OrderReturn(); + $refundReqBookings = $objOrderReturn->getOrderRefundRequestedBookings($order->id, 0, 1); + if ($refundReqBookings && (in_array($id_hotel_booking, $refundReqBookings))) { + $objBookingDetail = new HotelBookingDetail($id_hotel_booking); + // If order is cancelled, we can't edit order + if ($objBookingDetail->is_refunded && $objBookingDetail->is_cancelled) { + die(json_encode(array( + 'result' => false, + 'error' => Tools::displayError('Booking cannot be edited if booking is cancelled.'), + ))); + // If order is refunded, we can't edit dates + } elseif ($objBookingDetail->is_refunded + && (strtotime($old_date_from) != strtotime($new_date_from) || strtotime($old_date_to) != strtotime($new_date_to)) + ) { + die(json_encode(array( + 'result' => false, + 'error' => Tools::displayError('Check-In/Check-Out dates cannot be changed if booking is refunded.'), + ))); + } + } if (!Validate::isPrice($product_price_tax_incl) || !Validate::isPrice($product_price_tax_excl)) { die(json_encode(array( @@ -5639,46 +5498,89 @@ class AdminOrdersControllerCore extends AdminController ))); } - $product_informations = Tools::getValue('edit_product'); - $old_date_from = date('Y-m-d', strtotime(trim(Tools::getValue('date_from')))); - $old_date_to = date('Y-m-d', strtotime(trim(Tools::getValue('date_to')))); - $new_date_from = trim(date('Y-m-d', strtotime($product_informations['date_from']))); - $new_date_to = trim(date('Y-m-d', strtotime($product_informations['date_to']))); - $obj_booking_detail = new HotelBookingDetail(); - $product_quantity = (int) $obj_booking_detail->getNumberOfDays($new_date_from, $new_date_to); - $id_room = Tools::getValue('id_room'); - - if (trim(Tools::getValue('id_hotel')) == '') { + if ($id_hotel == '') { die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Hotel Id is mising.'), ))); - } elseif (trim($id_room) == '') { + } elseif ($id_room == '') { die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Room Id is missing.'), ))); - } elseif (trim(date('Y-m-d', strtotime($product_informations['date_from']))) == '') { + } elseif ($new_date_from == '') { die(json_encode(array( 'result' => false, - 'error' => Tools::displayError('Please enter check-in date.'), + 'error' => Tools::displayError('Please enter Check-In date.'), ))); } elseif (!Validate::isDateFormat($new_date_from)) { die(json_encode(array( 'result' => false, - 'error' => Tools::displayError('Please enter a valid check-in date.'), + 'error' => Tools::displayError('Please enter a valid Check-In date.'), ))); } elseif ($new_date_to == '') { die(json_encode(array( 'result' => false, - 'error' => Tools::displayError('Please enter check-out date.'), + 'error' => Tools::displayError('Please enter Check-Out date.'), ))); } elseif (!Validate::isDateFormat($new_date_to)) { die(json_encode(array( 'result' => false, - 'error' => Tools::displayError('Please enter a valid check-out date.'), + 'error' => Tools::displayError('Please enter a valid Check-out date.'), + ))); + } elseif ($new_date_to <= $new_date_from) { + die(json_encode(array( + 'result' => false, + 'error' => Tools::displayError('Check-out date should be after Check-In date.'), + ))); + } elseif ($room_unit_price == '') { + die(json_encode(array( + 'result' => false, + 'error' => Tools::displayError('Please enter unit price.'), + ))); + } elseif (!Validate::isPrice($room_unit_price)) { + die(json_encode(array( + 'result' => false, + 'error' => Tools::displayError('Please enter a valid unit price.'), + ))); + } elseif (!Validate::isUnsignedInt($product_quantity)) { + die(json_encode(array( + 'result' => false, + 'error' => Tools::displayError('Invalid quantity.'), ))); } + + // validations if order is with occupancy + if (!isset($adults) || !$adults || !Validate::isUnsignedInt($adults)) { + die(json_encode(array( + 'result' => false, + 'error' => Tools::displayError('Invalid number of adults.'), + ))); + } elseif (!Validate::isUnsignedInt($children)) { + die(json_encode(array( + 'result' => false, + 'error' => Tools::displayError('Invalid number of children.'), + ))); + } + + if ($children > 0) { + if (!isset($child_ages) || ($children != count($child_ages))) { + die(json_encode(array( + 'result' => false, + 'error' => Tools::displayError('Please provide all children age.'), + ))); + } else { + foreach($child_ages as $childAge) { + if (!Validate::isUnsignedInt($childAge)) { + die(json_encode(array( + 'result' => false, + 'error' => Tools::displayError('Invalid children age.'), + ))); + } + } + } + } + if ($this->context->employee->isSuperAdmin()) { $backOrderConfigKey = 'PS_BACKDATE_ORDER_SUPERADMIN'; } else { @@ -5689,24 +5591,18 @@ class AdminOrdersControllerCore extends AdminController if ($new_date_from < $compareDate) { die(json_encode(array( 'result' => false, - 'error' => sprintf(Tools::displayError('Check-in date should not be date before %s.'),$compareDate) + 'error' => sprintf(Tools::displayError('Check-In date should not be date before %s.'),$compareDate) ))); } } - if ($new_date_to <= $new_date_from) { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Check-out date should be after check-in date.'), - ))); - } elseif (!Validate::isUnsignedInt($product_quantity)) { - die(json_encode(array( - 'result' => false, - 'error' => Tools::displayError('Invalid quantity.'), - ))); - } - $rooms_booked = $obj_booking_detail->getRoomBookinInformationForDateRangeByOrder($id_room, $old_date_from, $old_date_to, $new_date_from, $new_date_to); - if ($rooms_booked) { + if ($rooms_booked = $obj_booking_detail->getRoomBookinInformationForDateRangeByOrder( + $id_room, + $old_date_from, + $old_date_to, + $new_date_from, + $new_date_to + )) { die(json_encode(array( 'result' => false, 'error' => Tools::displayError('This room is unavailable for selected duration.'), diff --git a/install/langs/bg/data/order_state.xml b/install/langs/bg/data/order_state.xml index ba7230bc7..f4661ce31 100644 --- a/install/langs/bg/data/order_state.xml +++ b/install/langs/bg/data/order_state.xml @@ -46,6 +46,6 @@ Получено частично плащане - + diff --git a/install/langs/bn/data/order_state.xml b/install/langs/bn/data/order_state.xml index dd6f8417b..079e3acba 100644 --- a/install/langs/bn/data/order_state.xml +++ b/install/langs/bn/data/order_state.xml @@ -46,6 +46,6 @@ আংশিক পেমেন্ট প্রাপ্ত - + diff --git a/install/langs/br/data/order_state.xml b/install/langs/br/data/order_state.xml index 306182ff7..e9a75f914 100644 --- a/install/langs/br/data/order_state.xml +++ b/install/langs/br/data/order_state.xml @@ -46,6 +46,6 @@ Pagamento parcial recebido - + diff --git a/install/langs/cs/data/order_state.xml b/install/langs/cs/data/order_state.xml index 8120bd196..bdbe0e77e 100644 --- a/install/langs/cs/data/order_state.xml +++ b/install/langs/cs/data/order_state.xml @@ -46,6 +46,6 @@ Částečná platba přijata - + \ No newline at end of file diff --git a/install/langs/de/data/order_state.xml b/install/langs/de/data/order_state.xml index 3366f5e62..65b042db0 100644 --- a/install/langs/de/data/order_state.xml +++ b/install/langs/de/data/order_state.xml @@ -46,6 +46,6 @@ Teilzahlung erhalten - + diff --git a/install/langs/en/data/order_state.xml b/install/langs/en/data/order_state.xml index b8cf92365..16e519f1a 100644 --- a/install/langs/en/data/order_state.xml +++ b/install/langs/en/data/order_state.xml @@ -46,6 +46,6 @@ Partial payment received - + diff --git a/install/langs/es/data/order_state.xml b/install/langs/es/data/order_state.xml index ebe33ab5d..f47bf65d3 100644 --- a/install/langs/es/data/order_state.xml +++ b/install/langs/es/data/order_state.xml @@ -46,6 +46,6 @@ Pago parcial recibido - + diff --git a/install/langs/fa/data/order_state.xml b/install/langs/fa/data/order_state.xml index ee8611aa7..8c992e07b 100644 --- a/install/langs/fa/data/order_state.xml +++ b/install/langs/fa/data/order_state.xml @@ -46,6 +46,6 @@ پرداخت جزئی دریافت شد - + diff --git a/install/langs/fr/data/order_state.xml b/install/langs/fr/data/order_state.xml index bccde25eb..55aa13404 100644 --- a/install/langs/fr/data/order_state.xml +++ b/install/langs/fr/data/order_state.xml @@ -46,6 +46,6 @@ Paiement partiel reçu - + diff --git a/install/langs/he/data/order_state.xml b/install/langs/he/data/order_state.xml index b9c8e24de..7bfc432fc 100644 --- a/install/langs/he/data/order_state.xml +++ b/install/langs/he/data/order_state.xml @@ -46,6 +46,6 @@ תשלום חלקי התקבל - + diff --git a/install/langs/hr/data/order_state.xml b/install/langs/hr/data/order_state.xml index e6805423b..39eaaa302 100644 --- a/install/langs/hr/data/order_state.xml +++ b/install/langs/hr/data/order_state.xml @@ -46,6 +46,6 @@ Primljena djelomična uplata - + diff --git a/install/langs/hu/data/order_state.xml b/install/langs/hu/data/order_state.xml index 5d53757b9..9b2b9c956 100644 --- a/install/langs/hu/data/order_state.xml +++ b/install/langs/hu/data/order_state.xml @@ -46,6 +46,6 @@ Részleges kifizetés megérkezett - + diff --git a/install/langs/id/data/order_state.xml b/install/langs/id/data/order_state.xml index 90b3ac4a1..853175220 100644 --- a/install/langs/id/data/order_state.xml +++ b/install/langs/id/data/order_state.xml @@ -46,6 +46,6 @@ Pembayaran sebagian diterima - + diff --git a/install/langs/it/data/order_state.xml b/install/langs/it/data/order_state.xml index e77a35b36..a328ca9ae 100644 --- a/install/langs/it/data/order_state.xml +++ b/install/langs/it/data/order_state.xml @@ -46,6 +46,6 @@ Pagamento parziale ricevuto - + diff --git a/install/langs/lt/data/order_state.xml b/install/langs/lt/data/order_state.xml index 270e6c6c6..d58ef02e0 100644 --- a/install/langs/lt/data/order_state.xml +++ b/install/langs/lt/data/order_state.xml @@ -46,6 +46,6 @@ Gautas dalinis apmokėjimas - + diff --git a/install/langs/mk/data/order_state.xml b/install/langs/mk/data/order_state.xml index 20086e951..d128aebe8 100644 --- a/install/langs/mk/data/order_state.xml +++ b/install/langs/mk/data/order_state.xml @@ -46,6 +46,6 @@ Примено е делумно плаќање - + diff --git a/install/langs/nl/data/order_state.xml b/install/langs/nl/data/order_state.xml index c2d7da6c7..c970d6d93 100644 --- a/install/langs/nl/data/order_state.xml +++ b/install/langs/nl/data/order_state.xml @@ -46,6 +46,6 @@ Gedeeltelijke betaling ontvangen - + diff --git a/install/langs/no/data/order_state.xml b/install/langs/no/data/order_state.xml index b8cf92365..16e519f1a 100644 --- a/install/langs/no/data/order_state.xml +++ b/install/langs/no/data/order_state.xml @@ -46,6 +46,6 @@ Partial payment received - + diff --git a/install/langs/pl/data/order_state.xml b/install/langs/pl/data/order_state.xml index 4cb1831b6..644e3d9ab 100644 --- a/install/langs/pl/data/order_state.xml +++ b/install/langs/pl/data/order_state.xml @@ -46,6 +46,6 @@ Otrzymano częściową płatność - + diff --git a/install/langs/pt/data/order_state.xml b/install/langs/pt/data/order_state.xml index 91361bf5c..382b23550 100644 --- a/install/langs/pt/data/order_state.xml +++ b/install/langs/pt/data/order_state.xml @@ -46,6 +46,6 @@ Pagamento parcial recebido - + diff --git a/install/langs/qc/data/order_state.xml b/install/langs/qc/data/order_state.xml index 7873dbeb6..fce19d5f6 100644 --- a/install/langs/qc/data/order_state.xml +++ b/install/langs/qc/data/order_state.xml @@ -46,6 +46,6 @@ Paiement partiel reçu - + diff --git a/install/langs/ro/data/order_state.xml b/install/langs/ro/data/order_state.xml index 7b310b557..68afd22b7 100644 --- a/install/langs/ro/data/order_state.xml +++ b/install/langs/ro/data/order_state.xml @@ -46,6 +46,6 @@ Plata parțială primită - + diff --git a/install/langs/ru/data/order_state.xml b/install/langs/ru/data/order_state.xml index e5fb90335..983bc12dc 100644 --- a/install/langs/ru/data/order_state.xml +++ b/install/langs/ru/data/order_state.xml @@ -46,6 +46,6 @@ Частичная оплата получена - + diff --git a/install/langs/si/data/order_state.xml b/install/langs/si/data/order_state.xml index af6b0edd2..73d97f838 100644 --- a/install/langs/si/data/order_state.xml +++ b/install/langs/si/data/order_state.xml @@ -46,6 +46,6 @@ අර්ධ ගෙවීමක් ලැබී ඇත - + diff --git a/install/langs/sr/data/order_state.xml b/install/langs/sr/data/order_state.xml index f2f17a60e..f2a5e6529 100644 --- a/install/langs/sr/data/order_state.xml +++ b/install/langs/sr/data/order_state.xml @@ -46,6 +46,6 @@ Делимична уплата примљена - + diff --git a/install/langs/sv/data/order_state.xml b/install/langs/sv/data/order_state.xml index 312b0b533..e55775740 100644 --- a/install/langs/sv/data/order_state.xml +++ b/install/langs/sv/data/order_state.xml @@ -46,6 +46,6 @@ Delbetalning mottagen - + diff --git a/install/langs/tw/data/order_state.xml b/install/langs/tw/data/order_state.xml index 366a726a3..f535a0c61 100644 --- a/install/langs/tw/data/order_state.xml +++ b/install/langs/tw/data/order_state.xml @@ -46,6 +46,6 @@ 已收到部分付款 - + diff --git a/install/langs/vn/data/order_state.xml b/install/langs/vn/data/order_state.xml index e8d3f740c..9b79504d1 100644 --- a/install/langs/vn/data/order_state.xml +++ b/install/langs/vn/data/order_state.xml @@ -46,6 +46,6 @@ Đã nhận được một phần thanh toán - + diff --git a/install/langs/zh/data/order_state.xml b/install/langs/zh/data/order_state.xml index 93728e668..7e868eec7 100644 --- a/install/langs/zh/data/order_state.xml +++ b/install/langs/zh/data/order_state.xml @@ -46,6 +46,6 @@ 已收到部分付款 - + diff --git a/js/daterangepicker/qlodaterangepicker.js b/js/daterangepicker/qlodaterangepicker.js index 369ea9325..401d2b6bc 100644 --- a/js/daterangepicker/qlodaterangepicker.js +++ b/js/daterangepicker/qlodaterangepicker.js @@ -22,6 +22,9 @@ var dateRangePickerOrg = $.fn.dateRangePicker; $.fn.dateRangePicker = function(opt) { if(typeof opt === "object") { + let container = $(this).parent(); + container.css({ position: 'relative' }); + const custom_opt = { format: 'DD-MM-YYYY', showTopbar: false, @@ -31,14 +34,14 @@ minDays: 2, startOfWeek: 'monday', hoveringTooltip: false, - container: '#page', + container: container, + inline: true, customArrowPrevSymbol: '', customArrowNextSymbol: '', - getValue: function() - { + getValue: function() { return $(this).find('span').html(); }, - setValue: function(s, s1, s2) { + setValue: function(s) { if (s) { $(this).find('span').html(s.replace('to', '  ')); } else { @@ -48,15 +51,56 @@ } } } + $.each(opt, function(index) { delete custom_opt[index]; }); $.extend(true, opt, custom_opt); - } var args = Array.prototype.slice.call(arguments,0); - return dateRangePickerOrg.apply(this, args); + + const dateRangePickerInput = dateRangePickerOrg.apply(this, args); + const calendarDom = $(dateRangePickerInput).data('dateRangePicker').getDatePicker(); + + dateRangePickerInput.on('datepicker-open', function() { + const positionClass = getPositionClass(dateRangePickerInput, calendarDom); + $(calendarDom).removeClass('top bottom').addClass(positionClass); + setPosition(dateRangePickerInput, calendarDom, positionClass) + }); + + return dateRangePickerInput; + + // helper function definitions + function getPositionClass(dateRangePickerInput, calendarDom) { + const inputElementHeight = dateRangePickerInput.outerHeight(); + const spaceTop = dateRangePickerInput.offset().top - $(window).scrollTop(); + const spaceBottom = $(window).height() - inputElementHeight - spaceTop; + const maxHeightNeeded = $(calendarDom).get(0).scrollHeight; + + let positionClass = 'bottom'; + // determine position class + if (spaceBottom < maxHeightNeeded && spaceTop > spaceBottom) { + positionClass = 'top'; + } + + return positionClass; + } + + function setPosition(dateRangePickerInput, calendarDom, positionClass) { + const inputElementHeight = dateRangePickerInput.outerHeight(); + + const css = {}; + if (positionClass == 'top') { + css.top = 'unset'; + css.bottom = inputElementHeight; + } else { + css.bottom = 'unset'; + css.top = $(dateRangePickerInput).position().top + inputElementHeight; + } + + $(calendarDom).css(css); + } } -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/mails/en/partial_payment_accepted.html b/mails/en/partial_payment_accepted.html new file mode 100644 index 000000000..45940907a --- /dev/null +++ b/mails/en/partial_payment_accepted.html @@ -0,0 +1,138 @@ + + + + + + Message from {shop_name} + + + + + + + + + + + + +
  + + + + + + + + + + + + + + + + + +{extra_mail_content_html} + + + + + + + + + + + + + +
+ + Hi {firstname} {lastname},
+ Thank you for booking with {shop_name}! +
+
+ + + + + + +
  + +

+ Order {order_name} - Payment processed

+ + Your payment for order with the reference {order_name} was successfully processed.

+ + Total Booking Amount: {total_paid}

+ Partial Payment Amount: {advance_paid_amount}

+ Total Paid Amount: {total_paid_real}

+
+
 
+
+ + + You can review your order and download your invoice from the "Order history" section of your customer account by clicking "My account" on our website. + +
+ + + If you have a guest account, you can follow your order via the "Guest Tracking" section on our website. + +
+
 
+ + diff --git a/mails/en/partial_payment_accepted.txt b/mails/en/partial_payment_accepted.txt new file mode 100644 index 000000000..799594197 --- /dev/null +++ b/mails/en/partial_payment_accepted.txt @@ -0,0 +1,26 @@ + +[/{shop_url}] + +Hi {firstname} {lastname}, + +Thank you for booking with {shop_name}! + +Order {order_name} - Payment processed + +Your payment for order with the reference {order_name} was successfully processed. + +Total Booking Amount: {total_paid} +Partial Payment Amount: {advance_paid_amount} +Total Paid Amount: {total_paid_real} + +You can review your order and download your invoice from the +"Order history" [/{history_url}] section of your customer account by +clicking "My account" [/{my_account_url}] on our website. + +If you have a guest account, you can follow your order via the +"Guest Tracking" [/{guest_tracking_url}?id_order={order_name}] section +on our website. + +{shop_name} [/{shop_url}] powered by Webkul(tm) +[https://webkul.com] + diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php index 8aee39b6f..0b615f59a 100644 --- a/modules/hotelreservationsystem/classes/HotelHelper.php +++ b/modules/hotelreservationsystem/classes/HotelHelper.php @@ -199,6 +199,8 @@ class HotelHelper Configuration::updateValue('WK_HOTEL_LOCATION_ENABLE', 1); Configuration::updateValue('WK_HOTEL_NAME_ENABLE', 1); + Configuration::updateValue('WK_HOTEL_NAME_SEARCH_THRESHOLD', 5); + Configuration::updateValue('WK_SEARCH_AUTO_FOCUS_NEXT_FIELD', 1); Configuration::updateValue('WK_ROOM_LEFT_WARNING_NUMBER', 10); Configuration::updateValue('WK_HTL_ESTABLISHMENT_YEAR', 2010); diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php index bfbf62f2b..7300566ee 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductPrice.php @@ -72,8 +72,10 @@ class RoomTypeServiceProductPrice extends ObjectModel if ($result = Db::getInstance()->getRow(' SELECT spp.`price`, spp.`id_tax_rules_group`, p.`auto_add_to_cart`, p.`price_addition_type` FROM `'._DB_PREFIX_.'product` p - LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product` sp ON (sp.`id_product` = p.`id_product`) - LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product_price` spp ON (spp.`id_product` = p.`id_product`) + LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product` sp + ON (sp.`id_product` = p.`id_product`) + LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product_price` spp + ON (spp.`id_product` = sp.`id_product` AND spp.`id_element` = sp.`id_element` AND spp.`element_type` = sp.`element_type`) WHERE p.`id_product`='.(int)$idProduct. ' AND sp.`id_element`='.(int)$idElement. ' AND sp.`element_type`='.(int)$elementType) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php index 30b34ea38..2d8d7ff6d 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php @@ -81,6 +81,32 @@ class AdminHotelGeneralSettingsController extends ModuleAdminController 'hint' => $this->l('This option can be disabled if only one active hotel in the website. In case of more than one active hotel, Hotel Name will always be shown in the search panel.'), ), + 'WK_SEARCH_AUTO_FOCUS_NEXT_FIELD' => array( + 'title' => $this->l('Focus next field automatically'), + 'cast' => 'intval', + 'type' => 'bool', + 'default' => '0', + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + ), + array( + 'id' => 'active_off', + 'value' => 0, + ), + ), + 'hint' => $this->l('Enable if you want the next booking search field to be focused automatically after setting value for a field.'), + ), + 'WK_HOTEL_NAME_SEARCH_THRESHOLD' => array( + 'title' => $this->l('Hotel name search threshold'), + 'type' => 'text', + 'required' => true, + 'validation' => 'isUnsignedInt', + 'hint' => $this->l('Enter the number of hotels after which user can search hotel by name.'), + 'desc' => $this->l('Set to 0 to always show the search box.'), + 'class' => 'fixed-width-xxl', + ), ), 'submit' => array( 'title' => $this->l('Save'), @@ -312,6 +338,8 @@ class AdminHotelGeneralSettingsController extends ModuleAdminController public function postProcess() { if (Tools::isSubmit('submitOptions'.$this->table)) { + $hotelNameSearchThreshold = Tools::getValue('WK_HOTEL_NAME_SEARCH_THRESHOLD'); + // check if field is atleast in default language. Not available in default prestashop $defaultLangId = Configuration::get('PS_LANG_DEFAULT'); $objDefaultLanguage = Language::getLanguage((int) $defaultLangId); @@ -324,6 +352,12 @@ class AdminHotelGeneralSettingsController extends ModuleAdminController // End occupancy fields validation + if (!$hotelNameSearchThreshold && $hotelNameSearchThreshold !== '0') { + $this->errors[] = $this->l('Hotel name search threshold field is required.'); + } elseif (!Validate::isUnsignedInt($hotelNameSearchThreshold)) { + $this->errors[] = $this->l('Hotel name search threshold field is invalid.'); + } + if (!trim(Tools::getValue('WK_HTL_CHAIN_NAME_'.$defaultLangId))) { $this->errors[] = $this->l('Hotel chain name is required at least in ').$objDefaultLanguage['name']; } else { diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index bf6473245..76a6c3bae 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -509,6 +509,7 @@ class HotelReservationSystem extends Module 'htl_room_type_global_demand', 'htl_room_type_global_demand_advance_option', 'htl_order_refund_rules', + 'htl_settings_link', ); //If Admin update new language when we do entry in module all lang tables. HotelHelper::updateLangTables($newIdLang, $langTables); diff --git a/modules/wkroomsearchblock/classes/WkRoomSearchHelper.php b/modules/wkroomsearchblock/classes/WkRoomSearchHelper.php index dc4ac075c..effe0f15f 100644 --- a/modules/wkroomsearchblock/classes/WkRoomSearchHelper.php +++ b/modules/wkroomsearchblock/classes/WkRoomSearchHelper.php @@ -228,6 +228,7 @@ class WkRoomSearchHelper $smartyVars['hotels_info'] = $hotelsInfo; $smartyVars['show_hotel_name'] = Configuration::get('WK_HOTEL_NAME_ENABLE'); $smartyVars['max_child_age'] = Configuration::get('WK_GLOBAL_CHILD_MAX_AGE'); + $smartyVars['hotel_name_search_threshold'] = (int) Configuration::get('WK_HOTEL_NAME_SEARCH_THRESHOLD'); $maxOrderDate = HotelOrderRestrictDate::getMaxOrderDate($idHotel); $smartyVars['max_order_date'] = date('Y-m-d', strtotime($maxOrderDate)); diff --git a/modules/wkroomsearchblock/controllers/front/autocompletesearch.php b/modules/wkroomsearchblock/controllers/front/autocompletesearch.php index 4a051c103..9dfa3bed5 100644 --- a/modules/wkroomsearchblock/controllers/front/autocompletesearch.php +++ b/modules/wkroomsearchblock/controllers/front/autocompletesearch.php @@ -22,44 +22,51 @@ class WkRoomSearchBlockAutoCompleteSearchModuleFrontController extends ModuleFro { public function initContent() { - $result = array(); $this->display_column_left = false; $this->display_column_right = false; + + $result = array('status' => false); $search_data = Tools::getValue('to_search_data'); $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); - if ($return_data) { - $html = ''; - foreach ($return_data as $value) { - $html .= '
  • '. - $value['name'].'
  • '; - } - $result['status'] = 'success'; + $locationCategories = $obj_htl_info->getHotelCategoryTree($search_data); + if ($locationCategories) { + $this->context->smarty->assign(array('location_categories' => $locationCategories)); + $html = $this->context->smarty->fetch( + $this->module->getTemplatePath('location-options.tpl') + ); + $result['status'] = true; $result['data'] = $html; } } 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['id']); + $locationCategories = Category::getAllCategoriesName($location_category_id); + if ($locationCategories) { + $hotelsInfo = array(); + foreach ($locationCategories as $category) { + if ($hotelInfo = $obj_htl_info->hotelBranchInfoByCategoryId($category['id_category'])) { + $maxOrderDate = HotelOrderRestrictDate::getMaxOrderDate($hotelInfo['id']); $maxOrderDate = date('Y-m-d', strtotime($maxOrderDate)); - $html .= '
  • '. - $hotel_info['hotel_name'].'
  • '; + + $hotelsInfo[] = array( + 'id_hotel' => $hotelInfo['id'], + 'id_category' => $hotelInfo['id_category'], + 'hotel_name' => $hotelInfo['hotel_name'], + 'max_order_date' => $maxOrderDate, + ); } } - $result['status'] = 'success'; - $result['data'] = $html; - } else { - $result['status'] = 'failed2'; + + $this->context->smarty->assign(array('hotels_info' => $hotelsInfo)); + $html = $this->context->smarty->fetch( + $this->module->getTemplatePath('hotel-options.tpl') + ); + + $result['status'] = true; + $result['html_hotel_options'] = $html; } - } else { - $result['status'] = 'failed3'; } - die(json_encode($result)); + + $this->ajaxDie(json_encode($result)); } } diff --git a/modules/wkroomsearchblock/views/css/chosen.css b/modules/wkroomsearchblock/views/css/chosen.css new file mode 100644 index 000000000..779c5e4c7 --- /dev/null +++ b/modules/wkroomsearchblock/views/css/chosen.css @@ -0,0 +1,470 @@ +/** + * 2010-2024 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-2024 Webkul IN + * @license LICENSE.txt + */ + +/* @group Base */ +.chosen-container { + position: relative; + vertical-align: middle; + font-size: 14px; + zoom: 1; + /* display: inline; */ + -moz-user-select: -moz-none; + -ms-user-select: none; + -webkit-user-select: none; + user-select: none; +} +.chosen-container .chosen-drop { + position: absolute; + top: 0; + left: -9999px; + z-index: 1010; + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; + width: 100%; + border-top: 0; + box-shadow: 0 4px 5px rgba(0, 0, 0, 0.15); +} +.chosen-container.chosen-container-single-nosearch .chosen-drop { + top: 100%; +} +.chosen-container.chosen-with-drop .chosen-drop { + left: 0; +} +.chosen-container a { + cursor: pointer; +} + +/* @end */ +/* @group Single Chosen */ +.chosen-container-single .chosen-single { + position: relative; + display: block; + overflow: hidden; + padding-left: 35px; + height: 100%; + border: 1px solid #555555; + border-radius: 4px; + background-clip: padding-box; + box-shadow: 0 0 3px #fff inset, 0 1px 1px rgba(0, 0, 0, 0.1); + color: #444; + text-decoration: none; + white-space: nowrap; + line-height: 24px; + background: #fff url('../img/icon-hotel.svg') no-repeat 10px 50%; + min-height: 55px; +} +.chosen-container-single.error_border { + border: none !important; +} +.chosen-container-single.error_border .chosen-single { + border: 2px solid red !important; +} + +.chosen-container-single .chosen-default { + color: #999; +} +.chosen-container-single .chosen-single span { + display: block; + overflow: hidden; + margin-right: 26px; + text-overflow: ellipsis; + white-space: nowrap; + position: relative; + top: 15px; + color: #333; +} +.chosen-container-single .chosen-single-with-deselect span { + margin-right: 38px; +} +.chosen-container-single .chosen-single abbr { + position: absolute; + top: 6px; + right: 26px; + display: block; + width: 12px; + height: 12px; + background: url('chosen-sprite.png') -42px 1px no-repeat; + font-size: 1px; +} +.chosen-container-single .chosen-single abbr:hover { + background-position: -42px -10px; +} +.chosen-container-single.chosen-disabled .chosen-single abbr:hover { + background-position: -42px -10px; +} +.chosen-container-single .chosen-single div { + position: absolute; + top: 0; + right: 0; + display: block; + width: 18px; + height: 100%; +} +.chosen-container-single .chosen-single div b { + display: block; + width: 100%; + height: 100%; + background: url('../../../../themes/hotel-reservation-theme/img/icon/icon-dropdown-arrow.svg') no-repeat calc(100% - 8px) 50%; +} +.chosen-container-single .chosen-search { + position: relative; + z-index: 1010; + margin: 0; + white-space: nowrap; + background: #fff; + border-radius: 4px; + height: 55px; +} +.chosen-container-single .chosen-search::after { + content: ''; + position: absolute; + top: 16px; + right: 1px; + height: 22px; + width: 19px; + background: url('../../../../themes/hotel-reservation-theme/img/icon/icon-dropdown-arrow.svg') no-repeat calc(100% - 8px) 50%; + /* background: url('../img/icon-hotel.svg') no-repeat 9px 50%; */ +} +.chosen-container-single .chosen-search input[type="text"] { + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; + margin: 0; + padding: 0; + padding-left: 35px; + width: 100%; + height: 100%; + outline: 0; + border: none; + font-size: 1em; + line-height: normal; + border-radius: 4px; + background: url('../img/icon-hotel.svg') no-repeat 9px 50%; +} +.chosen-container-single.chosen-container-active .chosen-search input[type="text"] { + border: 2px solid #1292FF; + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); + transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s; +} +.chosen-container-single .chosen-drop { + margin-top: -1px; + border-radius: 0 0 4px 4px; + background-clip: padding-box; +} +.chosen-container-single.chosen-container-single-nosearch .chosen-search { + position: absolute; + left: -9999px; +} + +/* @end */ +/* @group Results */ +.chosen-container .chosen-results { + position: relative; + overflow-x: hidden; + overflow-y: auto; + max-height: 240px; + background: #fff; + margin-top: 2px; + margin-bottom: 0; +} +.chosen-container .chosen-results li { + display: none; + margin: 0; + padding: 15px; + list-style: none; + color: #333; +} +.chosen-container .chosen-results li.active-result { + display: list-item; + cursor: pointer; +} +.chosen-container .chosen-results li.disabled-result { + display: list-item; + color: #ccc; + cursor: default; +} +.chosen-container .chosen-results li.highlighted { + background-color: #379bf0; + color: #fff; +} +.chosen-container .chosen-results li.no-results { + display: list-item; + background: #f4f4f4; +} +.chosen-container .chosen-results li.group-result { + display: list-item; + font-weight: bold; + cursor: default; +} +.chosen-container .chosen-results li.group-option { + padding-left: 15px; +} +.chosen-container .chosen-results li em { + font-style: normal; + text-decoration: underline; +} + +/* @end */ +/* @group Multi Chosen */ +.chosen-container-multi .chosen-choices { + position: relative; + overflow: hidden; + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; + margin: 0; + padding: 0; + width: 100%; + height: auto !important; + height: 1%; + border: 1px solid #aaa; + background-color: #fff; + background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJvYmplY3RCb3VuZGluZ0JveCIgeDE9IjAuNSIgeTE9IjAuMCIgeDI9IjAuNSIgeTI9IjEuMCI+PHN0b3Agb2Zmc2V0PSIxJSIgc3RvcC1jb2xvcj0iI2VlZWVlZSIvPjxzdG9wIG9mZnNldD0iMTUlIiBzdG9wLWNvbG9yPSIjZmZmZmZmIi8+PC9saW5lYXJHcmFkaWVudD48L2RlZnM+PHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idXJsKCNncmFkKSIgLz48L3N2Zz4g'); + background-size: 100%; + background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff)); + background-image: -moz-linear-gradient(#eeeeee 1%, #ffffff 15%); + background-image: -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%); + background-image: linear-gradient(#eeeeee 1%, #ffffff 15%); + cursor: text; +} +.chosen-container-multi .chosen-choices li { + float: left; + list-style: none; +} +.chosen-container-multi .chosen-choices li.search-field { + margin: 0; + padding: 0; + white-space: nowrap; +} +.chosen-container-multi .chosen-choices li.search-field input[type="text"] { + margin: 1px 0; + padding: 5px; + height: 15px; + outline: 0; + border: 0 !important; + background: transparent !important; + box-shadow: none; + color: #666; + font-size: 100%; + line-height: normal; + border-radius: 0; +} +.chosen-container-multi .chosen-choices li.search-field .default { + color: #999; +} +.chosen-container-multi .chosen-choices li.search-choice { + position: relative; + margin: 3px 0 3px 5px; + padding: 3px 20px 3px 5px; + border: 1px solid #aaa; + border-radius: 3px; + background-color: #e4e4e4; + background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJvYmplY3RCb3VuZGluZ0JveCIgeDE9IjAuNSIgeTE9IjAuMCIgeDI9IjAuNSIgeTI9IjEuMCI+PHN0b3Agb2Zmc2V0PSIyMCUiIHN0b3AtY29sb3I9IiNmNGY0ZjQiLz48c3RvcCBvZmZzZXQ9IjUwJSIgc3RvcC1jb2xvcj0iI2YwZjBmMCIvPjxzdG9wIG9mZnNldD0iNTIlIiBzdG9wLWNvbG9yPSIjZThlOGU4Ii8+PHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjZWVlZWVlIi8+PC9saW5lYXJHcmFkaWVudD48L2RlZnM+PHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idXJsKCNncmFkKSIgLz48L3N2Zz4g'); + background-size: 100%; + background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eeeeee)); + background-image: -moz-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); + background-image: -webkit-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); + background-image: linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); + background-clip: padding-box; + box-shadow: 0 0 2px #fff inset, 0 1px 0 rgba(0, 0, 0, 0.05); + color: #333; + line-height: 13px; + cursor: default; +} +.chosen-container-multi .chosen-choices li.search-choice .search-choice-close { + position: absolute; + top: 4px; + right: 3px; + display: block; + width: 12px; + height: 12px; + background: url('chosen-sprite.png') -42px 1px no-repeat; + font-size: 1px; +} +.chosen-container-multi .chosen-choices li.search-choice .search-choice-close:hover { + background-position: -42px -10px; +} +.chosen-container-multi .chosen-choices li.search-choice-disabled { + padding-right: 5px; + border: 1px solid #ccc; + background-color: #e4e4e4; + background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJvYmplY3RCb3VuZGluZ0JveCIgeDE9IjAuNSIgeTE9IjAuMCIgeDI9IjAuNSIgeTI9IjEuMCI+PHN0b3Agb2Zmc2V0PSIyMCUiIHN0b3AtY29sb3I9IiNmNGY0ZjQiLz48c3RvcCBvZmZzZXQ9IjUwJSIgc3RvcC1jb2xvcj0iI2YwZjBmMCIvPjxzdG9wIG9mZnNldD0iNTIlIiBzdG9wLWNvbG9yPSIjZThlOGU4Ii8+PHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjZWVlZWVlIi8+PC9saW5lYXJHcmFkaWVudD48L2RlZnM+PHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idXJsKCNncmFkKSIgLz48L3N2Zz4g'); + background-size: 100%; + background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eeeeee)); + background-image: -moz-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); + background-image: -webkit-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); + background-image: linear-gradient(to bottom, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); + color: #666; +} +.chosen-container-multi .chosen-choices li.search-choice-focus { + background: #d4d4d4; +} +.chosen-container-multi .chosen-choices li.search-choice-focus .search-choice-close { + background-position: -42px -10px; +} +.chosen-container-multi .chosen-results { + margin: 0; + padding: 0; +} +.chosen-container-multi .chosen-drop .result-selected { + display: list-item; + color: #ccc; + cursor: default; +} + +/* @end */ +/* @group Active */ +.chosen-container-active .chosen-single { + border: 2px solid #1292FF; + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); + transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s; +} +.chosen-container-active.chosen-with-drop .chosen-single div { + border-left: none; + background: transparent; +} +.chosen-container-active .chosen-choices { + border: 1px solid #5897fb; + box-shadow: 0 0 5px rgba(0, 0, 0, 0.3); +} +.chosen-container-active .chosen-choices li.search-field input[type="text"] { + color: #111 !important; +} + +/* @end */ +/* @group Disabled Support */ +.chosen-disabled { + opacity: 0.5 !important; + cursor: default; +} +.chosen-disabled .chosen-single { + cursor: default; +} +.chosen-disabled .chosen-choices .search-choice .search-choice-close { + cursor: default; +} + +/* chosen-drop top - start */ +.hotel-selector-wrap .chosen-container .chosen-drop.top .chosen-results { + position: absolute; + width: 100%; + bottom: calc(100% + 2px); +} +.hotel-selector-wrap .chosen-container.chosen-container-single-nosearch .chosen-drop.top .chosen-results { + position: absolute; + width: 100%; + bottom: calc(100% + 55px); +} +/* chosen-drop top - end */ + + +/* @end */ +/* @group Right to Left */ +.chosen-rtl { + text-align: right; +} +.chosen-rtl .chosen-single { + overflow: visible; + padding: 0 8px 0 0; +} +.chosen-rtl .chosen-single span { + margin-right: 0; + margin-left: 26px; + direction: rtl; +} +.chosen-rtl .chosen-single-with-deselect span { + margin-left: 38px; +} +.chosen-rtl .chosen-single div { + right: auto; + left: 3px; +} +.chosen-rtl .chosen-single abbr { + right: auto; + left: 26px; +} +.chosen-rtl .chosen-choices li { + float: right; +} +.chosen-rtl .chosen-choices li.search-field input[type="text"] { + direction: rtl; +} +.chosen-rtl .chosen-choices li.search-choice { + margin: 3px 5px 3px 0; + padding: 3px 5px 3px 19px; +} +.chosen-rtl .chosen-choices li.search-choice .search-choice-close { + right: auto; + left: 4px; +} +.chosen-rtl.chosen-container-single-nosearch .chosen-search, +.chosen-rtl .chosen-drop { + left: 9999px; +} +.chosen-rtl.chosen-container-single .chosen-results { + margin: 0 0 4px 4px; + padding: 0 4px 0 0; +} +.chosen-rtl .chosen-results li.group-option { + padding-right: 15px; + padding-left: 0; +} +.chosen-rtl.chosen-container-active.chosen-with-drop .chosen-single div { + border-right: none; +} +.chosen-rtl .chosen-search input[type="text"] { + padding: 4px 5px 4px 20px; + background: #fff url('chosen-sprite.png') no-repeat -30px -20px; + background: url('chosen-sprite.png') no-repeat -30px -20px, url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJvYmplY3RCb3VuZGluZ0JveCIgeDE9IjAuNSIgeTE9IjAuMCIgeDI9IjAuNSIgeTI9IjEuMCI+PHN0b3Agb2Zmc2V0PSIxJSIgc3RvcC1jb2xvcj0iI2VlZWVlZSIvPjxzdG9wIG9mZnNldD0iMTUlIiBzdG9wLWNvbG9yPSIjZmZmZmZmIi8+PC9saW5lYXJHcmFkaWVudD48L2RlZnM+PHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idXJsKCNncmFkKSIgLz48L3N2Zz4g'); + background: url('chosen-sprite.png') no-repeat -30px -20px, -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff)); + background: url('chosen-sprite.png') no-repeat -30px -20px, -moz-linear-gradient(#eeeeee 1%, #ffffff 15%); + background: url('chosen-sprite.png') no-repeat -30px -20px, -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%); + background: url('chosen-sprite.png') no-repeat -30px -20px, linear-gradient(#eeeeee 1%, #ffffff 15%); + direction: rtl; +} +.chosen-rtl.chosen-container-single .chosen-single div b { + background-position: 6px 2px; +} +.chosen-rtl.chosen-container-single.chosen-with-drop .chosen-single div b { + background-position: -12px 2px; +} + +.chosen-container .chosen-drop.dropup { + border-bottom: 0; + border-top: 1px solid #aaa; + top: auto; + bottom: 40px; +} + +.chosen-container.chosen-with-drop .chosen-single.dropup { + background-image: none; +} + +.chosen-container.chosen-with-drop .chosen-drop.dropup { + box-shadow: none; + margin-bottom: -16px; +} + +/* search results page - start */ +#category .chosen-container-single .chosen-single span { + min-height: 45px; + top: 11px; +} +/* search results page - end */ diff --git a/modules/wkroomsearchblock/views/css/wk-category-search.css b/modules/wkroomsearchblock/views/css/wk-category-search.css index fd3ce4f30..d5ee2fce4 100644 --- a/modules/wkroomsearchblock/views/css/wk-category-search.css +++ b/modules/wkroomsearchblock/views/css/wk-category-search.css @@ -48,6 +48,12 @@ height: unset; min-height: 45px; } + #search_hotel_block_form .hotel-selector-wrap .chosen-container-single .chosen-single { + min-height: 45px; + } + #search_hotel_block_form .hotel-selector-wrap .chosen-container-single .chosen-search { + height: 45px; + } /* #search_hotel_block_form #search_room_submit { height: 45px; } */ diff --git a/modules/wkroomsearchblock/views/css/wk-global-search.css b/modules/wkroomsearchblock/views/css/wk-global-search.css index d70fd2e11..89acdfa75 100644 --- a/modules/wkroomsearchblock/views/css/wk-global-search.css +++ b/modules/wkroomsearchblock/views/css/wk-global-search.css @@ -63,6 +63,9 @@ column-gap: 5px; grid-template-columns: repeat(2, 1fr); } +.fancybox-wrap #search_hotel_block_form .form-group.xs-calendar { + position: relative; +} /* #search_hotel_block_form { display: grid; grid-template-columns: 0.8fr repeat(3, 1fr) 0.6fr; @@ -100,6 +103,9 @@ #search_hotel_block_form .header-rmsearch-input:active, #search_hotel_block_form .header-rmsearch-input:focus { border: 2px solid #1292FF;} #search_hotel_block_form #id_hotel_button { + appearance: none; + width: 100%; + padding-left: 35px; background: url("../../views/img/icon-hotel.svg") no-repeat 10px 50%, url("../../views/img/icon-dropdown-arrow.svg") no-repeat calc(100% - 10px) 50%; background-color: #FFF;} #search_hotel_block_form #guest_occupancy { @@ -109,6 +115,8 @@ #search_hotel_block_form .input-date { display: grid; cursor: text;} + #search_hotel_block_form .input-date.focused { + border: 2px solid #1292FF; } #search_hotel_block_form .input-date span { align-self: center;} #search_hotel_block_form .input-date span i { @@ -117,14 +125,16 @@ color: #333;} .header-rmsearch-input:-moz-placeholder { /* Firefox 18- */ - color: #999999; - font-weight: 400;} + color: #333; + font-weight: 400; + opacity: 1;} .header-rmsearch-input::-moz-placeholder { /* Firefox 19+ */ - color: #999999; - font-weight: 400;} + color: #333; + font-weight: 400; + opacity: 1;} .header-rmsearch-input:-ms-input-placeholder { - color: #999999; + color: #333; font-weight: 400;} .search_block_container .dropdown-toggle { background-color: #f2f2f2; @@ -138,15 +148,6 @@ position: relative;} .header-rmsearch-wrapper .dropdown-menu { margin: 0px;} -.header-rmsearch-wrapper .hotel_dropdown_ul { - position: absolute; - font-size: 14px; - font-weight: 400; - padding: 0px; - width: 100%; - box-shadow: 0 8px 25px -4px rgba(0,0,0,0.39); - max-height: 145px; - overflow-y: auto;} .header-rmsearch-wrapper .location_search_results_ul { position: absolute; font-size: 14px; @@ -157,7 +158,7 @@ box-shadow: 0 8px 25px -4px rgba(0,0,0,0.39); max-height: 145px; overflow-y: auto;} - .header-rmsearch-wrapper .location_search_results_ul li, .header-rmsearch-wrapper .hotel_dropdown_ul li { + .header-rmsearch-wrapper .location_search_results_ul li { background-color: #fff; color: #333333; cursor: pointer; @@ -165,10 +166,16 @@ font-size: 14px; list-style: outside none none; padding: 15px;} - .header-rmsearch-wrapper .location_search_results_ul li:hover, .header-rmsearch-wrapper .location_search_results_ul li:focus, .header-rmsearch-wrapper .location_search_results_ul li:active, .header-rmsearch-wrapper .hotel_dropdown_ul li:hover, .header-rmsearch-wrapper .hotel_dropdown_ul li:focus, .header-rmsearch-wrapper .hotel_dropdown_ul li:active { + .header-rmsearch-wrapper .location_search_results_ul li:hover, .header-rmsearch-wrapper .location_search_results_ul li:focus, .header-rmsearch-wrapper .location_search_results_ul li:active { background-color: #379bf0; color: #FFFFFF;} +.header-rmsearch-wrapper .location_search_results_ul.top { + top: unset; + bottom: 55px; } +.header-rmsearch-wrapper .location_search_results_ul.bottom { + top: 100%; } + .header-rmsearch-wrapper .label-desc-txt { font-size: 12px; @@ -217,6 +224,11 @@ box-shadow: 0 8px 25px -4px rgba(0,0,0,0.39); left: 0px; padding: 20px;} + #search_occupancy_wrapper.top { + top: unset; + bottom: 100%; } + #search_occupancy_wrapper.bottom { + top: 100%; } #search_occupancy_wrapper .occupancy-info-separator { margin-bottom: 15px; margin-top: 15px; diff --git a/modules/wkroomsearchblock/views/img/chosen-sprite.png b/modules/wkroomsearchblock/views/img/chosen-sprite.png new file mode 100644 index 000000000..3611ae4ac Binary files /dev/null and b/modules/wkroomsearchblock/views/img/chosen-sprite.png differ diff --git a/modules/wkroomsearchblock/views/img/chosen-sprite@2x.png b/modules/wkroomsearchblock/views/img/chosen-sprite@2x.png new file mode 100644 index 000000000..ffe4d7d11 Binary files /dev/null and b/modules/wkroomsearchblock/views/img/chosen-sprite@2x.png differ diff --git a/modules/wkroomsearchblock/views/js/wk-room-search-block.js b/modules/wkroomsearchblock/views/js/wk-room-search-block.js index f5d180d16..f0c1d2dba 100644 --- a/modules/wkroomsearchblock/views/js/wk-room-search-block.js +++ b/modules/wkroomsearchblock/views/js/wk-room-search-block.js @@ -17,7 +17,327 @@ * @license https://store.webkul.com/license.html */ +const BookingSearchManager = { + inputSteps: { + 'location': { + init: function() { + $('.location_search_results_ul').hide(); + + // search location with users searched characters + $(document).on('keyup', '#hotel_location', function(e) { + BookingSearchManager.inputSteps['location'].onInput.call(this, e); + }); + + // set data on clicking the searched location on dropdown + $(document).on('click', '.location_search_results_ul li', function(e) { + e.preventDefault(); + + BookingSearchManager.inputSteps['location'].onInputComplete.call(this, e); + }); + + // handle Tab key press on hotel location field + $(document).on('keydown', '#hotel_location', function (e) { + if (e.which == 9) { // Tab key + e.preventDefault(); + + if ($('.location_search_results_ul').is(':visible')) { + $('.location_search_results_ul li:first').focus().click(); + } else { + BookingSearchManager.activateStep('hotel'); + } + } + }); + + // handle Tab key press on hotel location list + $(document).on('keydown', '.location_search_results_ul li', function (e) { + if (e.which == 9) { // Tab key + e.preventDefault(); + $(this).click(); + } + }); + + // navigate to prev and next li in the location dropdown + $('body').on('keydown', '.location_search_results_ul li', function(e) { + if (e.which == 40 || e.which == 38) { + var ulElement = $(this).closest('ul'); + var ulLength = ulElement.find('li').length; + $(this).blur(); + ulElement.scrollTop($(this).index() * $(this).outerHeight()); + if (e.which == 40) { + if ($(this).index() != (ulLength - 1)) { + $(this).next('li.search_result_li').focus(); + } else { + ulElement.find('li:first').focus(); + } + } else if (e.which == 38) { + if ($(this).index()) { + $(this).prev('li.search_result_li').focus(); + } else { + ulElement.find('li:last').focus(); + } + } + } + }); + }, + activate: function() { + $('#hotel_location').focus(); + }, + inputHasValue: function () { + return ($('#hotel_location').val() != '') && ($('#location_category_id').val() != ''); + }, + onInput: function (e) { + if (e.which == 13) { + return; + } + + if (($('.location_search_results_ul').is(':visible')) && (e.which == 40 || e.which == 38)) { + $(this).blur(); + if (e.which == 40) { + $('.location_search_results_ul li:first').focus(); + } else if (e.which == 38) { + $('.location_search_results_ul li:last').focus(); + } + } else { + $('.location_search_results_ul').empty().hide(); + if ($(this).val() != '') { + abortRunningAjax(); + ajax_check_var = $.ajax({ + url: autocomplete_search_url, + data: { + to_search_data: $(this).val(), + }, + method: 'POST', + dataType: 'json', + success: function(result) { + if (result.status) { + $('.location_search_results_ul').html(result.data); + $('.location_search_results_ul').show(); + } + } + }); + } + } + }, + onInputComplete: function (e) { + e.preventDefault(); + + $('.location_search_results_ul').empty().hide(); + $('#hotel_location').attr('value', $(this).html()); + $('#location_category_id').val($(this).val()); + + // fetch hotels for selected location + $.ajax({ + url: autocomplete_search_url, + data: { + location_category_id: $('#location_category_id').val(), + }, + method: 'POST', + dataType: 'json', + success: function(result) { + if (result.status) { + $('#hotel_cat_id').val(''); + $('#id_hotel_button').html(result.html_hotel_options); + $('#id_hotel_button').trigger('chosen:updated'); + + if (search_auto_focus_next_field) { + BookingSearchManager.activateStep('hotel'); + } + } else { + alert(no_results_found_cond); + } + } + }); + }, + }, + 'hotel': { + init: function() { + $('select#id_hotel_button').chosen({ + search_contains: true, + disable_search: !hotel_name_has_search, + width: '100%', + }); + + $(document).on('change', '#id_hotel_button', function() { + if ($(this).find('option:selected').val().trim() != '') { + $('#id_hotel_button_chosen .chosen-search input').blur(); + BookingSearchManager.inputSteps['hotel'].onInputComplete.call(this); + } + }); + + // prevents calendar from closing on hotel selection + $(document).on('click', '#id_hotel_button_chosen li', function(e) { + e.stopPropagation(); + }); + + $(document).on('keydown', '#id_hotel_button_chosen.chosen-container-active', function (e) { + if (e.which == 9) { // Tab key + e.preventDefault(); + if ($('#daterange_value').length) { + $('#daterange_value').focus(); + $('#daterange_value').click(); + } + } + }); + + $(document).on('keydown', '#id_hotel_button_chosen .chosen-search input', function (e) { + if (e.which == 9 && $('#daterange_value').siblings('.date-picker-wrapper').is(':visible')) { // Tab key + e.preventDefault(); + $('#daterange_value').data('dateRangePicker').close(); + + if (is_occupancy_wise_search) { + BookingSearchManager.activateStep('occupancy'); + } else { + BookingSearchManager.activateStep('submit'); + } + } + }); + + // if chosen will not be initialized add placeholder to hotel select element as first option + if (!BookingSearchManager.isBrowserSupported()) { + $('select#id_hotel_button option').first().html(select_htl_txt); + } + + if (hotel_name_has_search) { + $('select#id_hotel_button').on('chosen:showing_dropdown', function() { + $(this).siblings('.chosen-container').find('.chosen-single').addClass('invisible') + }); + + $('select#id_hotel_button').on('chosen:hiding_dropdown', function() { + $(this).siblings('.chosen-container').find('.chosen-single').removeClass('invisible') + }); + } + }, + activate: function() { + $('#id_hotel_button').trigger('chosen:open'); + }, + inputHasValue: function () { + return ($('#id_hotel').val() != '') && ($('#hotel_cat_id').val() != ''); + }, + onInputComplete: function () { + $('#id_hotel_button_chosen .chosen-search input').blur(); + const selectedHotel = $(this).find('option:selected'); + + if ($(selectedHotel).val().trim() != '') { + const maxOrderDate = $(selectedHotel).attr('data-max_order_date'); + const preparationTime = $(selectedHotel).attr('data-preparation_time') + + createDateRangePicker(maxOrderDate, preparationTime, $('#check_in_time').val(), $('#check_out_time').val()); + + $('#max_order_date').val(maxOrderDate); + $('#preparation_time').val(preparationTime); + $('#id_hotel').val($(selectedHotel).attr('data-id-hotel')); + $('#hotel_cat_id').val($(selectedHotel).attr('data-hotel-cat-id')); + + if (search_auto_focus_next_field) { + setTimeout(function () { + if ($('#id_hotel_button').data('chosen') != undefined) { + $('#id_hotel_button').data('chosen').close_field(); + } + + BookingSearchManager.activateStep('date_range'); + }, 10); + } + } else { + $('#id_hotel').val(''); + $('#hotel_cat_id').val(''); + } + }, + }, + 'date_range': { + init: function() { + $(document).on('keydown', '#daterange_value', function (e) { + if (e.which == 9) { // Tab key + e.preventDefault(); + $('#daterange_value').removeClass('focused').blur(); + + if ($('#daterange_value').data('dateRangePicker') != undefined) { + $('#daterange_value').data('dateRangePicker').close(); + } + + if (is_occupancy_wise_search) { + BookingSearchManager.activateStep('occupancy'); + } else { + BookingSearchManager.activateStep('submit'); + } + } + }); + }, + activate: function() { + $('#daterange_value').data('dateRangePicker').open(); + }, + inputHasValue: function () { + return ($('#check_in_time').val() != '') && ($('#check_out_time').val() != ''); + }, + }, + 'occupancy': { + init: function() { + $(document).on('keydown', '#guest_occupancy', function (e) { + if (e.which == 9) { // Tab key + e.preventDefault(); + if ($('#search_occupancy_wrapper').css('display') != 'none') { + $('#guest_occupancy').click(); + } + + BookingSearchManager.activateStep('submit'); + } + }); + }, + activate: function() { + if ($('#search_occupancy_wrapper').css('display') == 'none') { + $('#guest_occupancy').click().focus(); + } + }, + inputHasValue: function () { + return false; + }, + }, + 'submit': { + activate: function() { + $('#search_room_submit').focus(); + }, + inputHasValue: function () { + return false; + }, + }, + }, + init: function () { + this.inputSteps['location'].init(); + this.inputSteps['hotel'].init(); + this.inputSteps['date_range'].init(); + if (is_occupancy_wise_search) { + this.inputSteps['occupancy'].init(); + } + }, + activateStep: function (step) { + if (step in this.inputSteps) { + this.inputSteps[step].activate(); + } + }, + allFieldsFilled: function () { + return this.inputSteps['hotel'].inputHasValue() + && this.inputSteps['date_range'].inputHasValue() + }, + isBrowserSupported: function() { // defined as it is from chosen to decide if chosen will be initialized + if (window.navigator.appName === "Microsoft Internet Explorer") { + return document.documentMode >= 8; + } + if (/iP(od|hone)/i.test(window.navigator.userAgent)) { + return false; + } + if (/Android/i.test(window.navigator.userAgent)) { + if (/Mobile/i.test(window.navigator.userAgent)) { + return false; + } + } + + return true; + }, +} + $(document).ready(function() { + // initialize booking search fields + BookingSearchManager.init(); + // for screen size changes for room search var window_width = $(window).width(); if (window_width > 767) { @@ -54,10 +374,8 @@ $(document).ready(function() { /*END*/ var ajax_check_var = ''; - $('.location_search_results_ul').hide(); - function createDateRangePicker(max_order_date, preparation_time, dateFrom, dateTo) - { + createDateRangePicker = function (max_order_date, preparation_time, dateFrom, dateTo) { let start_date = new Date(); if (preparation_time) { start_date.setDate(start_date.getDate() + parseInt(preparation_time)); @@ -111,18 +429,63 @@ $(document).ready(function() { } }, endDate: max_order_date, + }).on('datepicker-first-date-selected', function() { + calendarFirstDateSelected = true; }).on('datepicker-change', function(event,obj){ $('#check_in_time').val($.datepicker.formatDate('yy-mm-dd', obj.date1)); $('#check_out_time').val($.datepicker.formatDate('yy-mm-dd', obj.date2)); + focusNextOnCalendarClose = true; + calendarFirstDateSelected = false; + }).on('datepicker-open', function() { + $('#daterange_value').addClass('focused').focus(); + }).on('datepicker-close', function() { + $('#daterange_value').removeClass('focused').blur(); + }).on('datepicker-closed', function() { + if (search_auto_focus_next_field && focusNextOnCalendarClose) { + if (is_occupancy_wise_search) { + if ($('#check_in_time').val() != '' && $('#check_out_time').val() != '') { + BookingSearchManager.activateStep('occupancy'); + } + } else { + if (BookingSearchManager.allFieldsFilled()) { + BookingSearchManager.activateStep('submit'); + } + } + + focusNextOnCalendarClose = false; + } }); } else { $('#daterange_value').dateRangePicker({ startDate: $.datepicker.formatDate('dd-mm-yy', new Date()), startDate: start_date, endDate: max_order_date, + }).on('datepicker-first-date-selected', function() { + calendarFirstDateSelected = true; }).on('datepicker-change', function(event,obj){ $('#check_in_time').val($.datepicker.formatDate('yy-mm-dd', obj.date1)); $('#check_out_time').val($.datepicker.formatDate('yy-mm-dd', obj.date2)); + focusNextOnCalendarClose = true; + calendarFirstDateSelected = false; + }).on('datepicker-open', function() { + $('#daterange_value').addClass('focused').focus(); + }).on('datepicker-close', function() { + $('#daterange_value').removeClass('focused').blur(); + calendarFirstDateSelected = false; + }).on('datepicker-closed', function() { + if (search_auto_focus_next_field && focusNextOnCalendarClose) { + if (is_occupancy_wise_search) { + if ($('#check_in_time').val() != '' && $('#check_out_time').val() != '') { + BookingSearchManager.activateStep('occupancy'); + } + } else { + if (BookingSearchManager.allFieldsFilled()) { + BookingSearchManager.activateStep('submit'); + } + } + + focusNextOnCalendarClose = false; + } }); } @@ -132,151 +495,21 @@ $(document).ready(function() { $.datepicker.formatDate('dd-mm-yy', $.datepicker.parseDate('yy-mm-dd', dateTo)) ); } - } - function abortRunningAjax() { + abortRunningAjax = function () { if (ajax_check_var) { ajax_check_var.abort(); } } - // search location with users searched characters - $(document).on('keyup', "#hotel_location", function(e) { - if (($('.location_search_results_ul').is(':visible')) && (e.which == 40 || e.which == 38)) { - $(this).blur(); - if (e.which == 40) { - $(".location_search_results_ul li:first").focus(); - } else if (e.which == 38) { - $(".location_search_results_ul li:last").focus(); - } - } else { - $('.location_search_results_ul').empty().hide(); - if ($(this).val() != '') { - abortRunningAjax(); - ajax_check_var = $.ajax({ - url: autocomplete_search_url, - data: { - to_search_data: $(this).val(), - }, - method: 'POST', - dataType: 'json', - success: function(result) { - if (result.status == 'success') { - $('.location_search_results_ul').html(result.data); - $('.location_search_results_ul').show(); - } - } - }); - } - } - }); - - // if user clicks anywhere and location/hotel li is visible the select first li as selection - $('body').on('click', function(e) { - if ($('.location_search_results_ul').is(':visible') && e.target.className != "search_result_li" && e.target.id != "hotel_location") { - $('.location_search_results_ul .search_result_li:first').click(); - } - - if ($('.hotel_dropdown_ul').is(':visible') && e.target.className != "search_result_li" && e.target.id != "hotel_location") { - $('.hotel_dropdown_ul .search_result_li:first').click(); - } - }); - - // 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()); - $('#location_category_id').val($(this).val()); - - $('.location_search_results_ul').empty().hide(); - - $.ajax({ - url: autocomplete_search_url, - data: { - location_category_id: $('#location_category_id').val(), - }, - method: 'POST', - dataType: 'json', - success: function(result) { - if (result.status == 'success') { - $('#hotel_cat_id').val(''); - $('#hotel_cat_name').html('Select Hotel'); - $('.hotel_dropdown_ul').empty(); - $('.hotel_dropdown_ul').html(result.data); - } else { - alert(no_results_found_cond); - } - } - }); - }); - - // navigate to prev and next li in the location/hotel dropdown - $('body').on('keyup', 'li.search_result_li', function(e) { - if (e.which == 40 || e.which == 38) { - var ulElement = $(this).closest('ul'); - var ulLength = ulElement.find('li').length; - $(this).blur(); - ulElement.scrollTop($(this).index() * $(this).outerHeight()); - if (e.which == 40) { - if ($(this).index() != (ulLength - 1)) { - $(this).next('li.search_result_li').focus(); - } else { - ulElement.find("li:first").focus(); - } - } else if (e.which == 38) { - if ($(this).index()) { - $(this).prev('li.search_result_li').focus(); - } else { - ulElement.find("li:last").focus(); - } - } - } - }); - - // when focus goes from hotel button to li list of hotels - $(document).on('keyup', "#id_hotel_button", function(e) { - if ($('.hotel_dropdown_ul').is(':visible')) { - if ($('.hotel_dropdown_ul .search_result_li').length) { - $(".hotel_dropdown_ul li:first").focus(); - } - } - }); - - // if user is selecting the location by keydown / up key - $(document).on('keydown', 'body', function(e) { - if ((e.which == 40 || e.which == 38) && ($('.location_search_results_ul li.search_result_li').is(':visible') || $('.hotel_dropdown_ul li.search_result_li').is(':visible'))) { - return false; - } else if (e.which == 13 && e.target.className == 'search_result_li') { - e.target.click(); - } else if (e.which == 9 && $('.location_search_results_ul').is(':visible')) { - if ($('.location_search_results_ul .search_result_li').length) { - $('.location_search_results_ul li.search_result_li:first').click(); - } - } else if (e.which == 9 && $('.hotel_dropdown_ul').is(':visible')) { - if ($('.hotel_dropdown_ul .search_result_li').length) { - $('.hotel_dropdown_ul li.search_result_li:first').click(); - } - } - }); - - $(document).on('click', '.hotel_dropdown_ul li', function() { - let max_order_date = $(this).attr('data-max_order_date'); - let preparation_time = $(this).attr('data-preparation_time') - createDateRangePicker(max_order_date, preparation_time, $('#check_in_time').val(), $('#check_out_time').val()); - $("#max_order_date").val(max_order_date); - $('#preparation_time').val(preparation_time); - $('#id_hotel').val($(this).attr('data-id-hotel')); - $('#hotel_cat_id').val($(this).attr('data-hotel-cat-id')); - $('#hotel_cat_name').html($(this).html()); - }); - // If only one hotel then set max order date on date pickers var max_order_date = $('#max_order_date').val(); var preparation_time = $('#preparation_time').val(); createDateRangePicker(max_order_date, preparation_time, $('#check_in_time').val(), $('#check_out_time').val()); // validations on the submit of the search fields - $('#search_room_submit').on('click', function(e) { + $(document).on('click', '#search_room_submit', function() { var check_in_time = $("#check_in_time").val(); var check_out_time = $("#check_out_time").val(); var max_order_date = $("#max_order_date").val(); @@ -291,7 +524,7 @@ $(document).ready(function() { $("#hotel_location").addClass("error_border"); error = true; } - $("#id_hotel_button").addClass("error_border"); + $("#id_hotel_button_chosen").addClass("error_border"); $('#select_htl_error_p').text(hotel_name_cond); error = true; } @@ -333,9 +566,10 @@ $(document).ready(function() { else return true; }); + // Occupancy field dropdown // add occupancy info block - $('#search_occupancy_wrapper .add_new_occupancy_btn').on('click', function(e) { + $(document).on('click', '#search_occupancy_wrapper .add_new_occupancy_btn', function(e) { e.preventDefault(); var occupancy_block = ''; @@ -512,64 +746,167 @@ $(document).ready(function() { // toggle occupancy block $('#guest_occupancy').on('click', function(e) { e.stopPropagation(); + if ($('#daterange_value').siblings('.date-picker-wrapper').is(':visible')) { + $('#daterange_value').data('dateRangePicker').close(); + } $("#search_occupancy_wrapper").toggle(); }); - // close the occupancy block when clink anywhere in the body outside occupancy block + function validateOccupancies() { + let hasErrors = 0; + + let adults = $("#search_occupancy_wrapper").find(".num_adults").map(function(){return $(this).val();}).get(); + let children = $("#search_occupancy_wrapper").find(".num_children").map(function(){return $(this).val();}).get(); + let child_ages = $("#search_occupancy_wrapper").find(".guest_child_age").map(function(){return $(this).val();}).get(); + + // start validating above values + if (!adults.length || (adults.length != children.length)) { + hasErrors = 1; + showErrorMessage(invalid_occupancy_txt); + } else { + $("#search_occupancy_wrapper").find('.occupancy_count').removeClass('error_border'); + + // validate values of adults and children + adults.forEach(function (item, index) { + if (isNaN(item) || parseInt(item) < 1) { + hasErrors = 1; + $("#search_occupancy_wrapper .num_adults").eq(index).closest('.occupancy_count_block').find('.occupancy_count').addClass('error_border'); + } + if (isNaN(children[index])) { + hasErrors = 1; + $("#search_occupancy_wrapper .num_children").eq(index).closest('.occupancy_count_block').find('.occupancy_count').addClass('error_border'); + } + }); + + // validate values of selected child ages + $("#search_occupancy_wrapper").find('.guest_child_age').removeClass('error_border'); + child_ages.forEach(function (age, index) { + age = parseInt(age); + if (isNaN(age) || (age < 0) || (age >= parseInt(max_child_age))) { + hasErrors = 1; + $("#search_occupancy_wrapper .guest_child_age").eq(index).addClass('error_border'); + } + }); + } + + if (hasErrors == 0) { + $("#search_occupancy_wrapper").hide(); + $("#search_hotel_block_form #guest_occupancy").removeClass('error_border'); + } else { + $("#search_hotel_block_form #guest_occupancy").addClass('error_border'); + return false; + } + + return true; + } + + // Body Events - start + var focusNextOnCalendarClose = true; + var calendarFirstDateSelected = false; $('body').on('click', function(e) { - // @TODO better approach to be found + // if user clicks anywhere and location li is visible then close it + if ($('.location_search_results_ul').is(':visible') + && e.target.className != 'search_result_li' + && e.target.id != 'hotel_location' + ) { + $('.location_search_results_ul').hide(); + $('#hotel_location').attr('placeholder', hotel_location_txt); + } + + // check if user clicked outside calendar + if ($('#daterange_value').siblings('.date-picker-wrapper').is(':visible')) { + if (!$(e.target).closest('.form-group').find('.date-picker-wrapper').length) { + focusNextOnCalendarClose = false; + } + } + + // close the occupancy block when clink anywhere in the body outside occupancy block if ($('#search_occupancy_wrapper').length) { if ($('#search_occupancy_wrapper').css('display') !== 'none') { if (!($(e.target).closest("#search_occupancy_wrapper").length)) { - // Before closing the occupancy block validate the vaules inside - let hasErrors = 0; - - let adults = $("#search_occupancy_wrapper").find(".num_adults").map(function(){return $(this).val();}).get(); - let children = $("#search_occupancy_wrapper").find(".num_children").map(function(){return $(this).val();}).get(); - let child_ages = $("#search_occupancy_wrapper").find(".guest_child_age").map(function(){return $(this).val();}).get(); - - // start validating above values - if (!adults.length || (adults.length != children.length)) { - hasErrors = 1; - showErrorMessage(invalid_occupancy_txt); - } else { - $("#search_occupancy_wrapper").find('.occupancy_count').removeClass('error_border'); - - // validate values of adults and children - adults.forEach(function (item, index) { - if (isNaN(item) || parseInt(item) < 1) { - hasErrors = 1; - $("#search_occupancy_wrapper .num_adults").eq(index).closest('.occupancy_count_block').find('.occupancy_count').addClass('error_border'); - } - if (isNaN(children[index])) { - hasErrors = 1; - $("#search_occupancy_wrapper .num_children").eq(index).closest('.occupancy_count_block').find('.occupancy_count').addClass('error_border'); - } - }); - - // validate values of selected child ages - $("#search_occupancy_wrapper").find('.guest_child_age').removeClass('error_border'); - child_ages.forEach(function (age, index) { - age = parseInt(age); - if (isNaN(age) || (age < 0) || (age >= parseInt(max_child_age))) { - hasErrors = 1; - $("#search_occupancy_wrapper .guest_child_age").eq(index).addClass('error_border'); - } - }); - } - - if (hasErrors == 0) { - $("#search_occupancy_wrapper").hide(); - $("#search_hotel_block_form #guest_occupancy").removeClass('error_border'); - } else { - $("#search_hotel_block_form #guest_occupancy").addClass('error_border'); - return false; - } + // Before closing the occupancy block validate the values inside + return validateOccupancies(); } } } }); + + var isEnterKeyHeldOnLocation = false; + $('body').on('keydown', function(e) { + let preventDefault = false; + + // fix for: if user pressed Tab after selecting only first date + if (e.which == 9 + && $('#daterange_value').siblings('.date-picker-wrapper').is(':visible') + && calendarFirstDateSelected + ) { + preventDefault = true; + $('#daterange_value').data('dateRangePicker').close(); + + setTimeout(function () { + if (is_occupancy_wise_search) { + BookingSearchManager.activateStep('occupancy'); + } else { + BookingSearchManager.activateStep('submit'); + } + }, 10); + } + + // if user is selecting the location by Up, Down, Enter or Tab keys + if ((e.which == 40 || e.which == 38) && $('.location_search_results_ul li.search_result_li').is(':visible')) { + return false; + } else if (e.which == 13 && e.target.className == 'search_result_li') { + // select location only after held Enter key is unheld + preventDefault = true; + isEnterKeyHeldOnLocation = true; + } else if (e.which == 9 && $('.location_search_results_ul').is(':visible')) { + preventDefault = true; + $(e.target).click(); + } + + // check if submit button must be focused + if (e.which == 9 && $('#search_occupancy_wrapper:visible').length) { + preventDefault = true; + if (validateOccupancies()) { + BookingSearchManager.activateStep('submit'); + } + } + + if (preventDefault) { + e.preventDefault(); + } + }); + + // select location only after held Enter key is unheld + $('body').on('keyup', function(e) { + if ($(e.target).is('.location_search_results_ul li') + && isEnterKeyHeldOnLocation + && e.which == 13 + ) { + $(e.target).click(); + } + }); + // Body Events - end + + // set positions of popups when required + if (page_name == 'index') { + $('#hotel_location, #id_hotel_button, #guest_occupancy').focus(function () { + setBookingSearchPositions(); + }); + + // after chosen has been initialized + $('select#id_hotel_button').on('chosen:ready', function() { + $('#id_hotel_button_chosen .chosen-search input').focus(function () { + setBookingSearchPositions(); + }); + }); + + $('#daterange_value').click(function () { + setBookingSearchPositions(); + }); + } }); + // function to set occupancy infor in guest occupancy field(search form) function setGuestOccupancy() { @@ -601,4 +938,45 @@ function setGuestOccupancy() guestButtonVal += ', ' + parseInt(rooms) + ' ' + room_txt; } $('#guest_occupancy > span').text(guestButtonVal); -} \ No newline at end of file +} + +// position dropdowns +function setBookingSearchPositions() { + // calculate available spaces + let searchForm = $('#search_hotel_block_form'); + + let inputFieldsAndDropdowns = [ + { input: $('#hotel_location'), dropdown: $('.location_search_results_ul')}, + { input: $('.hotel-selector-wrap'), dropdown: $('#id_hotel_button_chosen .chosen-drop')}, + { input: $('#guest_occupancy'), dropdown: $('#search_occupancy_wrapper')}, + ]; + + let positionClass = 'bottom'; + if (!searchForm.closest('.fancybox-wrap').length) { + let searchFormHeight = searchForm.outerHeight(); + let spaceTop = searchForm.offset().top - $(window).scrollTop(); + let spaceBottom = $(window).height() - searchFormHeight - spaceTop; + + // calculate max height for dropdowns + let maxHeightNeeded = 0; + $(inputFieldsAndDropdowns).each(function (i, inputFieldAndDropdown) { + if (!inputFieldAndDropdown.input.length) return false; + + // find needed space height + let cssMaxHeight = parseInt(inputFieldAndDropdown.dropdown.css('max-height')); + if (Number.isInteger(cssMaxHeight)) { + maxHeightNeeded = Math.max(maxHeightNeeded, cssMaxHeight); + } + }); + + // determine position class + if (spaceBottom < maxHeightNeeded && spaceTop > spaceBottom) { + positionClass = 'top'; + } + } + + // position dropdowns + $(inputFieldsAndDropdowns).each(function (i, inputFieldAndDropdown) { + inputFieldAndDropdown.dropdown.removeClass('top bottom').addClass(positionClass); + }); +} diff --git a/modules/wkroomsearchblock/views/templates/front/hotel-options.tpl b/modules/wkroomsearchblock/views/templates/front/hotel-options.tpl new file mode 100644 index 000000000..b6dd9cd0d --- /dev/null +++ b/modules/wkroomsearchblock/views/templates/front/hotel-options.tpl @@ -0,0 +1,27 @@ +{** + * 2010-2024 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-2024 Webkul IN + * @license LICENSE.txt + *} + + +{if isset($hotels_info) && is_array($hotels_info)} + {foreach from=$hotels_info item=hotel_info} + + {/foreach} +{/if} diff --git a/modules/wkroomsearchblock/views/templates/front/index.php b/modules/wkroomsearchblock/views/templates/front/index.php new file mode 100644 index 000000000..089d93577 --- /dev/null +++ b/modules/wkroomsearchblock/views/templates/front/index.php @@ -0,0 +1,29 @@ +{$category.name} + {/foreach} +{/if} diff --git a/modules/wkroomsearchblock/views/templates/hook/searchForm.tpl b/modules/wkroomsearchblock/views/templates/hook/searchForm.tpl index 9629b5e69..1703b29bf 100644 --- a/modules/wkroomsearchblock/views/templates/hook/searchForm.tpl +++ b/modules/wkroomsearchblock/views/templates/hook/searchForm.tpl @@ -1,7 +1,7 @@
    {if isset($location_enabled) && $location_enabled}
    - +