How do I export and import product attribute selections using a CSV file?
Use a CSV file for bulk edits and save time by not having to update each product's individual attributes separately.
In this article, you will learn how to export and import product attribute values (such as battery_capacity or color[fi] ) using a CSV file in AI Commerce platform. This method allows for quick bulk editing without having to update each product individually in the user interface. This article is especially useful if you want to handle hundreds of products at once or maintain multilingual attributes.
1. CSV Export (Product Attributes Export)
- The Export function (e.g. the "CSV Export Product Attributes" button) generates a CSV file where each row corresponds to one product and its attribute fields.
-
The first column is always
sku
, which identifies the product (e.g.products_model
). -
The following columns describe the attributes (
attribute_code
).- If the attribute is multilingual (i.e.
backend_type = 'varchar'
or'text'
), each language gets its own column likeattribute_code[fi]
,attribute_code[en]
, etc. - If the attribute is numeric (e.g.
int
,decimal
), you will only get one column.
- If the attribute is multilingual (i.e.
Example of CSV structure
If the attributes are color
(multilingual) and battery_capacity
(numeric), the first line (header) of the export might look like this:
sku;color[fi];color[en];battery_capacity
The following lines may contain products as follows:
SCOTT_001;Sininen;Blue;500
SCOTT_002;Punainen;Red;625
2. CSV Import (Import of product attributes)
Import allows you to update or create attribute values based on the uploaded CSV.
- The import script reads the file line by line and identifies the products based on the
sku
column (e.g.products_model
). - It updates or deletes existing attribute values:
- If
sku
value does not match any product, the row is skipped.
- If
Interpretation of attribute code and language code
- The column title determines whether it is
attribute_code[fi]
(language-specific) orattribute_code
(monolingual / numeric). - If the attribute code is unknown, the column is skipped.
- In a multilingual column, the import searches for the corresponding
lang_id
code in the system (e.g.[fi]
means Finnish).
Clearing a value
- If the value field is empty (e.g.
""
ornull
), the system deletes that attribute row ( DELETE ). This makes it easy to remove incorrect or outdated data.
Multi-select example
- If the attribute is of type multiselect , the input can contain comma-separated ID values (or selection codes). The script converts these into a storage format suitable for the system.
3. CSV file structure
Column | Description |
---|---|
sku | Product identifier (e.g. products_model ). Required. |
attribute_code or attribute_code[en] |
Each attribute as its own column, e.g. color[fi] , battery_capacity . |
(add attributes) | Separate columns for each attribute. |
- Available attributes are read from the eav_attribute table.
- If the attribute
backend_type
is'varchar'
or'text'
, the export and import will have language-specific columns. - If
backend_type
is'int'
or'decimal'
, there is only one column.
Example table in HTML format
Let's say the attributes are color
(multilingual) and battery_capacity
(numeric). Export could produce a CSV whose HTML equivalent looks like this:
sku | color[en] | color[en] | battery_capacity |
---|---|---|---|
SCOTT_001 | Blue | Blue | 500 |
SCOTT_002 | Red | Red | 625 |
The corresponding CSV file would be:
sku;color[fi];color[en];battery_capacity
SCOTT_001;Sininen;Blue;500
SCOTT_002;Punainen;Red;625
The fields are separated by a semicolon ;
. If the value contains semicolons, it is a good idea to surround it with quotation marks.
4. Validation & common problems
-
Number of columns
Each row must have the same number of columns as the header row. Otherwise, the import will abort or skip the row. -
Missing sku
The row is skipped because the product cannot be combined. -
Unknown attribute_code
If the column heading does not match a system attribute, it will not be updated. -
Language code
If the entry[xx]
does not match a code known to the system (e.g.[fi]
,[en]
), the language-specific value is skipped.
Possible error messages:
-
"No CSV file uploaded."
The file was not downloaded at all. -
"Cannot open CSV file."
There is a problem opening the file. -
"CSV missing header row."
The CSV file is missing a header row. -
"expected X columns, got Y"
The row has a different number of columns than the header.
5. Workflow in a nutshell
-
Export – Download CSV with
sku
+ attribute columns. - Edit – Open CSV in an editor (e.g. Excel, LibreOffice). Change, add or delete values.
-
Import – Load the CSV back.
- If the value is empty, it will be deleted.
- If it is a numeric or text value, a row is updated or created.
- Test with a small CSV first before making large mass updates. Check for any error messages.
6. Summary
- Product attribute values can be exported and imported using CSV – this is a very fast and efficient way to manage large product lists.
- The header row has
sku
and columns for each attribute. Multilingual attributes are displayed in multiple columns. - An empty value deletes the data, a filled value updates or adds it.
-
sku
matches the CSV row to the correct product andattribute_code
to the correct field. - The columns must match the structure of the export, including the number of columns and names.
Finally, we recommend testing with a small amount of data to ensure that the CSV file and the required attributes work correctly. Once the results are as desired, you can confidently make larger bulk updates.