Fixed: the validation error for max description field while duplicting room type and service products

This commit is contained in:
vishalsingh.qlo325
2025-05-10 11:04:44 +05:30
parent 4d13804ad1
commit 59082e4ec7
2 changed files with 109 additions and 73 deletions

View File

@@ -655,33 +655,52 @@ class AdminNormalProductsControllerCore extends AdminController
}
}
}
$limit = (int)Configuration::get('PS_SHORT_DESC_LIMIT');
if ($limit <= 0) {
$limit = 400;
}
$className = 'Product';
foreach (Language::getLanguages(true) as $language) {
if (Tools::strlen(strip_tags($product->name[$language['id_lang']])) > $limit) {
$this->errors[] = sprintf(
Tools::displayError('This %1$s field in %2$s is too long: %3$d chars max (current count %4$d).'),
call_user_func(array($className, 'displayFieldName'), 'description_short'),
$language['name'],
$limit,
Tools::strlen(strip_tags($product->name[$language['id_lang']]))
);
}
}
unset($product->id);
unset($product->id_product);
$product->indexed = 0;
$product->active = 0;
if ($product->add()
&& Category::duplicateProductCategories($id_product_old, $product->id)
&& ($combination_images = Product::duplicateAttributes($id_product_old, $product->id)) !== false
&& GroupReduction::duplicateReduction($id_product_old, $product->id)
// && Product::duplicateFeatures($id_product_old, $product->id)
&& Product::duplicateTags($id_product_old, $product->id)) {
if ($product->hasAttributes()) {
Product::updateDefaultAttribute($product->id);
} else {
Product::duplicateSpecificPrices($id_product_old, $product->id);
}
if (!Tools::getValue('noimage') && !Image::duplicateProductImages($id_product_old, $product->id, $combination_images)) {
$this->errors[] = Tools::displayError('An error occurred while copying images.');
} else {
Hook::exec('actionProductAdd', array('id_product' => (int)$product->id, 'product' => $product));
if (in_array($product->visibility, array('both', 'search')) && Configuration::get('PS_SEARCH_INDEXATION')) {
Search::indexation(false, $product->id);
if (!$this->errors) {
if ($product->add()
&& Category::duplicateProductCategories($id_product_old, $product->id)
&& ($combination_images = Product::duplicateAttributes($id_product_old, $product->id)) !== false
&& GroupReduction::duplicateReduction($id_product_old, $product->id)
// && Product::duplicateFeatures($id_product_old, $product->id)
&& Product::duplicateTags($id_product_old, $product->id)
) {
if ($product->hasAttributes()) {
Product::updateDefaultAttribute($product->id);
} else {
Product::duplicateSpecificPrices($id_product_old, $product->id);
}
$this->redirect_after = self::$currentIndex.(Tools::getIsset('id_category') ? '&id_category='.(int)Tools::getValue('id_category') : '').'&conf=19&token='.$this->token;
if (!Tools::getValue('noimage') && !Image::duplicateProductImages($id_product_old, $product->id, $combination_images)) {
$this->errors[] = Tools::displayError('An error occurred while copying images.');
} else {
Hook::exec('actionProductAdd', array('id_product' => (int)$product->id, 'product' => $product));
if (in_array($product->visibility, array('both', 'search')) && Configuration::get('PS_SEARCH_INDEXATION')) {
Search::indexation(false, $product->id);
}
$this->redirect_after = self::$currentIndex.(Tools::getIsset('id_category') ? '&id_category='.(int)Tools::getValue('id_category') : '').'&conf=19&token='.$this->token;
}
} else {
$this->errors[] = Tools::displayError('An error occurred while creating an object.');
}
} else {
$this->errors[] = Tools::displayError('An error occurred while creating an object.');
}
}
}