Jump to content

Recommended Posts

The categories are taken as strings so any variation like a leading or trailing blank on one but not the other will cause this to happen. For example " 123" may not be the same as "123 " which may be different from "123".

 

Hi rogue,

You are right, but my csv is created with Turbo Lister. So I haven't any space or characters that change the category' string.

thank you.

 

F

Link to comment
Share on other sites

  • 1 month later...

I can fix : 

change file controllers/admin/ AdminImportController.php line 1269: 

if (is_numeric($value))
					{
						if (Category::categoryExists((int)$value))
							$product->id_category[] = (int)$value;
						else
						{
							$category_to_create = new Category();
							$category_to_create->id = (int)$value;
							$category_to_create->name = AdminImportController::createMultiLangField($value);
							$category_to_create->active = 1;
							$category_to_create->id_parent = Configuration::get('PS_HOME_CATEGORY'); // Default parent is home for unknown category to create
							$category_link_rewrite = Tools::link_rewrite($category_to_create->name[$default_language_id]);
							$category_to_create->link_rewrite = AdminImportController::createMultiLangField($category_link_rewrite);
							if (($field_error = $category_to_create->validateFields(UNFRIENDLY_ERROR, true)) === true &&
								($lang_field_error = $category_to_create->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $category_to_create->add())
								$product->id_category[] = (int)$category_to_create->id;
							else
							{
								$this->errors[] = sprintf(
									Tools::displayError('%1$s (ID: %2$s) cannot be saved'),
									$category_to_create->name[$default_language_id],
									(isset($category_to_create->id) && !empty($category_to_create->id))? $category_to_create->id : 'null'
								);
								$this->errors[] = ($field_error !== true ? $field_error : '').(isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '').
									Db::getInstance()->getMsgError();
							}
						}
					}
					else if (is_string($value) && !empty($value))

to 

//if (is_numeric($value))
//					{
//						if (Category::categoryExists((int)$value))
//							$product->id_category[] = (int)$value;
//						else
//						{
//							$category_to_create = new Category();
//							$category_to_create->id = (int)$value;
//							$category_to_create->name = AdminImportController::createMultiLangField($value);
//							$category_to_create->active = 1;
//							$category_to_create->id_parent = Configuration::get('PS_HOME_CATEGORY'); // Default parent is home for unknown category to create
//							$category_link_rewrite = Tools::link_rewrite($category_to_create->name[$default_language_id]);
//							$category_to_create->link_rewrite = AdminImportController::createMultiLangField($category_link_rewrite);
//							if (($field_error = $category_to_create->validateFields(UNFRIENDLY_ERROR, true)) === true &&
//								($lang_field_error = $category_to_create->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $category_to_create->add())
//								$product->id_category[] = (int)$category_to_create->id;
//							else
//							{
//								$this->errors[] = sprintf(
//									Tools::displayError('%1$s (ID: %2$s) cannot be saved'),
//									$category_to_create->name[$default_language_id],
//									(isset($category_to_create->id) && !empty($category_to_create->id))? $category_to_create->id : 'null'
//								);
//								$this->errors[] = ($field_error !== true ? $field_error : '').(isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '').
//									Db::getInstance()->getMsgError();
//							}
//						}
//					}
				     if (!empty($value))
Link to comment
Share on other sites

×
×
  • Create New...