Re-import the same product file
Add/Update products
PHP Fatal error: Call to a member function getName() on null in /var/www/magento/html/vendor/magento/module-catalog-import-export/Model/Import/Product/CategoryProcessor.php on line 73
Hi @ljrweb
I cannot reproduce this bug on Magento 2.0.9 and current develop branch.
Could you try to reproduce it on 2.0.9?
Please, write more information for reproducing, if you can reproduce this bug on 2.0.9
i have same issue on Magento 2.1.1. I got same error with sample data.
http://magento.dev/admin/admin/import/validate/key/eb4d8c89ce1a6aaed91996161a8911e9026acb33437b77682d7f66bc29773683/?form_key=oleCoMgQ1fO5TAgu
Fatal error: Call to a member function getName() on null in /Users/sangthieu/Documents/WWW/magento.dev/public_html/vendor/magento/module-catalog-import-export/Model/Import/Product/CategoryProcessor.php on line 80
I have the same issue om Magento 2.1.3. Same error, just with 5 lines of CSV.
"PHP message: PHP Fatal error: Uncaught Error: Call to a member function getName() on null in /data/web/magento2/vendor/magento/module-catalog-import-export/Model/Import/Product/CategoryProcessor.php:80
I had the same issue, at the moment I have no idea what's the culprit but here's a quick fix for it.
in Magento\CatalogImportExport\Model\Import\Product\CategoryProcessor there's the line which causes this problem:
$path[] = $collection->getItemById((INT)$structure[$i])->getName();
add this on top of it.
if ($collection->getItemById($structure[$i]) == Null) {
continue;
}
Hello, @ljrweb. We could not reproduce Your issue neither on develop versions (2.0.15, 2.1.7, 2.2.0), nor on Your very one (2.0.7). Probably, the bug has already been fixed. Please let us know if You are still able to reproduce it on the develop version. Thanks for applying.
Goto to your project folder
vendor\magento\module-catalog-import-export\Model\Export\Product.php line no 439
Replace this
$path[] = $collection->getItemById($structure[$i])->getName();
with
$category = $this->_categoryFactory->create()->load($structure[$i]);
$path[] = $category->getName();
Also add a category factory in the product.php construct class
public function __construct(
\Magento\Catalog\Model\CategoryFactory $categoryFactory,
array $dateAttrCodes = []
){
$this->_categoryFactory = $categoryFactory;
}
Once you have added, compile your project and refresh cache and deploy the content
I suggest you , instead editing in core try overriding import and export model files
One cause of this error is deleting one or more "core/root" categories by manually deleting from catalog_category_entity.
It seems @magento-engcom-team is least interested in fixing these errors.
It occurs on Magento 2.2.2 as well. Magento is losing the game because of such errors and negligence of magento team :(
Same issue in here on 2.2.2 after deleting product directly from database (_catalog_product_entity_ table)
until properly clearing all data of deleted products, and clear related categories as well (even url_rewrite table) the error still exists
Same issue in here on 2.2.2
After manually deleting categories, make sure no existing category has a parent_id referencing a deleted one (don't forget to NOT delete the parent_id=0).
That fixed it for me.
Same issue here on 2.3.0 after fresh install
I have issue in magento2.2.8 after deleting categories from direct database. Actually this is the error and it can be solved by coding. but magento team is not interested to solve this issue.
One cause of this error is deleting one or more "core/root" categories by manually deleting from catalog_category_entity.
Can check which categories are corrupt with
var_dump($category->getPath()); in loop
vendor/magento/module-catalog-import-export/Model/Import/Product/CategoryProcessor.php:88
then check this id is really broke by calling url in admin area with this id
For us this was due to some migrated data which resulted in a few categories existing when their parent no longer did. Deleting these categories with a Mysql query did the trick.
delete c from catalog_category_entity as c left outer join catalog_category_entity as p on c.parent_id = p.entity_id where p.entity_id is null and c.entity_id != 1
Most helpful comment
It seems @magento-engcom-team is least interested in fixing these errors.
It occurs on Magento 2.2.2 as well. Magento is losing the game because of such errors and negligence of magento team :(