This article is about how to use the “ImportExport” interface that has been introduced with Magento 1.5 (CE) and Magento 1.10 (EE). I will demonstrate how to import product data via CSV files as well as elaborate on the characteristics of said file format. The main focus of this lecture will be on those functionalities that go beyond importing simple products: multilingualism, categories, tier prices, product images, product links, and grouped products. For further reading I recommend the lecture of the slides of Vinai Kopp’s Imagine 2011 talk. In it, the author explains how to import configurable products and individual options, which is why I will omit those for now, as well as developing custom converters for other file formats.
The ImportExport Interface
The ImportExport module replaces the old Dataflow module, which has been used in earlier versions for importing and exporting data. Both modules only allow the import and export of product and customer data to and from text files. Both modules are accessible both from the backend system and within custom modules. The main advantage of the ImportExport module is its speed, which has been increased considerably. Whereas the old module allowed the import of only a few products per second, the new one imports several hundred products per second.
In order to import product data with the ImportExport module, the data needs to be available in a specific format. Per default, the module only imports CSV files. Using my small FastSimpleImport module and a simple function call, one can also import PHP arrays, which can be generated within a custom module from any data source via PHP. This function call looks like this:
The data that is to be imported needs to be available in a predefined format. For my examples I will use the default CSV format. The same structure can be used for other import methods as well. In general, many characteristics of a file format can be gleaned from exporting existing product data und then taking a look at the resulting CSV file. The import format is basically identical, apart from the fact that the export does not support all functionalities that exist for the import, e.g. grouped products.
For CSV files, the following format applies:
– Column names in the first table row
– Field separator: comma
– Text separator: double quotation marks (optional)
– Character set: UTF-8
A file for importing basic product data can for example look like this:
For clarity I will present the data in a table format:
This table contains the required fields for new products. For existing products, fields can be omitted as preferred, except for the sku field, which is essential for identifying the product in question.
Updating the stock of two products could therefore look like this:
The general rule is that the _type,_attribute_set,and _store columns need to exist for product updates as well; they may however contain the value null if you do not want to overwrite the existing value. For clarity I will omit those columns in the following examples.
Optional attributes (e.g. cost, special_price) can simply be added as additional columns. The same goes for custom created attributes (e.g. color or manufacturer).
As select fields I label those fields that have predefined values, e.g. status (active or deactivated) or color (custom values). While the above listed fields status, visibility, and tax_class_id expect an ID value, other attributes need to be provided with specific option values:
Please note that these attributes require global option values, not localized ones.
Unfortunately, the interface is unable to create missing option values by itself. This will therefore need to be done in a preceding step.
For importing multilingual texts, a new row needs to be created for each store view.
For example like this:
The _store column contains the store view code.
It is important that the sku field is only filled for the first one of those rows pertaining to the product. All further rows will automatically be assigned to that product. This mechanism is also used for other fields that may have several different values. These will be specified below.
Like multiple languages, multiple websites are each listed in a separate row:
Categories are identified by their names (default values), using the complete path, separated by slashes. For example like this:
As above, values are each listed in a separate row.
Tier prices require a number of special fields that can be filled. How to import scaled prices can best be shown by the following example:
In this case, “all” is the default value for “all websites” or “all customer groups”.
Importing product images has only been possible since Magento versions 1.6 (CE) and 1.11. The images that are to be imported need to be available in the media/import folder. The corresponding rows of the import file need to look like this:
– The file name of the image that is to be imported is listed in the _media_image column.
– The _media_attribute_id column required the ID of the product attribute “image_gallery”. It can be obtained either from the admin panel or your custom modules using the expression
– The typing error _media_lable is intentional and hard-wired into Magento.
– In the image,small_image, and thumbnail columns, the first row contains the file names of the according main images.
– Unfortunately, existing images can not be deleted using the module.
Up-Selling, Cross-Selling, Related Products
Even linked products can be imported using the following pairs of fields:
– _links_related_sku and _links_related_position
– _links_crosssell_sku and _links_crosssell_position
– _links_upsell_sku and _links_upsell_position
An example could look like this:
Grouped products can also be imported. Two children products assigned to one grouped product should look like this:
Contrary to the functionality accessible via Magento’s admin panel, this is a way to edit product types after-wards.
Configurable Products and Individual Options
These functions are also supported. Since, however, Vinai has already presented those in detail in his lecture, let me point you to his lecture materials.
It should be noted that when importing data using the ImportExport module, indices are not automatically updated. They are however marked as invalid and will have to be updated separately via the admin panel or a custom module.
The ImportExport module is an important improvement for Magento, because it allows the fast and reliable importing of products by default. Personally, I use this module for all my product imports (and for all my customer data imports), because it innately offers many functionalities and is relatively easy to use (especially when combined with my small FastSimpleImport module). Little weaknesses and cosmetic flaws can be over-looked in this case.
With this article I hope to have given some helpful instructions on how to better understand und use the ImportExport module
Author: Andreas von Studnitz
Andreas von Studnitz is a Magento developer and one of the Managing Directors at integer_net. His main areas of interest are backend development, Magento consulting and giving developer trainings. He is a Magento 2 Certified Professional Developer Plus and holds several other Magento certifications for both Magento 1 and Magento 2. Andreas was selected as a Magento Master in 2019 and 2020.