Adding products one by one from a Magento store can be time-consuming. You can use a CSV product upload sheet or an extension to expedite this process.
This article will show you how to import and export products in Magento 2 by importing a CSV file. We’re using Magento 2.4.1 version for this article.
How to Import Products in Magento 2
Prepare the CSV file
- In the Magento admin panel, navigate to System > Data Transfer > Import.
- In the “Import Settings,” select Products from the “Entity Type” dropdown.
- Click Download Sample File hyperlink.
- Open the catalog_product CSV file to view its contents. As you can see, the sample file has column headings with sample products data.
- Delete all the sample data except the headings and one example product type for reference.
- Add the following column headings in the CSV file if not present:
base_image
base_image_label
small_image
small_image_label
thumbnail_image
thumbnail_image_label(You can skip this step if you don’t want to add images.) - Add product data in the respective rows and columns of the CSV file.
- Upload product images to your Magento 2 “var/import/images” folder.Note: Starting from Magento 2.3.2, the default root folder to import product images is “var/import/images.” You can also add a subfolder “var/import/images/product_images” for adding the images. Earlier, you could use a different folder as long as the folder path was specified in the “Images File Directory.”
If you’re using an external server, upload the images to the allotted folder and make sure you enter the full URL for all images in the right column by image type. For example http://example.com/images/image.jpg - Confirm the size of the import file is below 2MB.
Set the Import Behavior
- In the “Import Behavior” field, select either Add/Update, Replace, or Delete.
- Click the Validation Strategy dropdown and choose either Stop on Error or Skip error entries to control what happens if an error occurs when importing data.
- Leave the default value of 10 in the “Allowed Errors Count” text area.
- Similarly, accept the default value of a comma (,) in the “Field separator” and “Multiple value separator” text areas.
A comma is the default separator in a CSV file. You can use another separator, but you need to ensure that the CSV file data matches the specified separator. - Accept the default _EMPTY_VALUE_ value in the “Empty attribute value constant.”
- Select the “Fields Enclosure” checkbox to stop importing special characters found in the file data, such as backlashes, equal sign, and space characters.
Add the Import File
- In the “File to Import” section, click Choose File to add the CSV file to import.
- Leave the “Images File Directory” field blank to use the “var/import/images” folder. If the images are in the “var/import/images/product_images” folder, enter “product_images” in the text area.
Verify the Import Data
- Click the orange Check Data button on the top right.
- If the validation process has been completed successfully, you should see the following message:
- Click Import to import the products.
If the file has errors, you’ll see them listed in the error message. Correct them and import the file again. - Go to Catalog > Products, and check if the products with their images have been uploaded.
How to Export Products in Magento 2
- Navigate to System > Data Transfer > Export on the Magento admin panel.
- In the “Export Settings,” select Products from the “Entity Type” dropdown.
- Select the default CSV option from the “Export File Format” dropdown.
- Select the “Fields Enclosure” checkbox to mark special characters as escape sequence so that they are correctly interpreted. This will prevent the export of special characters such as ampersand and pipe, which interfere with data transfer.
- Set up export configurations in the “Entity Attributes” section. This section lists all the attributes in alphabetical order. Use the Search and Reset filters to control which attributes are displayed.
To remove an attribute from the export, select its corresponding checkbox in the “Exclude” column.
To export products with specific attribute values, add the value to the “Filter” column. For example, we’ve added “Long Sleeves” in the SKU field to export only long sleeve products.
- Click on the Continue button in the lower-left corner.
Once the export is successful, you can save or open the CSV file to edit and export it to another store.
Exported files are located in the “/var/export” folder by default. If the Remote storage module is enabled, the files can be found in “<remote-storage-root-directory>/import_export/export” folder.