Skip to content

Commit

Permalink
Accept all valid date formats
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek-webkul committed Jan 18, 2023
1 parent 3e49492 commit 2ec01db
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 6 additions & 2 deletions controllers/front/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,15 @@ public function init()
$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'));
}

Expand Down
8 changes: 6 additions & 2 deletions controllers/front/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ public function init()
$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'));
}

Expand Down
4 changes: 2 additions & 2 deletions themes/hotel-reservation-theme/js/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
};
Expand Down

0 comments on commit 2ec01db

Please sign in to comment.