Jump to content

[SOLVED] Importing categories with the same name is not possible.


Recommended Posts

Hi guys,

after a very short night (not a lot of sleep) I found out that there is a problem with the csv import module.

I have imported a csv like this for level 1 categories :

ID --- Name --- Parent Category
1001227 --- Audio/Video --- 1 
1001230 --- Batterijen & Energie --- 1
1001234 --- Beveiliging --- 1
1001231 --- Computer / Multimedia --- 1
1001224 --- Diverse --- 1
1001233 --- Foto & Camcorder --- 1
1001225 --- Gaming --- 1
1001232 --- Huishoudelijke apparaten --- 1
1001229 --- Kabels & connectoren --- 1
1001228 --- Radio & Tv ontvangst --- 1
1001223 --- Service & gereedschap --- 1
1001226 --- Sound & Light --- 1


so look good at the third one : ID 1001234 --- Beveiliging ----1
the moment I now upload the csv with the second tree levels
I have one line like this :


I have imported a csv like this for level 2 categories :

ID --- Name --- Parent Category
1001341 --- Beveiliging --- 1001231



the purpose is that under : 1001231 --- Computer / Multimedia --- 1
the treelevel2 : 1001341 --- Beveiliging --- 1001231 appears as different one as level 1

if you look well, the name is allready used but had a whole other meaning.
the ID of the Beveiliging is 1001341 and the first import the Beveiliging was :1001234
so total different id's.
now after I import this second level what happens.
the "1001234 --- Beveiliging --- 1" is no longer in treelevel one (where it must stay)
but is moved to : the treelevel : 1001231 --- Computer / Multimedia --- 1

so the whole section looks now like :

ID --- Name --- Parent Category
1001227 --- Audio/Video --- 1 
1001230 --- Batterijen & Energie --- 1
1001231 --- Computer / Multimedia --- 1
            1001231 --- Computer / Multimedia --- 1
1001224 --- Diverse --- 1
1001233 --- Foto & Camcorder --- 1
1001225 --- Gaming --- 1
1001232 --- Huishoudelijke apparaten --- 1
1001229 --- Kabels & connectoren --- 1
1001228 --- Radio & Tv ontvangst --- 1
1001223 --- Service & gereedschap --- 1
1001226 --- Sound & Light --- 1



So the import module moved the whole section 1001231 --- Computer / Multimedia --- 1
even if the second import has a totally different id... : 1001341 --- Beveiliging --- 1001231

so imagine that I have a 3 tree levels and together over 500 categories...all mixed up and totaly wrong.

any idea how we can solve this problem, because the problem is really in the import module.
It can not just change a whole level to an other level if the new level has the same name but a total different ID an total different parent category????

hope to hear something, because this is really wrong :-)

thanks for any tip.

Link to comment
Share on other sites

This is actually by design. PrestaShop doesn't support importing categories with the same name. It has been previously reported as a bug, but PrestaShop simply added a message on the Import tab that says "Note that the category import does not support categories of the same name" and marked the bug as resolved. There is a feature request here for this feature, so you're not alone in wanting this.

Looking at the categoryImport() function in admin/tabs/AdminImport.php, it appears it is the following code that checks whether a category with the same name already exists and then changes the category ID to it instead of what is in the CSV file:

$categoryAlreadyCreated = Category::searchByName($defaultLanguageId, $category->name[$defaultLanguageId], true);

// If category already in base, get id category back
if ($categoryAlreadyCreated['id_category'])
{
   $catMoved[$category->id] = intval($categoryAlreadyCreated['id_category']);
   $category->id =    intval($categoryAlreadyCreated['id_category']);
}



Perhaps commenting out this code will make the CSV import do what you want.

  • Like 1
Link to comment
Share on other sites

I have commented out the following code and i can confirm it works.
Importing similar named categories is now possible.
I also checked to see if you can do a re-import when your data is changed AND you do not delete the categories during import. And this also still works. The data gets updated.
Here is my code : (line 476 - 481

// If category already in base, get id category back
               if ($categoryAlreadyCreated['id_category'])
               {
                   //$catMoved[$category->id] = intval($categoryAlreadyCreated['id_category']);
                   //$category->id =    intval($categoryAlreadyCreated['id_category']);
               }




Now the PS team has to implement this into an option that you can enable/disable.

Link to comment
Share on other sites

this solved the problem.

thx rocky.


Hi deedch123.
Could you change the subject of your 1st thread to something more useful?
Then other visitor can find it through the search.
Here is a suggestion : [sOLVED] Importing categories with the same name is not possible.
Link to comment
Share on other sites

Uddhave,

did the update

and I just comment out the totale code like this :

               /*
               $categoryAlreadyCreated = Category::searchByName($defaultLanguageId, $category->name[$defaultLanguageId], true);

               // If category already in base, get id category back
               if ($categoryAlreadyCreated['id_category'])
               {
                   $catMoved[$category->id] = intval($categoryAlreadyCreated['id_category']);
                   $category->id =    intval($categoryAlreadyCreated['id_category']);
               }
               */



but I changed it back now to your solution.
only comment out the two lines.

thx

Link to comment
Share on other sites

  • 1 year later...

did the update

 

and I just comment out the totale code like this :

/admin/tabs/AdminImport.php version:1.4.1

 

Attachment:post-283195-0-40472600-1317189758_thumb.jpg

 

/*

    $categoryAlreadyCreated = Category::searchByNameAndParentCategoryId($defaultLanguageId, $category->name[$defaultLanguageId], $category->id_parent);
   // If category already in base, get id category back
   if ($categoryAlreadyCreated['id_category'])
   {
 $catMoved[$category->id] = (int)($categoryAlreadyCreated['id_category']);
 $category->id = (int)($categoryAlreadyCreated['id_category']);
   }

*/

Edited by sandybali (see edit history)
Link to comment
Share on other sites

  • 10 months later...

My suggestion for importing the categories with the same name:

 

If you don't want to struggle with ID's and the above code is not helping (my case not sure why), I mark them with some unique strings to distinguish them in CSV file:

1) Categoryname somestring

2) Categoryname someotherstring

 

And after successfull import I cut the string in database with this simple query (you have to change the column and fields):

 

UPDATE table_name SET column_name = REPLACE(column_name,'original_string','replace_string')

Edited by webplus (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 5 years later...
×
×
  • Create New...