Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento 2: Product import does not create sub categories

Tags:

magento2

I'm importing products from a CSV-file. The categories-column of the import file has a value like this:

Store Amsterdam/Lunchbox;Store Amsterdam/Lunchbox/Hot Sandwiches

I've set ";" as a Multiple value separator in the Magento 2 import settings.

Somehow Magento only adds the Store Amsterdam (root) categorie and imports 0 products (Probably because it doesn't reach the destination category).

When I create the sub categories by hand all products import correctly. But I don't want to do this for every 34 remaining stores.

In the report it says: Category "Store Amsterdam/Lunchbox" has not been created. URL key for specified store already exists.

What is going wrong here? Maybe writing permissions on category table? Different Magento user?

like image 520
Rick Avatar asked Jul 07 '17 08:07

Rick


1 Answers

Try to set url key in your import code this way

$_product = $this->_objectManager->create('Magento\Catalog\Model\Product');

$url = <yourcatname>.'_'.$sku;// just to make it unique
$url = strtolower($url);
$_product->setUrlKey($url); 

//now save your product
$_product->save();

This should resolve your issue! Happy customizing!

like image 147
Pallavi Avatar answered Oct 21 '22 10:10

Pallavi