Merge pull request #1036 from vishal-singh-webkul/gli-2057

Fixed: The redirection to page not found controller when the user inserts invalid date range in the URL in the category and product page.
This commit is contained in:
Rohit Jain
2024-07-11 16:53:26 +05:30
committed by GitHub
3 changed files with 29 additions and 24 deletions

View File

@@ -101,16 +101,8 @@ class CategoryControllerCore extends FrontController
// validate dates if available
$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))) {
$idHotel = HotelBranchInformation::getHotelIdByIdCategory($id_category);
if (!HotelHelper::validateDateRangeForHotel($dateFrom, $dateTo, $idHotel)) {
Tools::redirect($this->context->link->getPageLink('pagenotfound'));
}

View File

@@ -109,26 +109,18 @@ class ProductControllerCore extends FrontController
// validate dates if available
$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'));
}
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'));
}

View File

@@ -931,4 +931,25 @@ class HotelHelper
return $daysDifference;
}
public static function validateDateRangeForHotel($dateFrom, $dateTo, $idHotel)
{
$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 < $validStartDateTimeStamp))) {
$isValid = false;
} else if ($dateTo != '' && ($dateToTimestamp === false || ($dateToTimestamp < $validStartDateTimeStamp))) {
$isValid = false;
} else if ($dateTo != '' && $dateFrom != '' && $dateFromTimestamp >= $dateToTimestamp) {
$isValid = false;
}
return $isValid;
}
}