TL;DR: Reasons may vary, but you can find the info you need to fix the error inspecting the current AJAX request with your browser’s developer tools. For me it was that because of the ordering of my Excel sheet I was trying to create a category before its parent had been created.
When it comes to Prestashop I have mixed feelings. It is an awesome platform for non-technical people to set up and manage a fully-featured, customizable online shop; but on the other side I’ve always felt it is so developer unfriendly.
Hard to find documentation, weird dev community, intricate architecture, incomprehensible errors and a vast number of variables and constants to set up… I feel like there is no reason for Prestashop to have such a steep learning curve. I might talk more in-depth about this on other post, but for now let’s get our hands dirty with an error that I’ve recently encountered working in a client’s project that has brought me ungodly amounts of frustration.
The Prestashop import error comes up when trying to import categories from a CSV or Excel sheet in Prestashop 1.7. It states nothing but:
Which gives us close to no information at all about the error, even with debug mode enabled.
Turns out it’s just a poor error handling of AJAX requests and that the actual request holds the information we just might need to succeed.
Open up the developer tools (in Chrome: right click / Inspect) and head over the “Network” tab right before importing. There you should see all the AJAX requests that are being made “behind the scenes” by Prestashop. Click on start import and wait for the error to pop out.
When that happens, check out the last request in the list and look into the request “Preview” or “Response” tab:
There you go! That’s the reason it wasn’t working.
If we check out the Excel list to import we see that in fact there was trying to assign a category to a parent that wasn’t created yet (it was far below it in the Excel sheet).
If we search for that error message in our Prestashop codebase:
We see that, in fact, there is a function trying to calculate the current category to import depth and it throws an exception if it hasn’t been created yet.
Errors and fixing procedures may vary. It can be that your category name is too long, or that it contains weird characters that Prestashop may not like… just open up the developer tools, inspect the request and get the right info.
For me, the fix was obvious: I just ordered my Excel Sheet so that I create first 0-depth-level categories, then depth level 1 categories, and so on.
I tried commenting those 3 exception-related lines in Category.php and worked fine as well. That validation may not be necessary after all.
Picture: Clark Street Mercantile
P.S.: Follow me on Twitter to stay in the loop. I'm writing a book called Bold Hackers on making successful digital products as an indie hacker. Read other stories I've written. Subscribe below to get an alert when I publish a new post: