[+] BO : Merge of https://github.com/PrestaShop/PrestaShop/pull/570
This commit is contained in:
@@ -946,6 +946,39 @@ class CategoryCore extends ObjectModel
|
|||||||
AND c.`id_parent` = '.(int)$id_parent_category);
|
AND c.`id_parent` = '.(int)$id_parent_category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search with Pathes for categories
|
||||||
|
*
|
||||||
|
* @param integer $id_lang Language ID
|
||||||
|
* @param string $path of category
|
||||||
|
* @param boolean $object_to_create a category
|
||||||
|
* * @param boolean $method_to_create a category
|
||||||
|
* @return array Corresponding categories
|
||||||
|
*/
|
||||||
|
public static function searchByPath($id_lang, $path, $object_to_create = false, $method_to_create = false)
|
||||||
|
{
|
||||||
|
$categories = explode('/', trim($path));
|
||||||
|
$category = $id_parent_category = false;
|
||||||
|
|
||||||
|
if (is_array($categories) && count($categories))
|
||||||
|
foreach($categories as $category_name)
|
||||||
|
{
|
||||||
|
if ($id_parent_category)
|
||||||
|
$category = Category::searchByNameAndParentCategoryId($id_lang, $category_name, $id_parent_category);
|
||||||
|
else
|
||||||
|
$category = Category::searchByName($id_lang,$category_name,true);
|
||||||
|
|
||||||
|
if (!$category && $object_to_create && $method_to_create)
|
||||||
|
{
|
||||||
|
call_user_func_array(array($object_to_create, $method_to_create), array($id_lang, $category_name , $id_parent_category));
|
||||||
|
$category = Category::searchByPath($id_lang, $category_name);
|
||||||
|
}
|
||||||
|
if (isset($category['id_category']) && $category['id_category'])
|
||||||
|
$id_parent_category = (int)$category['id_category'];
|
||||||
|
}
|
||||||
|
return $category;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Each parent category of this category until the root category
|
* Get Each parent category of this category until the root category
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1357,6 +1357,13 @@ class AdminImportControllerCore extends AdminController
|
|||||||
$product->id_category[] = (int)$value;
|
$product->id_category[] = (int)$value;
|
||||||
else
|
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();
|
||||||
$category_to_create = new Category();
|
$category_to_create = new Category();
|
||||||
$category_to_create->id = (int)$value;
|
$category_to_create->id = (int)$value;
|
||||||
$category_to_create->name = AdminImportController::createMultiLangField($value);
|
$category_to_create->name = AdminImportController::createMultiLangField($value);
|
||||||
@@ -1381,35 +1388,11 @@ class AdminImportControllerCore extends AdminController
|
|||||||
}
|
}
|
||||||
else if (is_string($value) && !empty($value))
|
else if (is_string($value) && !empty($value))
|
||||||
{
|
{
|
||||||
$category = Category::searchByName($id_lang, trim($value), true);
|
$category = Category::searchByPath($default_language_id, trim($value), $this, 'productImportCreateCat');
|
||||||
if ($category['id_category'])
|
if ($category['id_category'])
|
||||||
$product->id_category[] = (int)$category['id_category'];
|
$product->id_category[] = (int)$category['id_category'];
|
||||||
else
|
else
|
||||||
{
|
$this->errors[] = sprintf(Tools::displayError('%1$s cannot be saved'), trim($value));
|
||||||
$category_to_create = new Category();
|
|
||||||
if (!Shop::isFeatureActive())
|
|
||||||
$category_to_create->id_shop_default = 1;
|
|
||||||
else
|
|
||||||
$category_to_create->id_shop_default = (int)Context::getContext()->shop->id;
|
|
||||||
$category_to_create->name = AdminImportController::createMultiLangField(trim($value));
|
|
||||||
$category_to_create->active = 1;
|
|
||||||
$category_to_create->id_parent = (int)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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1724,6 +1707,33 @@ class AdminImportControllerCore extends AdminController
|
|||||||
$this->closeCsvFile($handle);
|
$this->closeCsvFile($handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function productImportCreateCat($default_language_id, $category_name, $id_parent_category=null)
|
||||||
|
{
|
||||||
|
$category_to_create = new Category();
|
||||||
|
if (!Shop::isFeatureActive())
|
||||||
|
$category_to_create->id_shop_default = 1;
|
||||||
|
else
|
||||||
|
$category_to_create->id_shop_default = (int)Context::getContext()->shop->id;
|
||||||
|
$category_to_create->name = AdminImportController::createMultiLangField(trim($category_name));
|
||||||
|
$category_to_create->active = 1;
|
||||||
|
$category_to_create->id_parent = (int)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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function attributeImport()
|
public function attributeImport()
|
||||||
{
|
{
|
||||||
$default_language = Configuration::get('PS_LANG_DEFAULT');
|
$default_language = Configuration::get('PS_LANG_DEFAULT');
|
||||||
|
|||||||
Reference in New Issue
Block a user