From dc9eca6c1bccc3299bcd67516fd5f9879bf8ca23 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 26 Sep 2023 19:49:08 +0530 Subject: [PATCH 1/5] Allow hotel friendly url to be changed --- .../classes/HotelBranchInformation.php | 18 ++++++++-- .../admin/AdminAddHotelController.php | 33 +++++++++++++++++-- .../views/js/HotelReservationAdmin.js | 7 ++++ .../admin/add_hotel/helpers/form/form.tpl | 24 +++++++++++++- 4 files changed, 77 insertions(+), 5 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelBranchInformation.php b/modules/hotelreservationsystem/classes/HotelBranchInformation.php index 39e805901..17e516e4d 100644 --- a/modules/hotelreservationsystem/classes/HotelBranchInformation.php +++ b/modules/hotelreservationsystem/classes/HotelBranchInformation.php @@ -606,7 +606,7 @@ public function update($null_values = false) return $return; } - public function addCategory($name, $parent_cat = false, $group_ids, $ishotel = false, $idHotel = false) + public function addCategory($name, $parent_cat = false, $group_ids, $ishotel = false, $idHotel = false, $link_rewrite = false) { $context = Context::getContext(); if (!$parent_cat) { @@ -622,6 +622,15 @@ public function addCategory($name, $parent_cat = false, $group_ids, $ishotel = f $catName, $parent_cat )) { + if (is_array($link_rewrite)) { + $objCategory = new Category($categoryExists['id_category']); + + foreach (Language::getLanguages() as $lang) { + $objCategory->link_rewrite[$lang['id_lang']] = $link_rewrite[$lang['id_lang']]; + } + + $objCategory->save(); + } return $categoryExists['id_category']; } else { $category = new Category(); @@ -635,7 +644,12 @@ public function addCategory($name, $parent_cat = false, $group_ids, $ishotel = f $category->description[$lang['id_lang']] = $this->moduleInstance->l( 'Hotel Branch Category', 'HotelBranchInformation' ); - $category->link_rewrite[$lang['id_lang']] = Tools::link_rewrite($catName); + + if (is_array($link_rewrite)) { + $category->link_rewrite[$lang['id_lang']] = $link_rewrite[$lang['id_lang']]; + } else { + $category->link_rewrite[$lang['id_lang']] = Tools::link_rewrite($catName); + } } $category->id_parent = $parent_cat; $category->groupBox = $group_ids; diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index 278538193..a11b0291c 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -112,7 +112,7 @@ public function renderForm() $smartyVars['lang'] = true; $smartyVars['iso'] = $this->context->language->iso_code; //lang vars - $currentLangId = Configuration::get('PS_LANG_DEFAULT'); + $currentLangId = $this->default_form_language ? $this->default_form_language : Configuration::get('PS_LANG_DEFAULT'); $smartyVars['languages'] = Language::getLanguages(false); $smartyVars['currentLang'] = Language::getLanguage((int) $currentLangId); @@ -128,6 +128,7 @@ public function renderForm() if ($this->display == 'edit') { $idHotel = Tools::getValue('id'); $hotelBranchInfo = new HotelBranchInformation($idHotel); + $objCategory = new Category($hotelBranchInfo->id_category); $addressInfo = HotelBranchInformation::getAddress($idHotel); $idCountry = Tools::getValue('hotel_country', $addressInfo['id_country']); @@ -135,6 +136,7 @@ public function renderForm() $smartyVars['edit'] = 1; $smartyVars['address_info'] = $addressInfo; $smartyVars['hotel_info'] = (array) $hotelBranchInfo; + $smartyVars['link_rewrite_info'] = $objCategory->link_rewrite; //Hotel Images $objHotelImage = new HotelImage(); if ($hotelAllImages = $objHotelImage->getImagesByHotelId($idHotel)) { @@ -187,6 +189,7 @@ public function renderForm() Media::addJsDef( array( 'img_dir_l' => _PS_IMG_.'l/', + 'PS_ALLOW_ACCENTED_CHARS_URL' => (int) Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL'), ) ); $this->fields_form = array( @@ -253,6 +256,21 @@ public function processSave() } } } + + // validate Friendly URL values + if (!trim(Tools::getValue('link_rewrite_'.$defaultLangId))) { + $this->errors[] = $this->l('Friendly URL is required at least in '). + $objDefaultLanguage['name']; + } else { + foreach ($languages as $lang) { + if (trim(Tools::getValue('link_rewrite_'.$lang['id_lang']))) { + if (!Validate::isLinkRewrite(Tools::getValue('link_rewrite_'.$lang['id_lang']))) { + $this->errors[] = $this->l('Invalid Friendly URL in ').$lang['name']; + } + } + } + } + if (!$phone) { $this->errors[] = $this->l('Phone number is required field.'); } elseif (!Validate::isPhoneNumber($phone)) { @@ -357,6 +375,7 @@ public function processSave() // lang fields $hotelCatName = array(); + $linkRewiteArray = array(); foreach ($languages as $lang) { if (!trim(Tools::getValue('hotel_name_'.$lang['id_lang']))) { $objHotelBranch->hotel_name[$lang['id_lang']] = Tools::getValue( @@ -368,6 +387,16 @@ public function processSave() ); } + if (!trim(Tools::getValue('link_rewrite_'.$lang['id_lang']))) { + $linkRewiteArray[$lang['id_lang']] = Tools::getValue( + 'link_rewrite_'.$defaultLangId + ); + } else { + $linkRewiteArray[$lang['id_lang']] = Tools::getValue( + 'link_rewrite_'.$lang['id_lang'] + ); + } + $cleanShortDescription = Tools::getDescriptionClean( Tools::getValue('short_description_'.$lang['id_lang']) ); @@ -502,7 +531,7 @@ public function processSave() if ($catCity = $objHotelBranch->addCategory($city, $catState, $groupIds)) { $hotelCatName = $objHotelBranch->hotel_name; if ($catHotel = $objHotelBranch->addCategory( - $hotelCatName, $catCity, $groupIds, 1, $newIdHotel + $hotelCatName, $catCity, $groupIds, 1, $newIdHotel, $linkRewiteArray )) { $objHotelBranch = new HotelBranchInformation($newIdHotel); $objHotelBranch->id_category = $catHotel; diff --git a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js index 66a274406..4f0937a5b 100644 --- a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js +++ b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js @@ -767,6 +767,13 @@ function showLangField(select_lang_name, id_lang) $('.all_lang_icon').attr('src', img_dir_l+id_lang+'.jpg'); $('#choosedLangId').val(id_lang); + + var id_old_language = id_language; + id_language = id_lang; + + if (id_old_language != id_lang) { + changeEmployeeLanguage(); + } } /* ---- HotelConfigurationSettingController Admin ---- */ diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl index 212a25a0e..5940aa28b 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl @@ -112,9 +112,27 @@ {foreach from=$languages item=language} {assign var="hotel_name" value="hotel_name_`$language.id_lang`"} + {/foreach} + + +
+ +
+ {foreach from=$languages item=language} + {assign var="link_rewrite" value="link_rewrite_`$language.id_lang`"} + @@ -483,6 +501,10 @@ {block name=script}