From 3e49492af7abf257248c91c471dde45c2ce2fc03 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 12 Jan 2023 13:02:44 +0530 Subject: [PATCH 1/3] Fix ajax page not found issue on room type detail page --- themes/hotel-reservation-theme/js/product.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/hotel-reservation-theme/js/product.js b/themes/hotel-reservation-theme/js/product.js index fc5b6c5a7..9554e3d48 100644 --- a/themes/hotel-reservation-theme/js/product.js +++ b/themes/hotel-reservation-theme/js/product.js @@ -1237,8 +1237,8 @@ var BookingForm = { var data = { id_product: parseInt($('#product_page_product_id').val()), - date_from: $('#room_check_in').val(), - date_to: $('#room_check_out').val(), + date_from: $.datepicker.formatDate('yy-mm-dd', $.datepicker.parseDate('dd-mm-yy', $('#room_check_in').val())), + date_to: $.datepicker.formatDate('yy-mm-dd', $.datepicker.parseDate('dd-mm-yy', $('#room_check_out').val())), quantity: quantity, room_type_demands: JSON.stringify(getRoomsExtraDemands()), }; From 2ec01dbc4906e8cedfff8d261c13bcd6c6fa0665 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Wed, 18 Jan 2023 19:52:39 +0530 Subject: [PATCH 2/3] Accept all valid date formats --- controllers/front/CategoryController.php | 8 ++++++-- controllers/front/ProductController.php | 8 ++++++-- themes/hotel-reservation-theme/js/product.js | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/controllers/front/CategoryController.php b/controllers/front/CategoryController.php index 607257ac1..1c19b244c 100644 --- a/controllers/front/CategoryController.php +++ b/controllers/front/CategoryController.php @@ -99,11 +99,15 @@ class CategoryControllerCore extends FrontController $dateFrom = Tools::getValue('date_from'); $dateTo = Tools::getValue('date_to'); - if ($dateFrom != '' && !Validate::isDate($dateFrom)) { + $currentTimestamp = strtotime(date('Y-m-d')); + $dateFromTimestamp = strtotime($dateFrom); + $dateToTimestamp = strtotime($dateTo); + + if ($dateFrom != '' && (!$dateFromTimestamp || ($dateFromTimestamp < $currentTimestamp))) { Tools::redirect($this->context->link->getPageLink('pagenotfound')); } - if ($dateTo != '' && !Validate::isDate($dateTo)) { + if ($dateTo != '' && (!$dateToTimestamp || ($dateToTimestamp < $currentTimestamp))) { Tools::redirect($this->context->link->getPageLink('pagenotfound')); } diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index 997053ca9..70bb30678 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -92,11 +92,15 @@ class ProductControllerCore extends FrontController $dateFrom = Tools::getValue('date_from'); $dateTo = Tools::getValue('date_to'); - if ($dateFrom != '' && !Validate::isDate($dateFrom)) { + $currentTimestamp = strtotime(date('Y-m-d')); + $dateFromTimestamp = strtotime($dateFrom); + $dateToTimestamp = strtotime($dateTo); + + if ($dateFrom != '' && (!$dateFromTimestamp || ($dateFromTimestamp < $currentTimestamp))) { Tools::redirect($this->context->link->getPageLink('pagenotfound')); } - if ($dateTo != '' && !Validate::isDate($dateTo)) { + if ($dateTo != '' && (!$dateToTimestamp || ($dateToTimestamp < $currentTimestamp))) { Tools::redirect($this->context->link->getPageLink('pagenotfound')); } diff --git a/themes/hotel-reservation-theme/js/product.js b/themes/hotel-reservation-theme/js/product.js index 9554e3d48..fc5b6c5a7 100644 --- a/themes/hotel-reservation-theme/js/product.js +++ b/themes/hotel-reservation-theme/js/product.js @@ -1237,8 +1237,8 @@ var BookingForm = { var data = { id_product: parseInt($('#product_page_product_id').val()), - date_from: $.datepicker.formatDate('yy-mm-dd', $.datepicker.parseDate('dd-mm-yy', $('#room_check_in').val())), - date_to: $.datepicker.formatDate('yy-mm-dd', $.datepicker.parseDate('dd-mm-yy', $('#room_check_out').val())), + date_from: $('#room_check_in').val(), + date_to: $('#room_check_out').val(), quantity: quantity, room_type_demands: JSON.stringify(getRoomsExtraDemands()), }; From a548e1eeefc9335de842cc00c257a3250a84fdc6 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 19 Jan 2023 14:57:14 +0530 Subject: [PATCH 3/3] Code improvement --- controllers/front/CategoryController.php | 4 ++-- controllers/front/ProductController.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/controllers/front/CategoryController.php b/controllers/front/CategoryController.php index 1c19b244c..804639845 100644 --- a/controllers/front/CategoryController.php +++ b/controllers/front/CategoryController.php @@ -103,11 +103,11 @@ class CategoryControllerCore extends FrontController $dateFromTimestamp = strtotime($dateFrom); $dateToTimestamp = strtotime($dateTo); - if ($dateFrom != '' && (!$dateFromTimestamp || ($dateFromTimestamp < $currentTimestamp))) { + if ($dateFrom != '' && ($dateFromTimestamp === false || ($dateFromTimestamp < $currentTimestamp))) { Tools::redirect($this->context->link->getPageLink('pagenotfound')); } - if ($dateTo != '' && (!$dateToTimestamp || ($dateToTimestamp < $currentTimestamp))) { + if ($dateTo != '' && ($dateToTimestamp === false || ($dateToTimestamp < $currentTimestamp))) { Tools::redirect($this->context->link->getPageLink('pagenotfound')); } diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index 70bb30678..2548bf42f 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -96,11 +96,11 @@ class ProductControllerCore extends FrontController $dateFromTimestamp = strtotime($dateFrom); $dateToTimestamp = strtotime($dateTo); - if ($dateFrom != '' && (!$dateFromTimestamp || ($dateFromTimestamp < $currentTimestamp))) { + if ($dateFrom != '' && ($dateFromTimestamp === false || ($dateFromTimestamp < $currentTimestamp))) { Tools::redirect($this->context->link->getPageLink('pagenotfound')); } - if ($dateTo != '' && (!$dateToTimestamp || ($dateToTimestamp < $currentTimestamp))) { + if ($dateTo != '' && ($dateToTimestamp === false || ($dateToTimestamp < $currentTimestamp))) { Tools::redirect($this->context->link->getPageLink('pagenotfound')); }