Magento 2 CSV Import: Import Products In Magento 2

Magento 2 CSV Import: Import Products In Magento 2

Are you looking to streamline your product management? Magento 2 CSV import feature allows you to import product data, images, and attributes.

This tutorial will cover how to prepare your data, use the import process, and handle common issues.

Key Takeaways

  • Choose products and import products to Magento 2.
  • Use the default Magento 2 import product to a specific attribute.
  • Magento product type configuration in the Commerce server or Magento server.
  • Insights into generating URL keys automatically based on a product attribute in the Magento 2 store.
  • Overview of how to update products to the default location on the Magento server.
  • Steps to import products specified in the location on the Magento server.

Prerequisites For Importing Products CSV File Structure

Magento 2 admin panel showing the prerequisites for importing products CSV file structure

1. New Entities

Entities are created using the attribute values provided in the CSV file, such as:

  • If a required attribute lacks a default value and no valid value is provided, the entity (the corresponding row or rows) cannot be imported.
  • If a required attribute has a default value and no valid value is provided, the entity will be imported with the default value set for that attribute.
  • If complex data is invalid, the entity (the corresponding row or rows) cannot be imported.

Note: Examples of complex data include configurable products, custom options, and tiered pricing.

2. Existing entities

For non-complex data attributes, values from the import file will replace existing values. For example, empty values for non-required attributes. Check the following preconditions for this-

  • If a required attribute lacks a value or has a non-valid value, the existing value will remain unchanged.
  • If the entity's complex data is invalid, the entity (the corresponding row or rows) cannot be imported. This can be done unless the "Delete Entities" option is selected in the Import Behavior drop-down menu.

Note: Add/Update is most appropriate during regular inventory updates. Use Replace during the complete catalog overhaul.

3. Complex data

If an attribute in the import file exists and its value is derived from a predefined set of values, the following applies:

  • If the value is not included in the predefined set, the row can be imported and a default value (if defined) is set for the attribute.
  • If the value is already included in the predefined set, the corresponding row cannot be imported.
  • If the import file specifies an attribute name not yet defined in the system, it is not created, and its values are not imported.

4. Invalid files

  • A file cannot be imported if all rows are invalid.
  • If a non-existing service data or complex data name is specified in the import file, the import will fail. For example, a column with a _<non-existing name> heading.

Note: Adobe Commerce’s import process may not recognize files encoded in UTF-8 that use a Byte Order Mark (BOM). Files containing a BOM can cause issues or failures during the import process.

Import Process Operations For CSV File Update

Operation Description
Add/Update - Adds new product data to existing product entries in the database
- Updates all fields except SKU for existing products
- Automatically creates new tax classes, product categories, and SKUs provided in the import file
Note: Multiple field values cannot be removed using this behavior. For example, websites and categories. They will remain in the database if not listed in the CSV file
Replace - Replaces existing product data with new data from the import file
- Deletes all fields, including SKU, for matching entities and creates new records using CSV data
Note: Existing product data is cleared, and all references in the system are lost
- Errors occur if the CSV file references a non-existent SKU in the database (use Check Data to display errors)
Delete - Deletes entities from the database that exist in the import data
- Ignores all columns in the import data except for SKU
- Other attributes in the data can be disregarded
- Errors occur if the CSV file references a non-existent SKU in the database (use Check Data to display errors)

Steps To Configure Import And Export Inventory

Step 1: CSV file directory content

The export-import file contains the following information for each source:

  • source_code: The code for sources in Magento, with a row for each source and SKU.
  • sku: The product SKU in Magento, which must match an existing product in your store to update Inventory Management data correctly.
  • status: "0" indicates Out of Stock, "1" indicates In Stock. This value must be 1 to allow stock purchases from this source.
  • quantity: The total inventory available for this SKU and source.

Magento 2 admin panel with CSV file directory content settings for product import

Note: Use this option to update multiple products and their assigned sources efficiently. Correct any inaccuracies in inventory reports. Do this without individually updating through the application interface. For a base file, export first and update as necessary.

Step 2: Export product data from Magento 2 for all sources

  1. On the Admin sidebar, navigate to System > Data Transfer > Export.
  2. From the 'Entity Type' menu, select "Stock Sources".
  3. The export will only include data for products with an SKU.
  4. Click on 'Continue'.
  5. The file will be generated and downloaded for you to open and edit.

Magento 2 export settings for product data from all sources

Note: Once you've updated and managed the inventory amounts and product data, import the file back into Magento.

Step 3: Export products from Magento 2 for a specific source

  1. On the Admin sidebar, navigate to System > Data Transfer > Export.
  2. From the 'Entity Type' menu, select "Stock Sources".
  3. The export will only include data for products with a SKU.
  4. Use the "Entity Attributes" to filter the exported products by a specific source.
  5. In the source_code filter field, enter the code for the desired source.
  6. Click on 'Continue'.
  7. The file will be generated and downloaded for you to open and edit.

Magento 2 export products settings for a specific source

Note: After updating inventory amounts and product data, import the file back into Magento.

Step 4: Magento Import products data

  1. On the Admin sidebar, navigate to System > Data Transfer > Import.
  2. From the 'Entity Type' menu, select "Stock Sources".
  3. The export only retrieves data for products with a SKU.
  4. Configure the 'Import Behavior' settings as needed.
  5. Choose the .csv file to import.
  6. Click on the 'Check Data' button to complete the import process.

Magento 2 import settings for importing product data

Advanced Techniques For Importing Sample Products From The CSV File

1. Optimizing Product Images for Efficient Import

The size and storage location of your product images can impact the speed of your Magento 2 import products. To ensure optimal performance, consider the following:

i. Store images in the appropriate directory within your Magento 2 installation. For example, the /pub/media/import folder. If your images are hosted elsewhere, provide the full URL path in your CSV file. ii. Compress and resize images without compromising quality. Utilize tools like Adobe Photoshop or online image optimization services to create web-ready images. Smaller image files contribute to a reduced-size import file. This results in faster and more efficient imports. iii. Utilize specific tools or techniques for batch-processing images before import. Leverage some of the recommended image dimensions for different types of product images. Examples include thumbnails, main product images, and zoomed images.

2. Streamlining Product Descriptions

Providing comprehensive product information is essential. However, lengthy descriptions can increase the size of your import file. They can also slow down the import process. To optimize your product descriptions:

i. Focus on key features and unique selling points for each product. Aim to convey the necessary information concisely. ii. Limit descriptions to a range of 150 to 255 characters. This ensures that your short description of a product remains informative. It also maintains a manageable file size. Concise descriptions also improve readability for your customers.

3. Verifying and Testing Sample Products

After completing the import process, verify the accuracy and functionality of the imported sample products. Follow these steps:

i. Confirm that the sample products appear correctly in your catalog and admin product grid. ii. Spot-check individual product pages to ensure that attributes and images are displayed accurately. iii. Test the functionality of adding sample products to the cart and proceeding through the checkout process. iv. Verify that sample products are not appearing in search results or category permissions.

Note: Verify if all checks are successful. Then, proceed with refining your import process and settings before importing live products.

4. Cleaning Up Sample Products Post-Testing

Once testing is complete, remove the sample products from your store. This maintains a clean and accurate catalog. Follow these steps:

i. Export a CSV file containing only the SKUs of your sample products. ii. In the import settings, select "Delete" instead of "Add/Update". iii. Choose the CSV file with the sample product SKUs. iv. Execute the import process to mass delete all the sample products.

Troubleshooting Magento Import Data In The CSV File

1. Resolving CSV Data Format Errors

  • Use a spreadsheet tool like Google Sheets or Excel to edit CSVs (not a text editor).
  • Ensure column headers exactly match Magento's expected attributes.
  • Check that all required fields for your product type are populated.
  • Use consistent capitalization and spelling for attribute values.
  • Enclose any data with commas or quotes in double-quotes.

Note: If you encounter additional errors, export a new CSV template from Magento. Then, copy your data into the fresh template. This ensures your column headers and formatting are correct.

2. Handling Image Import Issues

  • Image filenames in the CSV exactly match the uploaded image filenames.
  • Correct paths to images on the server are specified.
  • Image file extensions are all lowercase (.jpg, not .JPG).
  • Image directory and file permissions are set to readable by Magento.

Note: Magento looks for images in the /pub/media/import directory by default. However, you can also specify an alternate image directory in the CSV.

3. Optimizing Large Magento 2 CSV Imports

  • Split your CSV into smaller files of 1,000-5,000 products each.
  • Import files one at a time to avoid server timeouts or memory limits.
  • Ensure the PHP memory_limit configuration is set high enough.
  • Use Magento 2's built-in import queue for asynchronous importing.
  • Run imports during low-traffic times to minimize performance impact.

Note: The key to massive imports is breaking them into manageable chunks. This reduces server load and helps you pinpoint issues faster.

4. Using Magento 2 Import History

If an import fails or results in unexpected data, turn to the Import History. Magento 2 automatically logs all import attempts with key details:

  • Date and time of import
  • Filename of the imported CSV
  • Number of entities (products) imported
  • User who ran the import
  • Import summary with errors and warnings

Note: You can view the Import History under System > Data Transfer > Import History. This is extremely useful for investigating issues and rolling back recent imports.

FAQs

1. What is the default size limit for import files in Magento 2?

The default size of the import file in Magento 2 is typically 2MB. However, this can be adjusted in the Magento 2 core settings. If you need to import larger files, you may need to modify your server settings. You can also split your import into smaller batches.

2. Can I import customer address data along with product information?

Yes, you can import customer data, including address information. However, this is done in a separate import process from product data. Magento 2 allows you to import various data types. Examples include products, customers, and customer addresses. Each type of data requires its own CSV file structure and import process.

3. What is the process for assigning products to specific categories during import?

Include a "categories" column in your CSV file. Use the full names of assigned categories, separated by the appropriate delimiter. Magento 2 product categories are different from Magento 1. Thus, ensure you are using the correct category structure. After import, verify the category assignments in the Magento 2 backend.

4. How is importing product categories in Magento 2 different from Magento 1 ones?

Importing key product attributes in Magento 2 is more flexible than in Magento 1. In Magento 2, you need to specify the attribute set before importing products. You can create custom attribute sets and map them in your import file. Magento 2 also allows for more complex product types and attribute relationships. Check your attribute structure in Adobe Commerce and Magento Open Source before importing.

5. Can I automatically generate URL keys based on a product name during import?

Yes, Magento 2 can automatically generate URL keys of the products during import. If you leave the "url_key" column blank in your CSV file, Magento will create one based on the product name. However, if you want to use custom URL keys, you can provide them in the "url_key" column. Remember that unique URL keys are required for all products in Magento 2.

6. How to import products with images in bulk and make them live in my Magento 2 store?

Use the Magento category import tool to upload products with the images. Ensure your CSV file includes the correct image file names and paths. Go to your Magento 2 admin panel to verify the products with their images. Do not forget to make the products live in-store by setting their status to "Enabled". Also, you can try assigning them to the correct websites and store views.

CTA

Summary

Magento 2 CSV import simplifies the management of your Magento store. It helps you to:

  • Specify multiple images per product more easily, including base, small, and thumbnail images.
  • Review the Magento 2 Product Import template and adjust your data accordingly.
  • Pay attention to new or changed fields that need to be updated for the Magento product import.
  • Test your import related to a small product image to the Magento 2 store.
  • Ensure your images contribute positively to your site's performance.
  • Ensure more flexibility to a smooth transition.

Consider Magento optimized server for using CSV files import product function to add or update the products.

Dikshya Shaw
Dikshya Shaw
Technical Writer

Dikshya leverages her content marketing and writing proficiency to deliver fresh, insightful content. Her meticulous research ensures industry expertise and emerging trends within the Magento landscape.


Get the fastest Magento Hosting! Get Started