From 8a7170261ce69d1db5839fa0f8a63097bcb6df07 Mon Sep 17 00:00:00 2001 From: aman-webkul Date: Tue, 21 May 2024 17:12:44 +0530 Subject: [PATCH 1/4] Add validations for Hotel address when add a new hotel --- .../admin/AdminAddHotelController.php | 67 ++++++++++++++++--- 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index 1d0e738b3..6faf66911 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -326,7 +326,39 @@ public function processSave() if ($city == '') { $this->errors[] = $this->l('City is required field.'); } elseif (!Validate::isCityName($city)) { - $this->errors[] = $this->l('Enter a Valid City Name.'); + $this->errors[] = $this->l('Enter a valid city name.'); + } + + //Since the address for the hotel is saved in the address table. We are validating the hotel address here manually. + $addressValidation = Address::getValidationRules('Address'); + foreach ($addressValidation['size'] as $field => $maxSize) { + if ('phone' == $field && Tools::strlen($phone) > $maxSize) { + $this->errors[] = sprintf( + Tools::displayError('The Hotel phone number is too long (%1$d chars max).'), + $maxSize + ); + } else if ('address1' == $field && Tools::strlen($address) > $maxSize) { + $this->errors[] = sprintf( + Tools::displayError('The Hotel address is too long (%1$d chars max).'), + $maxSize + ); + } else if ('city' == $field && Tools::strlen($city) > $maxSize) { + $this->errors[] = sprintf( + Tools::displayError('The Hotel city name is too long (%1$d chars max).'), + $maxSize + ); + } else if ('postcode' == $field && Tools::strlen($zipcode) > $maxSize) { + $this->errors[] = sprintf( + Tools::displayError('The Hotel zip code is too long (%1$d chars max).'), + $maxSize + ); + } else if (($value = Tools::getValue($field)) && Tools::strlen($value) > $maxSize) { + $this->errors[] = sprintf( + Tools::displayError('The Hotel %1$s field is too long (%2$d chars max).'), + $field, + $maxSize + ); + } } if ($idHotel) { @@ -378,13 +410,13 @@ public function processSave() $linkRewriteArray = array(); foreach ($languages as $lang) { if (!trim(Tools::getValue('hotel_name_'.$lang['id_lang']))) { - $objHotelBranch->hotel_name[$lang['id_lang']] = Tools::getValue( + $objHotelBranch->hotel_name[$lang['id_lang']] = trim(Tools::getValue( 'hotel_name_'.$defaultLangId - ); + )); } else { - $objHotelBranch->hotel_name[$lang['id_lang']] = Tools::getValue( + $objHotelBranch->hotel_name[$lang['id_lang']] = trim(Tools::getValue( 'hotel_name_'.$lang['id_lang'] - ); + )); } if (!trim(Tools::getValue('link_rewrite_'.$lang['id_lang']))) { @@ -469,23 +501,36 @@ public function processSave() } // getHotel address if ($idHotelAddress = $objHotelBranch->getHotelIdAddress()) { - $objAddress = new Address($idHotelAddress); + $objAddress = new Address($idHotelAddress); } else { $objAddress = new Address(); } + $objAddress->id_hotel = $newIdHotel; $objAddress->id_country = $country; $objAddress->id_state = $state; $objAddress->city = $city; $objAddress->postcode = $zipcode; $hotelName = $objHotelBranch->hotel_name[$defaultLangId]; - $objAddress->alias = $hotelName; - $hotelName = preg_replace('/[0-9!<>,;?=+()@#"°{}_$%:]*$/u', '', $hotelName); - $objAddress->lastname = $hotelName; - $objAddress->firstname = $hotelName; + $objAddress->alias = trim(substr($hotelName, 0, 32)); + $hotelName = trim(preg_replace('/[0-9!<>,;?=+()@#"°{}_$%:]*$/u', '', $hotelName)); + $addressFirstName = $hotelName; + $addressLastName = $hotelName; + // If hotel name is length is greater than 32 then we split it into two + if (Tools::strlen($hotelName) > 32) { + // Slicing and removing the extra spaces after slicing + $addressFirstName = trim(substr($hotelName, 0, 32)); + // To remove the excess space from last name + if (!$addressLastName = trim(substr($hotelName, 32, 32))) { + // since the last name can also be an empty space we will then use first name as last name + $addressLastName = $addressFirstName; + } + } + + $objAddress->firstname = $addressFirstName; + $objAddress->lastname = $addressLastName; $objAddress->address1 = $address; $objAddress->phone = $phone; - $objAddress->save(); // Save refund rules of the hotels From ba50168ac31664064539395d0ab5078ef4841111 Mon Sep 17 00:00:00 2001 From: Aman deep sharma Date: Mon, 29 Jul 2024 20:01:58 +0530 Subject: [PATCH 2/4] [Fixed]: Link rewrite not updating while hotel update --- .../controllers/admin/AdminAddHotelController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index 7a33dfc93..684cbdf91 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -582,6 +582,7 @@ public function processSave() if ($objHotelBranch->id_category) { $objCategory = new Category($objHotelBranch->id_category); $objCategory->name = $objHotelBranch->hotel_name; + $objCategory->link_rewrite = $linkRewriteArray; $objCategory->id_parent = $catCity; $objCategory->save(); Category::regenerateEntireNtree(); From 22f533040c8d74b22a5d721f5c35babd51d2c33a Mon Sep 17 00:00:00 2001 From: Aman deep sharma Date: Tue, 6 Aug 2024 15:10:16 +0530 Subject: [PATCH 3/4] [Fixed]: Empty address and phone number gets saved --- .../controllers/admin/AdminAddHotelController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index 684cbdf91..b40b651e3 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -274,7 +274,7 @@ public function processSave() } } - if (!$phone) { + if (!$phone = trim($phone)) { $this->errors[] = $this->l('Phone number is required field.'); } elseif (!Validate::isPhoneNumber($phone)) { $this->errors[] = $this->l('Please enter a valid phone number.'); @@ -300,7 +300,7 @@ public function processSave() $this->errors[] = $this->l('Rating is required field.'); } - if ($address == '') { + if (!$address = trim($address)) { $this->errors[] = $this->l('Address is required field.'); } From 36eba364bd1924d5ffa4575d719ac99b9d748935 Mon Sep 17 00:00:00 2001 From: Aman deep sharma Date: Tue, 13 Aug 2024 13:17:25 +0530 Subject: [PATCH 4/4] [Fixed]: Wrong alias gets saved --- .../controllers/admin/AdminAddHotelController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index b40b651e3..ded152095 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -515,8 +515,8 @@ public function processSave() $objAddress->city = $city; $objAddress->postcode = $zipcode; $hotelName = $objHotelBranch->hotel_name[$defaultLangId]; - $objAddress->alias = trim(substr($hotelName, 0, 32)); $hotelName = trim(preg_replace('/[0-9!<>,;?=+()@#"°{}_$%:]*$/u', '', $hotelName)); + $objAddress->alias = trim(substr($hotelName, 0, 32)); $addressFirstName = $hotelName; $addressLastName = $hotelName; // If hotel name is length is greater than 32 then we split it into two