From ba921726b6694a3840abaef2b3b41b41f49c448a Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 14 May 2024 19:41:31 +0530 Subject: [PATCH 1/3] Updated: The user will now be redirected to page not found incase there is direct manupulation of the dates in the url in category page and product page and the dates are invalid --- controllers/front/CategoryController.php | 4 ++++ controllers/front/ProductController.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/controllers/front/CategoryController.php b/controllers/front/CategoryController.php index 3823504ab..b60c6f101 100644 --- a/controllers/front/CategoryController.php +++ b/controllers/front/CategoryController.php @@ -114,6 +114,10 @@ class CategoryControllerCore extends FrontController Tools::redirect($this->context->link->getPageLink('pagenotfound')); } + if ($dateTo != '' && $dateFrom != '' && $dateFromTimestamp >= $dateToTimestamp) { + Tools::redirect($this->context->link->getPageLink('pagenotfound')); + } + // Instantiate category $this->category = new Category($id_category, $this->context->language->id); diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index ec77ebd09..237a85cac 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -122,6 +122,10 @@ class ProductControllerCore extends FrontController Tools::redirect($this->context->link->getPageLink('pagenotfound')); } + if ($dateTo != '' && $dateFrom != '' && $dateFromTimestamp >= $dateToTimestamp) { + Tools::redirect($this->context->link->getPageLink('pagenotfound')); + } + parent::init(); if ($id_product = (int) Tools::getValue('id_product')) { From 8407a4ba5191582246c65e5a6613ca7e547b1855 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Wed, 22 May 2024 13:29:59 +0530 Subject: [PATCH 2/3] Updated: The searched date valdiation process for the category and product controller in the front --- controllers/front/CategoryController.php | 14 +------------- controllers/front/ProductController.php | 14 +------------- .../classes/HotelHelper.php | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/controllers/front/CategoryController.php b/controllers/front/CategoryController.php index b60c6f101..8d3eac6a5 100644 --- a/controllers/front/CategoryController.php +++ b/controllers/front/CategoryController.php @@ -102,19 +102,7 @@ class CategoryControllerCore extends FrontController $dateFrom = Tools::getValue('date_from'); $dateTo = Tools::getValue('date_to'); - $currentTimestamp = strtotime(date('Y-m-d')); - $dateFromTimestamp = strtotime($dateFrom); - $dateToTimestamp = strtotime($dateTo); - - if ($dateFrom != '' && ($dateFromTimestamp === false || ($dateFromTimestamp < $currentTimestamp))) { - Tools::redirect($this->context->link->getPageLink('pagenotfound')); - } - - if ($dateTo != '' && ($dateToTimestamp === false || ($dateToTimestamp < $currentTimestamp))) { - Tools::redirect($this->context->link->getPageLink('pagenotfound')); - } - - if ($dateTo != '' && $dateFrom != '' && $dateFromTimestamp >= $dateToTimestamp) { + if (!HotelHelper::validateDateRange($dateFrom, $dateTo)) { Tools::redirect($this->context->link->getPageLink('pagenotfound')); } diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index 237a85cac..3a458e656 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -110,19 +110,7 @@ class ProductControllerCore extends FrontController $dateFrom = Tools::getValue('date_from'); $dateTo = Tools::getValue('date_to'); - $currentTimestamp = strtotime(date('Y-m-d')); - $dateFromTimestamp = strtotime($dateFrom); - $dateToTimestamp = strtotime($dateTo); - - if ($dateFrom != '' && ($dateFromTimestamp === false || ($dateFromTimestamp < $currentTimestamp))) { - Tools::redirect($this->context->link->getPageLink('pagenotfound')); - } - - if ($dateTo != '' && ($dateToTimestamp === false || ($dateToTimestamp < $currentTimestamp))) { - Tools::redirect($this->context->link->getPageLink('pagenotfound')); - } - - if ($dateTo != '' && $dateFrom != '' && $dateFromTimestamp >= $dateToTimestamp) { + if (!HotelHelper::validateDateRange($dateFrom, $dateTo)) { Tools::redirect($this->context->link->getPageLink('pagenotfound')); } diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php index 8aee39b6f..3f8c647e7 100644 --- a/modules/hotelreservationsystem/classes/HotelHelper.php +++ b/modules/hotelreservationsystem/classes/HotelHelper.php @@ -929,4 +929,21 @@ class HotelHelper return $daysDifference; } + + public static function validateDateRange($dateFrom, $dateTo) + { + $currentTimestamp = strtotime(date('Y-m-d')); + $dateFromTimestamp = strtotime($dateFrom); + $dateToTimestamp = strtotime($dateTo); + $isValid = true; + if ($dateFrom != '' && ($dateFromTimestamp === false || ($dateFromTimestamp < $currentTimestamp))) { + $isValid = false; + } else if ($dateTo != '' && ($dateToTimestamp === false || ($dateToTimestamp < $currentTimestamp))) { + $isValid = false; + } else if ($dateTo != '' && $dateFrom != '' && $dateFromTimestamp >= $dateToTimestamp) { + $isValid = false; + } + + return $isValid; + } } From 5ab9f4318e070b708d0835eb746226c74c51fcb4 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Thu, 27 Jun 2024 11:38:12 +0530 Subject: [PATCH 3/3] Added: Prepration time validation for dates selcted for hotel search and for the room type page --- controllers/front/CategoryController.php | 4 ++-- controllers/front/ProductController.php | 12 ++++++------ .../hotelreservationsystem/classes/HotelHelper.php | 12 ++++++++---- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/controllers/front/CategoryController.php b/controllers/front/CategoryController.php index 509a9e6c0..c96a8632d 100644 --- a/controllers/front/CategoryController.php +++ b/controllers/front/CategoryController.php @@ -101,8 +101,8 @@ class CategoryControllerCore extends FrontController // validate dates if available $dateFrom = Tools::getValue('date_from'); $dateTo = Tools::getValue('date_to'); - - if (!HotelHelper::validateDateRange($dateFrom, $dateTo)) { + $idHotel = HotelBranchInformation::getHotelIdByIdCategory($id_category); + if (!HotelHelper::validateDateRangeForHotel($dateFrom, $dateTo, $idHotel)) { Tools::redirect($this->context->link->getPageLink('pagenotfound')); } diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index f8aef8c77..177fd5004 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -109,18 +109,18 @@ class ProductControllerCore extends FrontController // validate dates if available $dateFrom = Tools::getValue('date_from'); $dateTo = Tools::getValue('date_to'); - - if (!HotelHelper::validateDateRange($dateFrom, $dateTo)) { - Tools::redirect($this->context->link->getPageLink('pagenotfound')); - } - parent::init(); if ($id_product = (int) Tools::getValue('id_product')) { $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id); } - if (!$this->product->booking_product || ($this->product->booking_product && !$this->product->show_at_front)) { + $objHotelRoomType = new HotelRoomType(); + $hotelRoomInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($this->product->id); + $idHotel = (int) $hotelRoomInfo['id_hotel']; + if (!HotelHelper::validateDateRangeForHotel($dateFrom, $dateTo, $idHotel)) { + Tools::redirect($this->context->link->getPageLink('pagenotfound')); + } else if (!$this->product->booking_product || ($this->product->booking_product && !$this->product->show_at_front)) { Tools::redirect($this->context->link->getPageLink('pagenotfound')); } diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php index 544a8fb7a..e4d78f7f8 100644 --- a/modules/hotelreservationsystem/classes/HotelHelper.php +++ b/modules/hotelreservationsystem/classes/HotelHelper.php @@ -932,15 +932,19 @@ class HotelHelper return $daysDifference; } - public static function validateDateRange($dateFrom, $dateTo) + public static function validateDateRangeForHotel($dateFrom, $dateTo, $idHotel) { - $currentTimestamp = strtotime(date('Y-m-d')); + $validStartDateTimeStamp = strtotime(date('Y-m-d')); + if ($preparationTime = (int) HotelOrderRestrictDate::getPreparationTime($idHotel)) { + $validStartDateTimeStamp = strtotime(date('Y-m-d', strtotime('+ '.$preparationTime.' day'))); + } + $dateFromTimestamp = strtotime($dateFrom); $dateToTimestamp = strtotime($dateTo); $isValid = true; - if ($dateFrom != '' && ($dateFromTimestamp === false || ($dateFromTimestamp < $currentTimestamp))) { + if ($dateFrom != '' && ($dateFromTimestamp === false || ($dateFromTimestamp < $validStartDateTimeStamp))) { $isValid = false; - } else if ($dateTo != '' && ($dateToTimestamp === false || ($dateToTimestamp < $currentTimestamp))) { + } else if ($dateTo != '' && ($dateToTimestamp === false || ($dateToTimestamp < $validStartDateTimeStamp))) { $isValid = false; } else if ($dateTo != '' && $dateFrom != '' && $dateFromTimestamp >= $dateToTimestamp) { $isValid = false;