diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index de428900ba9..734f516fa78 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -459,10 +459,14 @@ class ImportCsv extends ModeleImports $error++; }*/ $param_array = array('', $newval, 0, $arrayrecord[0]['val']); // Param to fetch parent from account, in chart. + } elseif ($class == 'Categorie') { + if ($objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel') { + $param_array = array('', $newval, $arrayrecord[1]['val']); + } } call_user_func_array(array($classinstance, $method), $param_array); // If not found, try the fetch from label - if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel') + if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel' && $class!='Categorie') { $param_array = array('', '', $newval); call_user_func_array(array($classinstance, $method), $param_array); diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php index c4799ba557e..1a92062b15f 100644 --- a/htdocs/core/modules/import/import_xlsx.modules.php +++ b/htdocs/core/modules/import/import_xlsx.modules.php @@ -486,10 +486,14 @@ class ImportXlsx extends ModeleImports $error++; }*/ $param_array = array('', $newval, 0, $arrayrecord[0]['val']); // Param to fetch parent from account, in chart. + } elseif ($class == 'Categorie') { + if ($objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel') { + $param_array = array('', $newval, $arrayrecord[1]['val']); + } } call_user_func_array(array($classinstance, $method), $param_array); // If not found, try the fetch from label - if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel') + if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel' && $class!='Categorie') { $param_array = array('', '', $newval); call_user_func_array(array($classinstance, $method), $param_array); diff --git a/htdocs/core/modules/modCategorie.class.php b/htdocs/core/modules/modCategorie.class.php index c04a4d6b346..e8a1bd218cd 100644 --- a/htdocs/core/modules/modCategorie.class.php +++ b/htdocs/core/modules/modCategorie.class.php @@ -406,15 +406,29 @@ class modCategorie extends DolibarrModules $this->import_icon[$r]=$this->picto; $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon $this->import_tables_array[$r]=array('ca'=>MAIN_DB_PREFIX.'categorie'); - $this->import_fields_array[$r]=array('ca.label'=>"Label*",'ca.type'=>"Type*",'ca.description'=>"Description"); - + $this->import_fields_array[$r]=array( + 'ca.label'=>"Label*",'ca.type'=>"Type*",'ca.description'=>"Description", + 'ca.fk_parent' => 'Parent' + ); $this->import_regex_array[$r]=array('ca.type'=>'^[0|1|2|3]'); + $this->import_convertvalue_array[$r] = array( + 'ca.fk_parent' => array( + 'rule' => 'fetchidfromcodeorlabel', + 'classfile' => '/categories/class/categorie.class.php', + 'class' => 'Categorie', + 'method' => 'fetch', + 'element' => 'category' + ) + ); $typeexample=""; if ($conf->product->enabled) { $typeexample.=($typeexample?"/":"")."0=Product"; } if ($conf->fournisseur->enabled) { $typeexample.=($typeexample?"/":"")."1=Supplier"; } if ($conf->societe->enabled) { $typeexample.=($typeexample?"/":"")."2=Customer-Prospect"; } if ($conf->adherent->enabled) { $typeexample.=($typeexample?"/":"")."3=Member"; } - $this->import_examplevalues_array[$r]=array('ca.label'=>"Supplier Category",'ca.type'=>$typeexample,'ca.description'=>"Imported category"); + $this->import_examplevalues_array[$r] = array( + 'ca.label'=>"Supplier Category",'ca.type'=>$typeexample,'ca.description'=>"Imported category", + 'ca.fk_parent' => '0' + ); if (! empty($conf->product->enabled)) {