Table of contents:
How to export product CSV in Magento 2
Magento has a default module for importing and exporting products – Magento_CatalogImportExport. In addition to it, there are many modules from third-party developers that allow you to set up a more flexible import and export of products (for example, Google / Facebook and other product processing systems).
Step #1: Log in to the admin panel and navigate to System -> Data Transfer -> Export.
Step #2: Select Entity Type -> Products. Export File Format is available in CSV format.
Step #3: Set Fields Enclosure at Checked to prevent the export of incorrect symbols, like equal sign, more and less characters, single and double quotes, backslashes, space characters and ampersands. The system will enclose them in double quotes to avoid data export problems.
Step #4: Set up export configurations.
When exporting products, it is possible to filter products by the list of attributes. For instance, if you set up the SKU field at TEST, only products that have the word TEST in their SKU will be exported.
You can also exclude certain attributes from export by checking the Exclude checkbox to the left of the name.
Bear in mind that currently you can not export products for a certain website or store, because Magento exports all products.
Step #5: Press the Continue button and export a product CSV file.
How to import product CSV in Magento 2
Step #1: Log in to the admin panel and navigate to System -> Data Transfer -> Import.
Step #2: In the Entity Type field select Products.
Step #3: Create a product CSV file.
Click Download Sample File to upload the sample of how to fill in the CSV product import file. Use the UTF-8 coding while creating or editing CSV file to avoid validation issues during the import.
Magento has several scenarios of product import:
- Add/Update – Magento checks the availability of products with the specified SKU. If no match to the SKU is detected then new values are added to the product, and in case no such product exists, the system creates it.
- Replace – product attribute values are substituted for the new ones.
- Delete – if there is a product with a certain SKU in the import file, the product is deleted from Magento.
Moreover, Magento implements several error processing algorithms. When you use the Stop on Error option, any file validation error will not allow to run the import. There is a Skip error entries function allowing to specify the variety of errors you can run the import with.
By default, Magento uses comma to separate values in CSV file (Field separator), yet you can specify another separator you used to create or edit import file. Similar to this, you can set up a Multiple value separator.
To prevent incorrect data import, like equal sign, more and less characters, single and double quotes, backslashes, space characters and ampersands, check the Fields Enclosure. This way Magento will add additional double quotes to prevent special symbol import.
Step #4: Specify the CSV file in the Select File to Import field.
Magento allows to import files with a limited number of fields, only the required ones. If you do not need to fill in all the fields you got as a result of product export, specify only the required ones: sku, product_websites, product_type, attribute_set_code, categories, name, price, qty, additional_attributes.
In case you need to import images as well, you need to specify the path to the folder with media files. If you import images from the local server, specify the path relative to the current Magento installation, for example, var/media/import_products or the standard pub/media/import. The folder should have the same image path structure as the import file (if in the import file the path is /9/4/94111017_2_5.png, them physically the picture is located at var/media/import_products/9/4/94111017_2_5.png.) When you import from the cloud server, you specify the complete image address.
When importing products, it is also possible to create the structure of categories specified in the categories field. Bear in mind that the categories must be created in accordance with the specified hierarchy, for instance if you have a value for categories field All Products / Main / Second, then Magento will create the All Products category first, then create the Main one as a child for her and after that Second as a child for Main and assign a product for these categories. If there is a parent category, then Magento will add children for her. If all categories exist, then the product will simply be added to these categories without creating new ones.
Some products require additional attributes import, for example, the ones created by the admin. During the CSV export the fields are united in a single additional_attributes field. Such format is not very useful for editing or adding new attributes, therefore, it is better to create separate columns for each attribute and specify their values there.
If you import grouped products, you need to specify SKU values in the associated_skus field, like in the example below. For configured products, fill in the configurable_variations fields (in the format sku=PRODUCT_SKU, attribute=value|sku=PRODUCT_SKU2, attribute=value2) and configurable_variation_labels). Similarly, specify the values for bundle items in the bundle_values field.
Step #5: Press Check Data to validate the import file.
Step #6: In case there are no errors or they are included into Allowed Errors Count, you can import Magento CSV product file.
Magento 2 import common validation errors
1.Incorrect value of the select fields. To resolve it, find the values of the attribute at Stores -> Attributes -> Product and compare with the ones specified in CSV file.
2. Images loading errors. The reason may lie in the physical absence of images at the server (in the specified Images File Directory folder), or in incorrect rights for the files and folders, or in the incorrect path.
3. Different number of fields and product info. This happens because Magento processed the CSV file incorrectly. Check the separators and double quotes in the CSV file and if some of them are absent, add the missing signs.
4. Errors with URL Rewrites. This error occurs when another product has the same URL rewrite as we try to import or other custom URL rewrite. The solution is to add any postfix into the import file or delete the conflicting URL Rewrite.
5. Incorrect product_type. One of the reasons the issue occurs is the use of third-party modules for defining new product types or incorrect values in the product_type field. The solution is to check the data in the import file or install a third-party module that this type of products adds (if not installed).
6. Incorrect visibility. The reason for it is using invalid values for the visibility field. The solution is to use standard Magento text values (Not Visible Individually => 1 / Catalog => 2 / Search => 3 / Catalog, Search => 4).
7. Incorrect store. Occurs due to the absence of the configured store or an error in the field data. The solution is to check if this store exists and create the store if it does not. Moreover, check whether the values of field and store identifier values correspond.
8. Incorrect separator or format. The error occurs when the file is created with the separators different from the ones specified in the import. The solution is to check what separator is in CSV file and specify the same in the import configuration.
Wrapping it up
From the article you have learned how to import and export product data in Magento, as well as got acquainted with the most common import validation errors. If you have any questions or comments, please leave them down below.