When importing products from XLSX, the ImportManger class (ImportProductsFromXlsx function), will generate an unhandled exception if the category hierarchy does not match, but the last child category name does match.
For example, if my excel file contains this category entry: "Body >> Bumper >> Bumper Grilles"
However, the correct value should be: "Body Parts >> Bumper >> Bumper Grilles"
The code at line 1343 will throw an unhandled exception: Sequence contains no matching element
This is the current code:
var importedCategories = categoryNames.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => allCategories.ContainsKey(x.Trim()) ? allCategories[x.Trim()].Id : allCategories.Values.First(c => c.Name == x.Trim()).Id).ToList();
This happens because:
allCategories.ContainsKey(x.Trim())
Will return false, then execute this condition:
allCategories.Values.First(c => c.Name == x.Trim()).IdWhich will fail, since the string will not be found, and throw a "Sequence contains no matching element" error.
We need to gracefully handle this error and report what the error is to the end user, in this case the fully qualified category path was not found the it the list of all allCategories.