madpugger Posted July 10 Share Posted July 10 Surely this can't still be a thing?! Men > Shoes Women > Shoes We still can't import this? Does anyone know of a workaround or a module that allows CSV (or google sheet/excel) import of categories with the same name? I have a file with ID, Parent ID, Name, Active etc. I know I can import products into categories with the same name in different places by using the full path, ie home/mens/shoes for one fake product, then home/womens/shoes on another, but this seems ridiculous to have to import fake products to fix a messed up category tree! It's also not really feasible with the amount of categories. Thanks Link to comment Share on other sites More sharing options...
madpugger Posted July 10 Author Share Posted July 10 Oh, also, on import I'd like to delete categories I no longer need (put there by an erroneous product import for example), but to move any orphaned products to the parent but without disabling them! Link to comment Share on other sites More sharing options...
Daresh Posted July 11 Share Posted July 11 It seems you need quite a lot there. Maybe for a start you would be interested in an import script that is able to import categories from a CSV file, where the categories are stored in path format, like: Men>Shoes, Women>Shoes? I could develop such solution for you. 1 Link to comment Share on other sites More sharing options...
madpugger Posted July 13 Author Share Posted July 13 27 minutes ago, El Patron said: Use category IDs instead of names in your CSV Assign products or sub-categories by their unique ID, not name. This ensures the importer assigns them accurately, even with name duplicates. Note: you must obtain category IDs from your database (e.g., via phpMyAdmin). Unless I am missing something, you can't do this in category import. There is no way to CSV import PARENT ID So Mens>Shoes>Trainers Womens>Shoes>Trainers This is not possible to import as a CATEGORY import. As I said above, I know I can do it with a product import sheet with Categories XYZ as: Mens/Shoes/Trainers or Womens/Shoes/Trainers, and I know I can do it with Category ID too, although this just made String imports for me (i.e. Category 1, 59, 18 would make three new categories of "1", "59" and "18" rather than importing to IDs 1, 59 and 18, but regardless, my question was how to import CATEGORIES not products. I don't want to import temporary products JUST to make a category tree. Link to comment Share on other sites More sharing options...
madpugger Posted July 13 Author Share Posted July 13 On 7/11/2025 at 12:55 PM, Daresh said: It seems you need quite a lot there. Maybe for a start you would be interested in an import script that is able to import categories from a CSV file, where the categories are stored in path format, like: Men>Shoes, Women>Shoes? I could develop such solution for you. Possibly, but surely it should be natively possible to CSV IMPORT a CATEGORY TREE by ID! I am sure there are plenty of people who use PS that have categories with the same name. It is possible to do what you suggest already with products - although interestingly I haven't actually tried this with CATEGORY import. In product import, under Categories XYZ you can put: Mens/Shoes/Trainers and it will place the product in the right category, but if for example they are unisex and you also want them in Womens>Shoes>Trainers, it is not possible to do in product import: Mens/Shoes/Trainers, Womens>Shoes/Trainers - PS ignores everything after the first item, so it will place the item in Mens>Shoes>Trainers but not the womens one. However, this wouldn't be an issue in a category import if it accepts Mens/Shoes/Trainers but I suspect it will just make a category "Mens/Shoes/Trainers" or throw an error. All that is needed is for PS Import of Categories to do this by ID for Category and Parent category. It's then possible to import ALL categories in one pass, so long as the categories are listed by depth in the CSV. Link to comment Share on other sites More sharing options...
madpugger Posted July 13 Author Share Posted July 13 2 minutes ago, El Patron said: Using phpmyadmin you can do whatever you want. Daresh can help you better. Yes, I know I can do it directly in the database, but this isn't an ideal solution for fixing PS! 1 Link to comment Share on other sites More sharing options...
madpugger Posted July 13 Author Share Posted July 13 As suspected, Mens/Shoes/Trainers just makes a category of "Mens/Shoes/Trainers" using CATEGORY import, but for those looking to do Product imports, this would make a category tree of Mens > Shoes > Trainers and place the product in Trainers under Mens Shoes. Category Import needs to be updated to allow import by CATEGORY ID and PARENT ID rather than name (optionally) Link to comment Share on other sites More sharing options...
madpugger Posted July 13 Author Share Posted July 13 14 minutes ago, El Patron said: It's a solution I would use, recommend. You can open new feature request on github, get an experienced dev or wait for other community member to provide a different solution. I prefer phpmyadmin, but always test on dev copy. Thanks for your help. Yes, I am happy to use PHPMyAdmin but I'd rather see if there is a cleaner way for PS users since this is a forum for users of PS too, looking to solve problems. I feel this is a fairly basic thing (hence using Shoes and Trainers as examples - they are not the categories I actually need!) I could do it in the database for sure, but this doesn't help back office users. If everything was just fixed using the database, then we'd need no UI or back office! But I understand that you're just offering support for my issue right now. (I've sorted it already but as I say, I'd like a proper fix to help others too). I have also put a feature request in on Git, thanks. 1 Link to comment Share on other sites More sharing options...
madpugger Posted July 13 Author Share Posted July 13 (edited) 15 minutes ago, El Patron said: Share how you solved for others. I have done it manually for now for duplicated names but I'd prefer to see a solution in PS import, which is why I've started the thread. I would have done it in PHPMyAdmin but there wasn't enough errors to warrant this in my case right now, but I would still like to see a fix so we can export/import to a fresh shop or routinely modify trees which we do by exporting via an endpoint into google sheets and amending them there. However, for anyone reading that is having this issue. You can manually enter duplicates in the tree as PS uses ID as the unique identifier, it is only the CATEGORY IMPORT that is an issue with duplicate names. Then for product import you can use CATEGORY ID if you wish (although this is bug prone, I don't think it works with Excel imports as it will use the number as a string for the name) or you can put the path separated by forward slash "/" without quotes in the Categories xyz column. Example Product import category column would be "mens/shoes/trainers" without the quotes. this will place your product in Trainers under Mens Shoes. You can even use this to import your categories to make a category tree using "fake" products that you can delete later (a workaround of sorts - but absolutely ridiculous that you need to use PRODUCT IMPORT to make your category tree! Example: Product name, Category Temporary Product 1, Mens/Shoes/Trainers Temp Product 2, Womens/Shoes/Trainers Temp Product 3, Kids/Shoes/Trainers Temp Product 4, Mens/Shoes/Flip Flops (I don't actually sell shoes sorry!) Temp Product 5, Mens/Shoes/Flip Flops/Any Other Child name you like Then you would need to delete these temporary products. Edit: Note, you don't need to add Mens before Shoes when doing it as above, if you used something like "Cat 1/Cat 2/Cat 3/Cat 4 in your first line, all of these categories would be created by PS and look like this in the BO once completed. Home>Cat 1>Cat 2>Cat 3>Cat 4 (the home category is default, so your imported categories will fall under it). Edited July 13 by madpugger (see edit history) 1 Link to comment Share on other sites More sharing options...
El Patron Posted July 13 Share Posted July 13 33 minutes ago, madpugger said: I have done it manually for now for duplicated names but I'd prefer to see a solution in PS import, which is why I've started the thread. I would have done it in PHPMyAdmin but there wasn't enough errors to warrant this in my case right now, but I would still like to see a fix so we can export/import to a fresh shop or routinely modify trees which we do by exporting via an endpoint into google sheets and amending them there. However, for anyone reading that is having this issue. You can manually enter duplicates in the tree as PS uses ID as the unique identifier, it is only the CATEGORY IMPORT that is an issue with duplicate names. Then for product import you can use CATEGORY ID if you wish (although this is bug prone, I don't think it works with Excel imports as it will use the number as a string for the name) or you can put the path separated by forward slash "/" without quotes in the Categories xyz column. Example Product import category column would be "mens/shoes/trainers" without the quotes. this will place your product in Trainers under Mens Shoes. You can even use this to import your categories to make a category tree using "fake" products that you can delete later (a workaround of sorts - but absolutely ridiculous that you need to use PRODUCT IMPORT to make your category tree! Example: Product name, Category Temporary Product 1, Mens/Shoes/Trainers Temp Product 2, Womens/Shoes/Trainers Temp Product 3, Kids/Shoes/Trainers Temp Product 4, Mens/Shoes/Flip Flops (I don't actually sell shoes sorry!) Temp Product 5, Mens/Shoes/Flip Flops/Any Other Child name you like Then you would need to delete these temporary products. Edit: Note, you don't need to add Mens before Shoes when doing it as above, if you used something like "Cat 1/Cat 2/Cat 3/Cat 4 in your first line, all of these categories would be created by PS and look like this in the BO once completed. Home>Cat 1>Cat 2>Cat 3>Cat 4 (the home category is default, so your imported categories will fall under it). Please change title to solved so others find your solution. Link to comment Share on other sites More sharing options...
madpugger Posted July 13 Author Share Posted July 13 (edited) 8 minutes ago, El Patron said: Please change title to solved so others find your solution. NO! Why would I change it to solved? Is there now a magic way of importing CATEGORIES with the same name as CATEGORIES without doing products as per original question? The original question is not solved. The reason this is not solved is because the workaround I suggest above only works for adding new categories, it does not fix a broken tree. If you delete all categories to clear the IDs, it will break all product category linking. Additionally, you can only add a product to ONE category doing it this way, you cannot separate by comma (i.e. Cat1/Cat2/Cat3, Cat4/Cat5, Cat 18 etc, it will ONLY put it in Cat3 in this example and will not add the other categories in the list if they dont exist.) My original question is about how to import categories with the same name to fix a broken tree. Edited July 13 by madpugger (see edit history) 1 Link to comment Share on other sites More sharing options...
GlennaJAllen Posted July 14 Share Posted July 14 (edited) You can try importing categories with unique identifiers (like IDs or slugs) instead of names to avoid duplication and keep the structure clean.I also surfed and saw at https://modhello.net/ very good sharing Edited July 15 by GlennaJAllen (see edit history) Link to comment Share on other sites More sharing options...
Paul C Posted July 14 Share Posted July 14 (edited) @madpugger what version of Prestashop are you using? I'm not sure I understand the "broken tree" part. If the actual category tree structure is corrupt, then you would need to force it to recalculate. This can be done via code, or more simply - just add a random category from the back office. That will force it to recalculate the tree as a side-effect and you can then delete this extra new category once it's done. If you mean "broken" as in products in the wrong categories.... It does appear that you *can't* remove categories during a subsequent product import to update. During the import it appears to only add new categories for existing products (in controllers/admin/AdminImportController.php): if (isset($product->id) && $product->id && Product::existsInDatabase((int) $product->id, 'product')) { $product->loadStockData(); $category_data = Product::getProductCategories((int) $product->id); if (is_array($category_data)) { foreach ($category_data as $tmp) { if (!$product->category || is_array($product->category)) { $product->category[] = $tmp; } } } } The above code takes the existing categories and appends them to the categories you have in your import file (for existing products). Later it removes any duplicates. Ideally there should be a switch in there to specify whether you want to keep the existing categories or not. It would be worth logging it as a "feature request" (Prestashop github issues click "New Issue" and mark it as a feature request). I *think* that if you were to simply edit the line: $category_data = Product::getProductCategories((int) $product->id); To: $category_data = []; // Product::getProductCategories((int) $product->id); Then you would only set the imported categories for the product. This has the side-effect of removing any categories not specified in the import. Importing categories themselves is fraught. It *should* work but with some caveats. I don't use the default CSV importer but when I look at the example import file for categories (in the docs folder) you can indeed specify the parent category in the category import. Looking at the code (I'm looking at 8.2.0 right now, although I don't imagine it has changed much if at all since 1.6) you can specify either a name or an ID for the parent category. From the docs folder: Category ID;Active (0/1);Name *;Parent category;Root category (0/1);Description;Meta title;Meta description;URL rewritten;Image URL If you use a name for the parent category, then it will pick up the first category of that name that it finds as it's using Category::searchByName(). The parent category, if specified by name needs to pre-exist AND be unique for this to work. If the parent category is specified by an id, then everything should be fine as it subsequently finds the subcategory id using the function Category::searchByNameAndParentCategoryId() The upshot is that you should probably always use an absolute category id for the parent field, so make sure that you import the parent categories first. Best practice would be to import categories by level (i.e. first import parent categories, then separately import subcategories once you know the parent ids etc.). Since you have a category structure that you want now, then this is probably all moot for you, but maybe not for others starting their "import journey" EDIT: Note that I don't recommend modifying core files as suggested above. Doing it temporarily to sort out a problem is slightly different though and you can revert the change once the issue is fixed and then hopefully it gets fixed via a feature request. If I can find the time I might consider submitting a pull request with the necessary changes required to make the above happen, but there's no guarantee that the request will be accepted or which version it could be applied to, hence the question at the top of my response..... Edited July 14 by Paul C (see edit history) Link to comment Share on other sites More sharing options...
madpugger Posted July 14 Author Share Posted July 14 9 hours ago, Paul C said: @madpugger what version of Prestashop are you using? I'm not sure I understand the "broken tree" part. If the actual category tree structure is corrupt, then you would need to force it to recalculate. This can be done via code, or more simply - just add a random category from the back office. That will force it to recalculate the tree as a side-effect and you can then delete this extra new category once it's done. If you mean "broken" as in products in the wrong categories.... It does appear that you *can't* remove categories during a subsequent product import to update. During the import it appears to only add new categories for existing products (in controllers/admin/AdminImportController.php): if (isset($product->id) && $product->id && Product::existsInDatabase((int) $product->id, 'product')) { $product->loadStockData(); $category_data = Product::getProductCategories((int) $product->id); if (is_array($category_data)) { foreach ($category_data as $tmp) { if (!$product->category || is_array($product->category)) { $product->category[] = $tmp; } } } } The above code takes the existing categories and appends them to the categories you have in your import file (for existing products). Later it removes any duplicates. Ideally there should be a switch in there to specify whether you want to keep the existing categories or not. It would be worth logging it as a "feature request" (Prestashop github issues click "New Issue" and mark it as a feature request). I *think* that if you were to simply edit the line: $category_data = Product::getProductCategories((int) $product->id); To: $category_data = []; // Product::getProductCategories((int) $product->id); Then you would only set the imported categories for the product. This has the side-effect of removing any categories not specified in the import. Importing categories themselves is fraught. It *should* work but with some caveats. I don't use the default CSV importer but when I look at the example import file for categories (in the docs folder) you can indeed specify the parent category in the category import. Looking at the code (I'm looking at 8.2.0 right now, although I don't imagine it has changed much if at all since 1.6) you can specify either a name or an ID for the parent category. From the docs folder: Category ID;Active (0/1);Name *;Parent category;Root category (0/1);Description;Meta title;Meta description;URL rewritten;Image URL If you use a name for the parent category, then it will pick up the first category of that name that it finds as it's using Category::searchByName(). The parent category, if specified by name needs to pre-exist AND be unique for this to work. If the parent category is specified by an id, then everything should be fine as it subsequently finds the subcategory id using the function Category::searchByNameAndParentCategoryId() The upshot is that you should probably always use an absolute category id for the parent field, so make sure that you import the parent categories first. Best practice would be to import categories by level (i.e. first import parent categories, then separately import subcategories once you know the parent ids etc.). Since you have a category structure that you want now, then this is probably all moot for you, but maybe not for others starting their "import journey" EDIT: Note that I don't recommend modifying core files as suggested above. Doing it temporarily to sort out a problem is slightly different though and you can revert the change once the issue is fixed and then hopefully it gets fixed via a feature request. If I can find the time I might consider submitting a pull request with the necessary changes required to make the above happen, but there's no guarantee that the request will be accepted or which version it could be applied to, hence the question at the top of my response..... WOW that's a lot to digest! I'll look fully later, but in answer to "Broken" I mean, if some (silly person) imported products with new categories - they all end up in the HOME category as their parent. So to "Fix" this, we'd want to do a Category import to ensure all the categories have the correct parents, but this can't be done by Parent Name, as there are duplicates of Parent names, hence the use of mens/shoes/trainers and womens/shoes/trainers as an example. So perhaps Mens/Shoes/Trainers exists, but also so does Home/Womens, Home/Shoes, Home/Trainers. So it is not possible to import (in the default PS import) to "fix" this. Regardless, even to start with a clean slate, using google sheets or excel for example to build the tree (much easier than adding each category manually), you cant "make" a tree that has the mens and womens shoes and trainers. Thanks Link to comment Share on other sites More sharing options...
madpugger Posted July 14 Author Share Posted July 14 11 hours ago, GlennaJAllen said: You can try importing categories with unique identifiers (like IDs or slugs) instead of names to avoid duplication and keep the structure clean. Yes, but you CANT as far as I can tell, use PARENT ID, so this doesn't work. Link to comment Share on other sites More sharing options...
madpugger Posted July 14 Author Share Posted July 14 9 hours ago, Paul C said: I don't use the default CSV importer but when I look at the example import file for categories (in the docs folder) you can indeed specify the parent category in the category import. Looking at the code (I'm looking at 8.2.0 right now, although I don't imagine it has changed much if at all since 1.6) you can specify either a name or an ID for the parent category. From the docs folder: Category ID;Active (0/1);Name *;Parent category;Root category (0/1);Description;Meta title;Meta description;URL rewritten;Image URL If you use a name for the parent category, then it will pick up the first category of that name that it finds as it's using Category::searchByName(). The parent category, if specified by name needs to pre-exist AND be unique for this to work. Interesting. When I import using Excel, it throws an error when using Parent ID. Also, at the top of Category Import, it also says importing categories with the same name is not supported, which makes me think the PARENT ID does not work. Perhaps this is an excel import issue where the column if formatted as plain text? But if that was the case, surely PS would have removed the banner telling us it is not possible? Link to comment Share on other sites More sharing options...
Paul C Posted July 15 Share Posted July 15 12 hours ago, madpugger said: Interesting. When I import using Excel, it throws an error when using Parent ID. Also, at the top of Category Import, it also says importing categories with the same name is not supported, which makes me think the PARENT ID does not work. Perhaps this is an excel import issue where the column if formatted as plain text? But if that was the case, surely PS would have removed the banner telling us it is not possible? I have some free time today so will set up a fresh install and try out a few things. The code 100% supports the intent that the "Parent category" field in the category CSV import file can be either a category name or an absolute category id. Link to comment Share on other sites More sharing options...
madpugger Posted July 15 Author Share Posted July 15 1 hour ago, Paul C said: I have some free time today so will set up a fresh install and try out a few things. The code 100% supports the intent that the "Parent category" field in the category CSV import file can be either a category name or an absolute category id. Thanks for that! I'll go try a CSV rather than Excel import, but it will probably be later on today before I get time! It just seems strange that, if it does actually support it, PS tells us it doesn't! Link to comment Share on other sites More sharing options...
Paul C Posted July 15 Share Posted July 15 (edited) OK so in a fresh install of the development branch (9.1.0) from git I created a very simple category import file with the following contents (Note that category id = 2 is "Home" and category id = 1 is "Root" so both are there by default and omitted): Category ID;Active (0/1);Name *;Parent category;Root category (0/1);Description 3;1;Women;2;0;Clothing for women 4;1;Men;2;0;Clothing for men 5;1;Shoes;3;0;Shoes for women 6;1;Shoes;4;0;Shoes for men I imported it successfully and have the two top-level categories "Women" and "Men" each with a subcategory of "Shoes". There is the issue however that both the "Shoes" subcategories have their link_rewrite field in the database set to "shoes". I then tried again (selected options to "Delete all categories before import" and "Force all ID numbers") with the following import file: Category ID;Active (0/1);Name *;Parent category;Root category (0/1);Description;Rewritten URL 3;1;Women;2;0;Clothing for women;women 4;1;Men;2;0;Clothing for men;men 5;1;Shoes;3;0;Shoes for women;shoes-women 6;1;Shoes;4;0;Shoes for men;shoes-men This seems to work for me and all of the categories were individually accessible. Edited July 15 by Paul C (see edit history) Link to comment Share on other sites More sharing options...
madpugger Posted July 16 Author Share Posted July 16 (edited) 22 hours ago, Paul C said: OK so in a fresh install of the development branch (9.1.0) from git I created a very simple category import file with the following contents (Note that category id = 2 is "Home" and category id = 1 is "Root" so both are there by default and omitted): Category ID;Active (0/1);Name *;Parent category;Root category (0/1);Description 3;1;Women;2;0;Clothing for women 4;1;Men;2;0;Clothing for men 5;1;Shoes;3;0;Shoes for women 6;1;Shoes;4;0;Shoes for men I imported it successfully and have the two top-level categories "Women" and "Men" each with a subcategory of "Shoes". There is the issue however that both the "Shoes" subcategories have their link_rewrite field in the database set to "shoes". I then tried again (selected options to "Delete all categories before import" and "Force all ID numbers") with the following import file: Category ID;Active (0/1);Name *;Parent category;Root category (0/1);Description;Rewritten URL 3;1;Women;2;0;Clothing for women;women 4;1;Men;2;0;Clothing for men;men 5;1;Shoes;3;0;Shoes for women;shoes-women 6;1;Shoes;4;0;Shoes for men;shoes-men This seems to work for me and all of the categories were individually accessible. Thanks, I have just tested on 9.0.0 and 8.2.1 also and it works, kind of! So the banner at the top of category import page is slightly misleading! You can use parent ID (certainly as CSV, I haven't properly tested XLS yet), BUT, the categories need to be in place first. In my case, I imported EVERYTHING to the home category with their FIXED ID's, then re-ran the import with the correct PARENT ID. I had to do this as our categories aren't sequential, so after deleting everything, it threw an error - the parent ID must exist before it can be a parent (which makes sense). ie. we may have ID, Name, Parent ID 10, Shoes, 100 100, Men, 2 So I ran: 10, Shoes, 2 100, Men, 2 Then re-ran the first file. This seemed to work fine. So I am not sure why PS says it's not supported, although I guess it isn't supported in a single pass fashion unless there are no categories that have a Parent ID higher than it's own ID. Thanks for this! Much appreciated. NOTE I have only tested with a CSV, not Excel yet, but the last time I used Excel with IDs, it saw them as strings and made a load of categories with numbers as their NAME. Edited July 16 by madpugger (see edit history) 1 Link to comment Share on other sites More sharing options...
Paul C Posted July 16 Share Posted July 16 2 hours ago, madpugger said: NOTE I have only tested with a CSV, not Excel yet, but the last time I used Excel with IDs, it saw them as strings and made a load of categories with numbers as their NAME The import processes lines in the import file sequentially (otherwise there would be issues with storing the entire file in memory and the import script timing out if too big) so yes, you need to make sure that the parent categories are processed first before the subcategories. I believe it would work as one import as long as that is the case. I suspect that excel will use commas as separators and may "decorate" the fields making them look like strings. I remember back in the day using a good "CSV" editor that let you handle such files much easier (this was way back when ZenCart and osCommerce were all the rage). Sadly I can't remember what it was called! Link to comment Share on other sites More sharing options...
madpugger Posted July 17 Author Share Posted July 17 19 hours ago, Paul C said: The import processes lines in the import file sequentially (otherwise there would be issues with storing the entire file in memory and the import script timing out if too big) so yes, you need to make sure that the parent categories are processed first before the subcategories. I believe it would work as one import as long as that is the case. I suspect that excel will use commas as separators and may "decorate" the fields making them look like strings. I remember back in the day using a good "CSV" editor that let you handle such files much easier (this was way back when ZenCart and osCommerce were all the rage). Sadly I can't remember what it was called! Yes, you could be right. We download as TSV from google sheets, then find/replace TAB with ; and change back to .csv and this works for us. Downloading as CSV directly doesn't work as you can't find/replace commas, since they are needed in some fields. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now