4

Having trouble exporting products from Magento 2.x.

When I do an export from System > Export and select Entity Type of Products I'm receiving a Fatal Error.

Fatal error: Uncaught Error: Call to a member function getName() on null in C:\Web\gpp-magento2\vendor\magento\module-catalog-import-export\Model\Export\Product.php:442 Stack trace: #0 C:\Web\gpp-magento2\vendor\magento\module-catalog-import-export\Model\Export\Product.php(410): Magento\CatalogImportExport\Model\Export\Product->initCategories() #1 C:\Web\gpp-magento2\vendor\magento\framework\ObjectManager\Factory\AbstractFactory.php(111): Magento\CatalogImportExport\Model\Export\Product->__construct(Object(Magento\Framework\Stdlib\DateTime\Timezone), Object(Magento\Eav\Model\Config), Object(Magento\Framework\App\ResourceConnection), Object(Magento\Store\Model\StoreManager), Object(Magento\Framework\Logger\Monolog), Object(Magento\Catalog\Model\ResourceModel\Product\CollectionFactory), Object(Magento\ImportExport\Model\Export\Config), Object(Magento\Catalog\Model\ResourceModel\ProductFactory), Object(Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory), Object(Magento\Catalog\Model\ResourceModel\Category in C:\Web\gpp-magento2\vendor\magento\module-catalog-import-export\Model\Export\Product.php on line 442

A little background about this magento2 project, we are in the slow process of moving away from our Mage 1.9 store. We have been through the migration process and tying up some loose ends. Today I ran into the above while attempting an export to test the functionality of exporting products and reimporting them to observe changes.

showing you where I'm seeing the error

  • Did you maybe check if any products have a blank/null name? Check in DB or just sort by name in Catalog -> Product – Lez Jan 12 '18 at 22:49
  • @Lez I think you're on to something, I took a look in the DB and it does seem like we are missing some product names. I'm not able to locate these missing names in the backend of magento. Will do some more digging tomorrow. Thanks for the response! – WO_PGH Jan 16 '18 at 4:47
  • @Lez I did some more digging and although I did see some null values within catalog_product_entity_varchar nothing is null or blank for attribute_id 96(product name) – WO_PGH Jan 26 '18 at 1:04
  • SELECT * FROM gpp.catalog_product_entity_varchar WHERE attribute_id = 96; .... Do you think by chance there is something wrong with the category name? – WO_PGH Jan 26 '18 at 1:05
  • Category names are good.. nothing null or blank catalog_category_entity_varchar WHERE attribute_id = 111 and store_id = 0; – WO_PGH Jan 26 '18 at 1:13
2

go to Fatal error: Call to a member function getName() on a non-object in app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php on line 173

replace :

$path[] = $collection->getItemById($structure[$i])->getName();

with:

if($collection->getItemById($structure[$i]))
$path[] = $collection->getItemById($structure[$i])->getName();

Hope it will help you.

0

We had a slightly different issue but looking at the stack trace I believe the root cause was the same.

Ours was

Uncaught exception 'Error' with message 'Call to a member function getName() on null' in vendor/magento/module-catalog-import-export/Model/Import/Product/CategoryProcessor.php:90

when trying to import products

The problem was due to category entities existing when their linked parent category no longer did. There is a related github issue here. Our solution was not to modify any code but to fix the underlying data issue by finding these problem categories and removing them.

I suggest you first find the problem categories to get an idea of how bad the problem is:

select * 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

Notice the and c.entity_id != 1 this is because the root category does not have a parent but we do not want to delete this. Next if you're comfortable that the resulting categories should no longer exist then we can delete them:

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

Obviously we are deleting entities from the database here so this should be done with caution. If possible test on a development environment first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.