Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: Friendly URL for search results page can not be changed #843

Merged
merged 8 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions modules/hotelreservationsystem/classes/HotelBranchInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,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) {
Expand All @@ -669,6 +669,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();
Expand All @@ -682,7 +691,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public function renderForm()
$smartyVars['lang'] = true;
$smartyVars['iso'] = $this->context->language->iso_code;
//lang vars

$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);
Expand All @@ -129,13 +128,15 @@ 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']);

$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)) {
Expand Down Expand Up @@ -188,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(
Expand Down Expand Up @@ -254,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)) {
Expand Down Expand Up @@ -358,6 +375,7 @@ public function processSave()

// lang fields
$hotelCatName = array();
$linkRewriteArray = array();
foreach ($languages as $lang) {
if (!trim(Tools::getValue('hotel_name_'.$lang['id_lang']))) {
$objHotelBranch->hotel_name[$lang['id_lang']] = Tools::getValue(
Expand All @@ -369,6 +387,16 @@ public function processSave()
);
}

if (!trim(Tools::getValue('link_rewrite_'.$lang['id_lang']))) {
$linkRewriteArray[$lang['id_lang']] = Tools::getValue(
'link_rewrite_'.$defaultLangId
);
} else {
$linkRewriteArray[$lang['id_lang']] = Tools::getValue(
'link_rewrite_'.$lang['id_lang']
);
}

$cleanShortDescription = Tools::getDescriptionClean(
Tools::getValue('short_description_'.$lang['id_lang'])
);
Expand Down Expand Up @@ -502,15 +530,14 @@ public function processSave()
if ($catState) {
if ($catCity = $objHotelBranch->addCategory($city, $catState, $groupIds)) {
$hotelCatName = $objHotelBranch->hotel_name;

// add/update hotel category
if ($objHotelBranch->id_category) {
$objCategory = new Category($objHotelBranch->id_category);
$objCategory->name = $objHotelBranch->hotel_name;
$objCategory->save();
} else {
if ($catHotel = $objHotelBranch->addCategory(
$hotelCatName, $catCity, $groupIds, 1, $newIdHotel
$hotelCatName, $catCity, $groupIds, 1, $newIdHotel, $linkRewriteArray
)) {
$objHotelBranch = new HotelBranchInformation($newIdHotel);
$objHotelBranch->id_category = $catHotel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,35 @@
{foreach from=$languages item=language}
{assign var="hotel_name" value="hotel_name_`$language.id_lang`"}
<input type="text"
id="hotel_name_{$language.id_lang}"
id="name_{$language.id_lang}"
name="hotel_name_{$language.id_lang}"
value="{if isset($smarty.post.$hotel_name)}{$smarty.post.$hotel_name|escape:'htmlall':'UTF-8'}{elseif isset($edit)}{$hotel_info.hotel_name[{$language.id_lang}]|escape:'htmlall':'UTF-8'}{/if}"
class="form-control wk_text_field_all wk_text_field_{$language.id_lang} copy2friendlyUrl"
maxlength="128"
{if $currentLang.id_lang != $language.id_lang}style="display:none;"{/if} />
{/foreach}
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label required" for="link_rewrite" >
{l s='Friendly URL :' mod='hotelreservationsystem'}
{include file="../../../_partials/htl-form-fields-flag.tpl"}
</label>
<div class="col-lg-6">
{foreach from=$languages item=language}
{assign var="link_rewrite" value="link_rewrite_`$language.id_lang`"}
<input type="text"
id="link_rewrite_{$language.id_lang}"
name="link_rewrite_{$language.id_lang}"
value="{if isset($smarty.post.$link_rewrite)}{$smarty.post.$link_rewrite|escape:'htmlall':'UTF-8'}{elseif isset($edit)}{$link_rewrite_info[{$language.id_lang}]|escape:'htmlall':'UTF-8'}{/if}"
class="form-control wk_text_field_all wk_text_field_{$language.id_lang}"
maxlength="128"
{if $currentLang.id_lang != $language.id_lang}style="display:none;"{/if} />
{/foreach}
</div>
<div class="col-lg-2">
<button type="button" class="btn btn-default" onmousedown="updateFriendlyURLByName();"><i class="icon-random"></i> {l s='Generate'}</button>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">
Expand Down Expand Up @@ -507,6 +528,7 @@
<script type="text/javascript">
var id_language = {$defaultFormLanguage|intval};
allowEmployeeFormLang = {$allowEmployeeFormLang|intval};
var ps_force_friendly_product = false;

// for tiny mce setup
var iso = "{$iso|escape:'htmlall':'UTF-8'}";
Expand Down