deech123 Posted June 4, 2010 Share Posted June 4, 2010 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 ----1the moment I now upload the csv with the second tree levelsI 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 1if 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 :1001234so 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 --- 1so 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 --- 1even if the second import has a totally different id... : 1001341 --- Beveiliging --- 1001231so 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 More sharing options...
rocky Posted June 4, 2010 Share Posted June 4, 2010 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. 1 Link to comment Share on other sites More sharing options...
deech123 Posted June 4, 2010 Author Share Posted June 4, 2010 this solved the problem.thx rocky. Link to comment Share on other sites More sharing options...
uddhava Posted June 7, 2010 Share Posted June 7, 2010 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 More sharing options...
uddhava Posted June 7, 2010 Share Posted June 7, 2010 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 More sharing options...
deech123 Posted June 7, 2010 Author Share Posted June 7, 2010 Uddhave,did the updateand 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 More sharing options...
uddhava Posted June 7, 2010 Share Posted June 7, 2010 Uddhave,did the updateand I just comment out the totale code like this : Yes, you could comment the whole code. I just was catious not to break the code.Thanks for the update Link to comment Share on other sites More sharing options...
sandybali Posted September 28, 2011 Share Posted September 28, 2011 (edited) did the update and I just comment out the totale code like this : /admin/tabs/AdminImport.php version:1.4.1 Attachment: /* $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 September 28, 2011 by sandybali (see edit history) Link to comment Share on other sites More sharing options...
webplus Posted August 1, 2012 Share Posted August 1, 2012 (edited) 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 August 1, 2012 by webplus (see edit history) 1 Link to comment Share on other sites More sharing options...
Geeky_Gamer2017 Posted August 11, 2017 Share Posted August 11, 2017 Where is the file for this i did not see the file admin/tabs/AdminImport.php 2 Link to comment Share on other sites More sharing options...
Recommended Posts