added constant in the configruation for the max char of short description, fixed validation messages for the admin add hotel

This commit is contained in:
vishalsingh.qlo325
2025-05-10 19:01:44 +05:30
parent 59082e4ec7
commit 2ba202b343
8 changed files with 58 additions and 55 deletions

View File

@@ -446,11 +446,11 @@
</label>
<div class="col-lg-9">
{include
file="controllers/products/textarea_lang.tpl"
file="controllers/normal_products/textarea_lang.tpl"
languages=$languages
input_name='description_short'
input_value=$product->description_short
max=$PS_SHORT_DESC_LIMIT}
maxlength=$PS_SHORT_DESC_LIMIT}
</div>
</div>
{* <div class="form-group">

View File

@@ -43,6 +43,8 @@ class ConfigurationCore extends ObjectModel
/** @var string Object last modification date */
public $date_upd;
const PS_SHORT_DESC_LIMIT = 400;
/**
* @see ObjectModel::$definition
*/

View File

@@ -947,12 +947,10 @@ class ProductCore extends ObjectModel
if ($field == 'description_short') {
$limit = (int)Configuration::get('PS_SHORT_DESC_LIMIT');
if ($limit <= 0) {
$limit = 800;
$limit = Configuration::PS_SHORT_DESC_LIMIT;
}
$size_without_html = Tools::strlen(strip_tags($value));
$size_with_html = Tools::strlen($value);
$this->def['fields']['description_short']['size'] = $limit + $size_with_html - $size_without_html;
$this->def['fields']['description_short']['size'] = $limit;
}
return parent::validateField($field, $value, $id_lang, $skip, $human_errors);
}

View File

@@ -657,7 +657,7 @@ class AdminNormalProductsControllerCore extends AdminController
}
$limit = (int)Configuration::get('PS_SHORT_DESC_LIMIT');
if ($limit <= 0) {
$limit = 400;
$limit = Configuration::PS_SHORT_DESC_LIMIT;
}
$className = 'Product';
foreach (Language::getLanguages(true) as $language) {
@@ -2180,7 +2180,7 @@ class AdminNormalProductsControllerCore extends AdminController
// Check description short size without html
$limit = (int)Configuration::get('PS_SHORT_DESC_LIMIT');
if ($limit <= 0) {
$limit = 400;
$limit = Configuration::PS_SHORT_DESC_LIMIT;
}
foreach ($languages as $language) {
if ($this->isProductFieldUpdated('description_short', $language['id_lang']) && ($value = Tools::getValue('description_short_'.$language['id_lang']))) {
@@ -3545,7 +3545,7 @@ class AdminNormalProductsControllerCore extends AdminController
'token' => $this->token,
'currency' => $currency,
'link' => $this->context->link,
'PS_SHORT_DESC_LIMIT' => Configuration::get('PS_SHORT_DESC_LIMIT') ? Configuration::get('PS_SHORT_DESC_LIMIT') : 400
'PS_SHORT_DESC_LIMIT' => Configuration::get('PS_SHORT_DESC_LIMIT') ? Configuration::get('PS_SHORT_DESC_LIMIT') : Configuration::PS_SHORT_DESC_LIMIT
));
$data->assign($this->tpl_form_vars);

View File

@@ -193,7 +193,7 @@ class AdminPreferencesControllerCore extends AdminController
'type' => 'text',
'suffix' => $this->l('characters'),
'class' => 'fixed-width-xl',
'desc' => $this->l('If set to 0, the maximum limit will be 400 characters.')
'desc' => sprintf($this->l('If set to 0, the maximum limit will be %d characters.'), Configuration::PS_SHORT_DESC_LIMIT)
),
// 'PS_DISPLAY_SUPPLIERS' => array(
// 'title' => $this->l('Display suppliers and manufacturers'),

View File

@@ -815,7 +815,7 @@ class AdminProductsControllerCore extends AdminController
$room_type_info = $obj_hotel_room_type->getRoomTypeInfoByIdProduct($id_product_old);
$limit = (int)Configuration::get('PS_SHORT_DESC_LIMIT');
if ($limit <= 0) {
$limit = 400;
$limit = Configuration::PS_SHORT_DESC_LIMIT;
}
$className = 'Product';
if ($room_type_info && $room_type_info['id_hotel'] == $id_hotel_new) {
@@ -2190,7 +2190,7 @@ class AdminProductsControllerCore extends AdminController
// Check description short size without html
$limit = (int)Configuration::get('PS_SHORT_DESC_LIMIT');
if ($limit <= 0) {
$limit = 400;
$limit = Configuration::PS_SHORT_DESC_LIMIT;
}
foreach ($languages as $language) {
if ($this->isProductFieldUpdated('description_short', $language['id_lang']) && ($value = Tools::getValue('description_short_'.$language['id_lang']))) {
@@ -4387,7 +4387,7 @@ class AdminProductsControllerCore extends AdminController
'token' => $this->token,
'currency' => $currency,
'link' => $this->context->link,
'PS_SHORT_DESC_LIMIT' => Configuration::get('PS_SHORT_DESC_LIMIT') ? Configuration::get('PS_SHORT_DESC_LIMIT') : 400,
'PS_SHORT_DESC_LIMIT' => Configuration::get('PS_SHORT_DESC_LIMIT') ? Configuration::get('PS_SHORT_DESC_LIMIT') : Configuration::PS_SHORT_DESC_LIMIT,
'category_position' => Tools::getValue('category_position', $product->getPositionInCategory()),
));
$data->assign($this->tpl_form_vars);

View File

@@ -1194,12 +1194,10 @@ class HotelBranchInformation extends ObjectModel
if ($field == 'short_description') {
$limit = (int)Configuration::get('PS_SHORT_DESC_LIMIT');
if ($limit <= 0) {
$limit = 400;
$limit = Configuration::PS_SHORT_DESC_LIMIT;
}
$size_without_html = Tools::strlen(strip_tags($value));
$size_with_html = Tools::strlen($value);
$this->def['fields']['short_description']['size'] = $limit + $size_with_html - $size_without_html;
$this->def['fields']['short_description']['size'] = $limit;
}
return parent::validateField($field, $value, $id_lang, $skip, $human_errors);

View File

@@ -124,6 +124,9 @@ class AdminAddHotelController extends ModuleAdminController
$smartyVars['defaultCurrency'] = Configuration::get('PS_CURRENCY_DEFAULT');
$smartyVars['PS_SHORT_DESC_LIMIT'] = Configuration::get('PS_SHORT_DESC_LIMIT');
if (!$smartyVars['PS_SHORT_DESC_LIMIT']) {
$smartyVars['PS_SHORT_DESC_LIMIT'] = Configuration::PS_SHORT_DESC_LIMIT;
}
$countries = Country::getCountries($this->context->language->id, true);
$smartyVars['country_var'] = $countries;
@@ -265,7 +268,7 @@ class AdminAddHotelController extends ModuleAdminController
$map_formated_address = Tools::getValue('locformatedAddr');
$map_input_text = Tools::getValue('googleInputField');
$hotelFeatures = Tools::getValue('id_features', array());
$shortDescriptionMaxChar = Configuration::get('PS_SHORT_DESC_LIMIT') ? Configuration::get('PS_SHORT_DESC_LIMIT') : 400;
$shortDescriptionMaxChar = Configuration::get('PS_SHORT_DESC_LIMIT') ? Configuration::get('PS_SHORT_DESC_LIMIT') : Configuration::PS_SHORT_DESC_LIMIT;
// check if field is atleast in default language. Not available in default prestashop
$defaultLangId = Configuration::get('PS_LANG_DEFAULT');
@@ -282,51 +285,53 @@ class AdminAddHotelController extends ModuleAdminController
$this->errors[] = $this->l('Invalid Hotel name in ').$lang['name'];
}
}
if ($shortDescription = html_entity_decode(Tools::getValue('short_description_'.$lang['id_lang']))) {
if (!Validate::isCleanHtml($shortDescription)) {
$this->errors[] = sprintf($this->l('Short description is not valid in %s'), $lang['name']);
}
}
}
$shortDescriptionLength = Tools::strlen($shortDescription);
$shortDescriptionHtmlLength = $shortDescriptionLength - Tools::strlen(strip_tags($shortDescription));
if ($shortDescriptionLength > ($shortDescriptionMaxChar + $shortDescriptionHtmlLength)) {
$this->errors[] = sprintf($this->l('Short description cannot exceed %s characters in '), $shortDescriptionMaxChar).$lang['name'];
}
}
if ($description = html_entity_decode(Tools::getValue('description_'.$lang['id_lang']))) {
if (!Validate::isCleanHtml($description)) {
$this->errors[] = sprintf($this->l('Description is not valid in %s'), $lang['name']);
}
}
if ($policies = html_entity_decode(Tools::getValue('policies_'.$lang['id_lang']))) {
if (!Validate::isCleanHtml($policies)) {
$this->errors[] = sprintf($this->l('policies are not valid in %s'), $lang['name']);
}
foreach ($languages as $lang) {
if ($shortDescription = html_entity_decode(Tools::getValue('short_description_'.$lang['id_lang']))) {
if (!Validate::isCleanHtml($shortDescription)) {
$this->errors[] = sprintf($this->l('Short description is not valid in %s'), $lang['name']);
}
if ($metaTitle = trim(Tools::getValue('meta_title_'.$lang['id_lang']))) {
if (!Validate::isGenericName($metaTitle)) {
$this->errors[] = $this->l('Invalid Meta title in ').$lang['name'];
} else if (Tools::strlen($metaTitle) > 128) {
$this->errors[] = $this->l('Meta title cannot exceed 128 characters in ').$lang['name'];
}
$shortDescriptionLength = Tools::strlen($shortDescription);
if ($shortDescriptionLength > $shortDescriptionMaxChar) {
$this->errors[] = sprintf($this->l('Short description cannot exceed %s characters in '), $shortDescriptionMaxChar).$lang['name'];
}
}
if ($metaDescription = trim(Tools::getValue('meta_description_'.$lang['id_lang']))) {
if (!Validate::isGenericName($metaDescription)) {
$this->errors[] = $this->l('Invalid Meta description in ').$lang['name'];
} else if (Tools::strlen($metaDescription) > 255) {
$this->errors[] = $this->l('Meta description cannot exceed 128 characters in ').$lang['name'];
}
if ($description = html_entity_decode(Tools::getValue('description_'.$lang['id_lang']))) {
if (!Validate::isCleanHtml($description)) {
$this->errors[] = sprintf($this->l('Description is not valid in %s'), $lang['name']);
}
}
if ($policies = html_entity_decode(Tools::getValue('policies_'.$lang['id_lang']))) {
if (!Validate::isCleanHtml($policies)) {
$this->errors[] = sprintf($this->l('policies are not valid in %s'), $lang['name']);
}
}
if ($metaKeyWords = trim(Tools::getValue('meta_keywords_'.$lang['id_lang']))) {
if (!Validate::isGenericName($metaKeyWords)) {
$this->errors[] = $this->l('Invalid Meta keywords in ').$lang['name'];
} else if (Tools::strlen($metaKeyWords) > 255) {
$this->errors[] = $this->l('Meta keywords cannot exceed 128 characters in ').$lang['name'];
}
if ($metaTitle = trim(Tools::getValue('meta_title_'.$lang['id_lang']))) {
if (!Validate::isGenericName($metaTitle)) {
$this->errors[] = $this->l('Invalid Meta title in ').$lang['name'];
} else if (Tools::strlen($metaTitle) > 128) {
$this->errors[] = $this->l('Meta title cannot exceed 128 characters in ').$lang['name'];
}
}
if ($metaDescription = trim(Tools::getValue('meta_description_'.$lang['id_lang']))) {
if (!Validate::isGenericName($metaDescription)) {
$this->errors[] = $this->l('Invalid Meta description in ').$lang['name'];
} else if (Tools::strlen($metaDescription) > 255) {
$this->errors[] = $this->l('Meta description cannot exceed 128 characters in ').$lang['name'];
}
}
if ($metaKeyWords = trim(Tools::getValue('meta_keywords_'.$lang['id_lang']))) {
if (!Validate::isGenericName($metaKeyWords)) {
$this->errors[] = $this->l('Invalid Meta keywords in ').$lang['name'];
} else if (Tools::strlen($metaKeyWords) > 255) {
$this->errors[] = $this->l('Meta keywords cannot exceed 128 characters in ').$lang['name'];
}
}
}