User Tools

Site Tools


Sidebar

magento_2:import_products

For more details see how the Import Products for Magento 2 extension works.

Guide for Import Products for Magento 2

Set connections to 3rd-party systems and marketplaces with the help of Import Products for Magento 2. Automatically sync different product bases, regularly update prices or stock quantities, import new product categories and reviews.

  • Automate stock updates from third-party vendors
  • Use 4 formats and 8 import sources
  • Import any product data by mapping the fields
  • Prevent errors with the validation system
  • Configure performance settings to migrate huge volumes of data
  • Import products to Magento 2 from XML feed
  • This extension is included in the all-in-one Import & Export M2 solution
Download the sample data in CSV, XML, ODS and XLSX formats: sample-product-files.zip

The Import Structure

Amasty Import by now has 3 separate modules to carry out import tasks:

  • Import Products: a separate interface to import product entities regularly using profiles
  • Amasty One-time Import: suitable for a one-time import of any available entity
  • Amasty Import Cron Jobs: a tab to create cron jobs concerning import activity

The more Amasty import modules you have, the more entities you will be able to manage in the simplified module and in the Cron Jobs version. Follow Import & Export solution updates to discover new possibilities.

Import Products Configuration

Before building import profiles, configure the basic import performance options.

Go to Stores → Configuration → Amasty Extensions → Import Products.

General Settings

Import Batch Size - set number of products that will be processed in an iteration.

Import History Auto-Cleaning - choose Yes to clean logs automatically. The records will be removed from Import History after the period specified below.

Auto-Cleaning Period (Days) - define the period after which import history will be cleaned.

Multi-Process Import

Enable Multi-Process Import - enable this option to perform import in multiple threads and speed up the import process.

The 'Multi-Process Import' feature requires the PHP extension 'pcntl' to be installed on the server. If you enable the feature and no performance boost happens, please ask your hoster/system administrator to check if the 'pcntl' extension is installed.

Number of Parallel Processes - if the previous option is enabled, specify the number of processes according to your server capabilities. The more parallel processes are set, the faster the import process goes, but the higher the load on the server is.

Keep in mind, that the multi-process for Amasty One-time Import and Amasty Import Cron Jobs should be enabled in the other tab.

Import Products Profiles

The extended product import functionality allows you to create flexible profiles for import and execute it on regular basis. To view all the profiles, proceed to System → Import Products → Profiles.

Here you can see all existing profiles, their IDs, names, file formats, execution types and the dates of the last run/update.

Troubleshooting

Before starting the configuration, please, check the key aspects of the successful product import below:

  • When working with configurable, grouped or bundle products, you should import the related Simple products first. Only when all simple products are imported, you can start importing the configurable ones.
  • Make sure the websites and store views are the same on import and export instances.
  • Attributes and attribute sets should be the same on the import and export instances.
  • When adding some attributes to a product manually on the export instance, these attributes are automatically pulled into the attribute set. But before importing, you need to assign them manually to the corresponding attribute set on the import instance so that the values ​​of these attributes are matched during import.
  • If you are going to import Magento bundle products or other configurable products, you should also pay attention to whether the attributes of the simples are included in this set attribute. If not, you should add them manually. For example, we've selected the Default attribute set and created simple products with the color and size attributes. In this case, we need to add these attributes to the Default attribute set manually, so that the simple products could be assigned to the configurable one.
  • If you use the Delete behavior, it is better to disable all unnecessary fields and use only sku or row_id.
  • Make sure that the Entity Key Delimiters are the same in the import configuration and export file. It is not recommended to leave this field empty.

Troubleshooting: Import Images

You can import product images in several ways:

  • To import single images, you can either provide the links to the images in the import file, and the extension will automatically download and import them, or place images in a particular folder on the import instance and specify the path to this folder in the file.
  • Importing a few images at once to the Images and Videos folder can be carried out with the Product Media Gallery entity. For this import, it is necessary to place images in a particular folder on the import instance and specify the path to this folder in the file.
Please note that you can import images through the Product Media Gallery entity only if the Merge Rows into One feature is disabled. To check the setting, go to System → Profiles → Import Profiles → Choose the needed profile → Edit Profile → File Settings.

New Profile Creation

Let's consider the case of new profile creation. For example, we want to set automatic import of new simple products.

Please, remember that you should upload configurable products only AFTER the simple ones. It means that it's necessary to import the simple products relative to the configurables first, and only then you can import the configurable ones themselves.

First of all, hit the Add New Profile button.

You can duplicate the already created profiles if you want to build a profile similar to the existing one.

Sample Files

To avoid mistakes and complete configuration faster, you can use sample files.

To download it, fill in the required fields for profile creation (such as Name, Import Source, etc.). If you have no fields added yet, the file will include all possible data. If you want to generate a specific sample file, proceed to the Fields Configuration first so that the generator could compose a relevant file including only those fields that you've added.

General Configuration

Profile Name - specify the name of the profile for internal usage. This name will be displayed in the grid.

Batch Size - set the number of products that will be processed in an iteration. You may configure batch size for each profile separately or specify the value in general configuration and use this default value.

Reindex After Importing - enable this option to run reindex automatically after the import.

Disable Products Not in File - activate this feature if you want to enable the products from the import file and disable the already existing ones on your instance (for example, in cases you want to completely update the product catalog and show only imported products on the frontend).

Please note: If the setting is enabled, reindex will be performed in importing to make the products invisible on a storefront.

File Settings

Now we need to choose the required file type and configure its settings.

The following formats are available:

  • CSV
  • XML
  • JSON
  • ODS
  • XLSX

For CSV, ODS and XLSX formats you can:

Rows Merged into One - enable this option if the rows in the import files are merged.

For a CSV file you can additionally set:

  • Merged Rows Data Delimiter
  • Field Delimiter
  • Field Enclosure Character

For a JSON file you can additionally set:

  • Header
  • Items Container Name
  • Footer

For a XML file specify the path to the node in the Data XPath field, e.g. if you have <items><item>1</item><item>2</item></items>, the path will be items/item.

XSLT Editor

The extension includes an XSLT editor so that you could import XML files with any custom formatting. Using this functionality, you can create custom templates for XML documents and add, remove, rearrange or sort elements in the file.

What is XSLT?

A lot of 3rd-party platforms you are integrating with use custom XML table formatting. Magento itself can't import such files since it is impossible to match the attributes with the custom names properly. XSLT (Extensible Stylesheet Language Transformations) helps to interpret the document, match the values in the file with the Magento database and import data correctly.

Find out how the XSLT works in this tutorial.

Before importing a custom XML file, review the formatting and find out how the attributes provided in the document are named and structured in Magento. Then, create an Xsl Template to match the values.

To simplify template creation, download this ready-made sample file: xsl-template-for-import.zip


We've chosen a CSV format.

You can download sample files for the appropriate file formation.

Import Source

Now choose a suitable import source and specify the path for images if the file does not contain the links to the media files.

IMPORTANT: please, copy all product images to any folder of the instance you are importing to. Specify the path to the folder in an appropriate field and only then start importing. Alternatively, provide the links to the images right in the file so that the extension could automatically download them.

Available sources:

  • Local Directory
  • File Upload
  • FTP
  • SFTP
  • URL
  • Google Sheets
  • REST API Endpoint
  • Dropbox
  • Google Drive

For Local Directory specify a File Path relative to Magento installation (e.g. var/import/import.csv).

For File Upload select the file to import. Make sure your file isn't more than 2M and it is saved in UTF-8 encoding for proper import.

If you want to use FTP / SFTP for import, you will need to fill the following fields:

  • Host
  • User
  • Password
  • File Path
  • File Name for FTP/SFTP.

For FTP you can also enable a Passive Mode.

For URL source, apart from the URL itself, provide Basic Authentication Username and Password.

The document should be opened by a direct URL, and the URL should contain the file format, e.g. https://example/download?id=19&file=-1.xml (here we use XML format). It is necessary since in Google Cloud the link to the file is used without an extension, and the Import Products extension can't validate it. Thus, you need to add the format. Additionally, if the access is shared for all users, then the username and password fields are not required. If only certain users can see the file, then you need to enter their credentials for access.

For Google Sheets specify the required URL.

When using Google Sheets (you can import a file of different formats there), you need to specify the required format and specify the same format when importing. The link to the doc should be shared with everyone.

For REST API Endpoint provide the endpoint (e.g. https://magento.instance/rest/all/V1/some/endpoint) and choose the required authentication method.

Keep in mind that only CSV и XML file types can be used when importing with Rest API Endpoint.

Dropbox Configuration

To import using Dropbox, you will need to provide the access token. Follow the steps below to get the token.

1. Go to https://www.dropbox.com/developers and sign in.

2. Hit the Create Apps button.

3. Choose an API, a type of access you need and specify the title for your folder.

Agree with the terms & conditions and click Create App. You will be automatically redirected to the folder configuration.

4. Proceed to the Permissions tab.

Grant the permissions to write the files and click Submit.

5. Return to the Settings tab.

6. Find the OAuth 2 section and hit the Generate button below the Generated access token field.

7. Copy the token and paste it into the Generated Access Token field.

Google Drive Configuration

To set the integration with Google Drive, you need a specific API key. To get the key and configure this import source correctly, follow the steps below.

1. First of all, you need to install Google APIs Client Library on your Magento instance. Click here and install composer require google/apiclient:“^2.0”.

2. Go here and choose a project or create a new one if necessary.

3. When the required project is chosen, return to this page and enable Google Drive API.

4. If everything is correct, you will see the following status:

5. Click Manage and proceed to APIs & Services → Credentials. There click Create Credentials →Service account.

6. Provide Service account details. You can skip Step 2 and Step 3.

Click Done.

7. Navigate to the Service accounts tab and find the required service. Expand the Actions dropdown and hit the Manage keys option.

8. Expand the Add Key dropdown and select Create new key.

9. Choose JSON file format and hit the Create button.

The file will be automatically generated and downloaded.

10. Proceed to the Details tab and copy the email.

11. Go to My Drive. Create a folder from which the files will be imported to Magento. Specify the title.

12. Now click Share and insert the email that you've copied. Click Done.

13. Return to the admin panel. Upload a JSON file, provide the path to the created folder and file title.

The configuration is ready. Run import profile and check the result.


As we already have a CSV file to import, we've chosen the File Upload option.

Import Settings

In this tab, you can adjust import behavior.

Import Behavior - choose a suitable behavior for import:

  • Add/Update - in this case, the extension compares product IDs from the import file and the already existing products in the Magento instance. If a product ID is unique and doesn't exist in Magento, a new product will be created. If a product with the same ID already exists, the extension just changes/adds the data specified in the import file.
  • Only Add - the extension imports products with new IDs and skips the already existing ones.
  • Only Update - the extension updates the information in the existing products and skips not existing ones.
  • Delete - the extension deletes the products specified in the import file from Magento.

Enable Autofill for Typical Use Cases - if enabled, Fields Configuration will be automatically filled in with the settings to perform the typical use cases for importing products from third-party systems. The setting can be used only during new profile creation.

Each behavior has a specific pull of the required fields, e.g. if you add new products, your import file must contain more columns than in the update behavior. Please, enable the autofill option to avoid errors during import and map fields properly.

Product Identifier - choose Product Entity ID, Product SKU, or Custom Attribute as an identifier.

Product Entity ID is the ordinal number in the database provided by Magento, e.g. 45. Product SKU is a unique identifier, that can contain letters as well, e.g. MG-9856.

If you select Custom Attribute as a product identifier, the dependent Product Identifier Attribute setting appears and you can specify the exact attribute to use as the main identifier:

  • Product Name
  • SKU
  • Meta Title
  • URL Key

Validation Strategy - you can either stop the import process if any error appears (Stop On Error option) or skip invalid data and continue importing (Skip Error Entities option).

Please, note that if you Skip Error Entities and some configuration issues exist, the extension will complete the import with a 'Success' status, but 0 products will be imported.

If you choose Stop on Errors option, the status will be 'Failed'.

Allowed Errors Count - specify the number of errors to halt the import process.

Fields Configuration

In this tab, you need to choose the required entities and map fields. If you enabled the Autofill for Typical Use Cases option previously, the required fields will be automatically added and you can proceed to mapping. If the option was not enabled, you need to add the entities and fields manually.

Please, attentively check all the fields before importing. Otherwise, the extension won't be able to match the columns and will display an error.

The functionality has a tree structure. Thus, you can add any entity, any field within a particular entity, customize entity keys/field names/delimiters and so on to match the requirements of the import.

See how the tree-structure configuration is created:

Below you can see all available for importing entities:

Apart from adding required entities and fields, you need to map all required fields and additional fields that you want to import from the file.

Let's see how to configure the mapping.

First of all, open your import file and check how it is configured. Pay attention to column names and delimiters.

As we see, in our file all columns of the root entity have a custom entity key - simple.

In this case, we need to provide the same entity key in the fields configuration.

Then we check the delimiters. In our file we have a slash as the delimiter:

Thus, we need to specify the same delimiter in the configuration:

If ready, proceed to column names.

In the configuration, we see that the entity_id, attribute_set_id, type_id, sku, has_options and required_options are the required fields (as they were autofilled for the add/update algorithm).

Now we check if we have the same columns in our import file.

Here we see that 5 out of 6 columns are present, but some of them have a different column name, e.g. instead of attribute_set_id we have just set_id, and instead of type_id we see just type. In such cases, we should match the titles from the import file with the titles in Magento.

If the titles are identical (as we have for the entity_id, sku and required_options columns), just leave the Import File Field empty.

If you check all fields and see that some of the required ones are absent in the import file, set the Default Value. For example, Magento requires has_options column, but we don't have this one in our file. In this case, we can just provide the required value in the Default Value field (e.g. 1).

This way, you need to check all fields and map the titles so that the extension could import products properly. Add any entities and provide custom entity keys if needed.

To add the fields, click Map Fields and choose the necessary ones in the modal window. Use the search field to speed up configuration.

When the configuration is ready, upload the file in the Import Source tab. Click Save and Continue Edit.

Now you can Validate the file.

The extension will display validation progress and results in a popup window.

If the configuration was incorrect, you will see an error.

In case of successful validation, you can start the import.

Modify Values Before Import

Now you can use modifiers to change the values specified in a file before importing. For example, you can change the date format, add any text and apply various mathematical actions to prices (e.g. rounding, multiplication, etc.).

Modifiers are added right during the fields configuration.

Hit the Add Modifier button and choose the required action in a dropdown.

Types of modifiers you can use:

  • Text Modifiers: Adjust the text of the text values by appending, prepending, capitalizing, etc.
  • Numeric Modifiers: Use for number modifications, e.g. rounding prices.
  • Date Modifiers: Specify a suitable date format.
  • Custom Modifiers: Replace the output of one field with the value of another.

Text Modifiers

Append - Adds the text after the value in the column. The text is specified in an additional field that appears when this modifier is selected.

Prepend - Adds text before the value in the column. The text is specified in an additional field that appears when this modifier is selected.

Trim - This modifier removes spaces from the beginning and the end of the string (there is already a trim).

Upper Case - After selecting this modifier, the entire word in a value field is capitalized.

Lower Case - After selecting this modifier, the whole word is written in lowercase.

Capitalize - After selecting this modifier, the value in the column is capitalized.

Capitalize Each Word - After selecting this modifier, each word starts with a capital letter.

Strip Html Tags - Modifier removes all HTML tags from the string (the modifier is useful when importing meta titles, descriptions, etc.).

Replace - After choosing this modifier, 2 fields appear: in the first one we indicate the word that needs to be replaced, and in the second one - the word to be replaced with.

Full Match Replace modifier functions similarly to the Replace modifier. However, it only replaces the value from the first field (From) with the value from the second field (To) when the value from the first field is fully matched.

For example, if you specifically need to replace only '2' with '3', it's better to choose the Full Match Replace modifier. This is because if you opt for the Replace modifier instead, specifying From: '2' and To: '3', it might result in '122' being replaced with '133' due to the presence of '2'.

Replace First - the same as Replace, but for the first case only.

Numeric Modifiers

Absolute Value - Modifier changes the negative value in the column to positive. Example: was -5 → now is 5.

Round To - When this modifier is selected, an additional field appears, in which we indicate the number of decimal places to which we round the number in the column. Example: 33.75 → enter 1 → get 33.8.

Plus - When this modifier is selected, indicate the number that is added to the number in the column.

Minus - Indicate the number that is subtracted from the number in the column.

Multiplied By - Specify the number that is multiplied by the number in the column.

Divided By - Provide the number by which the number in the column is divided.

Modulo - Indicate the number by which the number in the column is divided, and when division occurs, we get the remainder of the division in the export file. Example: we have 10, entered the number 3, received 1 in the file.

Truncate - Modifier removes decimal numbers without rounding. For example: 33.75 → Truncate → 33.

Ceil - Modifier allows you to round a number up to the nearest whole number.

Floor - Modifier allows you to round a number down to the nearest whole number.

Date Modifiers

Date Format - Specify the date format that is applied to the date in the file.

Custom Modifiers

In some cases, custom modifiers replace the output of the value of one field with the value of another. For example, Option Label to Option Value: instead of label, the value will be imported. Or, for instance, Status Code for Status ID: instead of code, the id will be imported.

Moreover, in some product import cases, you can utilize the Create New Attribute Value modifier. This modifier assists in importing specific attribute values, even if they do not already exist in the system.

For instance, if you import a product with the value 'purple' for the color attribute, but such a value hasn't been created in your Magento system, it will be automatically generated after the import when using the Create New Attribute Value modifier.

Please note that the Create New Attribute Value modifier can be used only alongside with the Add/Update and Only add options of the Import Behavior setting.

Import Filters

In this tab, you can filter products and import only required ones. For example, import the products of the Gear category only.

Filtering duplicates the field configuration structure, which means that you can filter data by any field you've added.

Additionally, you can use specific filters for the Date parameter, e.g. upload products created in the last X days or weeks.

Automatic Import

If you have configured the mapping and the products were imported successfully, you can set the automatic import of future products.

Run Profile by Cron - if enabled, the import will be initiated automatically by cron according to the schedule specified.

Frequency - choose a suitable import schedule.

If you choose a custom one, provide the schedule manually.

Alert Notifications

Using this tab, you can enable email notifications about errors for a particular profile.

Enable Email Alert - set to Yes to notify the recipients about failed imports.

Email Sender - choose the contact that will send automatic emails.

Email Recipients - set to whom the emails will be sent.

Email Template - select the template for failure notifications.

Profile Import History

For each profile a separate import history is available. Check the statuses, dates and logs.

General Import History

You may also check the logs for all import profiles in one place. Navigate to Amasty → Import Products → History. See the statues and check details to get a full picture.

REST API and CLI requests

It is possible to run import and export profiles using the REST API and CLI.

REST API:

  • “/V1/am_import_export/get_profile_runners/” method=“GET” - to get available profile runners
  • “/V1/am_import_export/run_profile/” method=“POST” - to run a profile
  • “/V1/am_import_export/check_profile_status/” method=“POST”- to check profile status

CLI:

  • php bin/magento am-import-export:show-profile-runners-list
  • php bin/magento am-import-export:run-profile product_import_profile 1
  • php bin/magento am-import-export:check-profile-status product_import_profile %identity_from_run_command%

Amasty One-time Import: Fast & Easy

This extension is helpful to perform one-time operations as it has a simplified UI. If you have only the Import Products extension, you will be able to import any product entity, but if you will have other import extensions by Amasty, you will easily import any available entity in one place.

Go to System → Amasty Import → Import and select the entity to import.

As soon as you choose the entity, you will be able to configure import details, such as format, title, included fields, etc. Check each configuration detail for each tab in the Import Profile Configuration sections.

General Settings for One-time Import

To configure the basic options for Amasty Import, navigate to Stores → Configuration → Amasty Extensions → Import.

Enable Multi-Process Import - set to Yes to speed up the import.

The 'Multi-Process Import' feature requires the PHP extension 'pcntl' to be installed on the server. If you enable the feature and no performance boost happens, please ask your hoster/system administrator to check if the 'pcntl' extension is installed.

Number of Parallel Processes - specify the number of processes according to your server capabilities. The more parallel processes are set, the faster the import process goes, but the higher the server loads.

Enable Debug Mode - set to Yes to allow the system to detect errors and display detailed information about them in the popup (including server errors). Also, error information can be found in var/log/amasty_import_debug.log.

Enable Import without Memory Limit - enable the setting if the import process terminates because the memory limit exceeds to allow using all available memory volume for the import process.

CLI PHP Path - using this option, you can check the Magento path which is used by our extension when running the commands directly during the processing of PHP requests. To change it, please run the following command:

bin/magento config:set amasty_base/system/cli_php_path %CLI_PHP_PATH%
If you run a command and a new path is not displayed in this setting, please recheck the path you've specified. In case the path is incorrect, the changes won't be applied to the admin panel and you'll see the default path.

Amasty Import Cron Jobs

Also, the extension includes Amasty Import Cron Jobs features: you can create regular cron jobs to import any available entity.

Go to System → Amasty Import → Cron Jobs.

The more installed Amasty Import extensions you have, the more entities you can import by cron.

Click New Import Job.

Specify the cron job title for internal use and set the schedule for importing. The file configuration algorithm is the same as described in the Import Profile section.


Find out how to install the Import Products extension for Magento 2 via Composer.
Rate the user guide
 stars  from 2 votes (Details)
magento_2/import_products.txt · Last modified: 2024/03/13 10:39 by kkondrateva