Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product Import Fatal Error: Call to a member function getName() on null #4979

Closed
ljrweb opened this issue Jun 11, 2016 · 16 comments
Closed

Product Import Fatal Error: Call to a member function getName() on null #4979

ljrweb opened this issue Jun 11, 2016 · 16 comments
Labels
bug report Component: ImportExport Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Progress: needs update

Comments

@ljrweb
Copy link

ljrweb commented Jun 11, 2016

Steps to reproduce

  1. Use composer to install 2.0.7
  2. Create sub category tree
  3. Create a configurable attribute
  4. Create a configurable product with 2 variations
  5. Export the products
  6. Re-import the same product file

Expected result

  1. Add/Update products

Actual result

  1. 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
@wert2all wert2all self-assigned this Jun 23, 2016
@wert2all wert2all removed their assignment Jun 23, 2016
@BaDos BaDos self-assigned this Sep 12, 2016
@BaDos
Copy link
Contributor

BaDos commented Sep 12, 2016

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

@BaDos BaDos removed their assignment Sep 12, 2016
@sangthieu
Copy link

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

@LiquidSebbey
Copy link

LiquidSebbey commented Feb 8, 2017

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

@RaitzeR
Copy link

RaitzeR commented May 9, 2017

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; }

@AlexWorking
Copy link

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.

@magento-engcom-team magento-engcom-team added the Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch label Sep 18, 2017
@rajvinoth
Copy link

rajvinoth commented Oct 16, 2017

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

@nkajic
Copy link
Member

nkajic commented Oct 31, 2017

One cause of this error is deleting one or more "core/root" categories by manually deleting from catalog_category_entity.

@webspeaks
Copy link

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 :(

@mamsincl
Copy link
Contributor

mamsincl commented Mar 5, 2018

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

@nishantbkw
Copy link

Same issue in here on 2.2.2

@bvboas
Copy link

bvboas commented Jul 9, 2018

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.

@develth
Copy link

develth commented Mar 19, 2019

Same issue here on 2.3.0 after fresh install

@ShaileshChauhan2
Copy link

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.

@haq0003
Copy link

haq0003 commented Jun 15, 2019

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

magento-engcom-team pushed a commit that referenced this issue Nov 6, 2019
@andrewkett
Copy link
Contributor

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

@jorisssss
Copy link

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

This solved it for me, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: ImportExport Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Progress: needs update
Projects
None yet
Development

No branches or pull requests