How to Import Related Products to Magento 2?

- Fire development, Magento 2

Magento 2 Development; Magento 2 tutorial

The following article is based on a StackExchange question by Guest. The author asks how to import related products to Magento 2. Although the desired functionality was added to the new platform version, you may still face certain issues moving this data type to your store.

Even if a CSV file has a row with the related_skus attribute with the specified data for a product, the default import process may not be flawless. If in admin under Products->Catalog the imported product contains no related products in the Related Products sidebar tab but those products exist in the catalog with SKUs, you’ve come to the right place.

Raul Sanchez provides the possible solution to the problem. He assumes that the default import module has some kind of bug with related products. Raul’s solution is based on a new console command.

The command expects a 2-columns related.csv file in the var folder. The columns are parent SKU & children SKUs. A comma is a CSV separator, and a pipe is a children_skus separator.

Below, you can see the corresponding files. Replace Sinapsis with your vendor name, and Sync with the module name. After installing the module, run bin/magento setup:upgrade & you’ll see the new command under bin/magento list. Execute it by running

Also, note that since the 2.2 version, there are 2 changes required: an extra line before saving $product. This, you will prevent this issue.

Besides, it is necessary to change admin to adminhtml in

Note that the first change is innocuous for older Magento 2 versions. The second one may be harmful. Therefore, the following code contains only the first change:

app / code / Sinapsis / Sync / etc / di.xml

app / code / Sinapsis / Sync / etc / module.xml

app / code / Sinapsis / Sync / registration.php

app / code / Sinapsis / Sync / Console / Command / RelatedCommand.php

It is a quite complex solution, isn’t it? You can essentially simplify the way you import related products to Magento 2 with our Improved Import & Export Magento 2 extension. The module extends the default functionality of the platform and adds lots of new features to product import. Since related products are supported by default, our extension also allows moving them to Magento 2.

Besides, it enhances product import with the ability to create a schedule for fully automated updates; the mapping functionality to match all third-party attributes to default attributes of Magento 2; hardcoded values for selected attributes, etc. For further information, follow the link below:

Download/Buy Improved Import & Export Magento 2 Extension

We hope the article was useful. For other useful Magento 2 tips, check out our Cookbook.