Importing Images - Part 1
-
In that case, the structure of the CSV file is in general the same as for the product import, but you only the columns sku, store_view_code, attribute_set_code, product_type as well as the columns for the images, e. g. base_image.
E. g. if you'll use the add-update operation, reduce the observers to their minimum, like
{
...,
"operations": [
...,
{
"name" : "add-update",
"plugins" : [
{
"id": "import.plugin.global.data"
},
{
"id": "import.plugin.subject",
"subjects": [
{
"id": "import.subject.move.files",
"identifier": "move-files",
"file-resolver": {
"prefix": "product-import"
},
"ok-file-needed": true
},
{
"id": "import_product.subject.bunch",
"identifier": "files",
"file-resolver": {
"prefix": "product-import"
},
"params" : [
{
"copy-images" : true,
"clean-up-media-gallery" : true,
"clean-up-empty-columns" : [
"base_image",
"small_image",
"swatch_image",
"thumbnail_image"
],
"media-directory" : "pub/media/catalog/product",
"images-file-directory" : "var/importexport/images"
}
]
"observers": [
{
"import": [
"import.observer.attribute.set",
"import_product.observer.file.upload",
"import_product.observer.last.entity.id",
"import_product.observer.product.attribute.update",
"import_product_media.observer.product.media",
"import_product_media.observer.clear.media.gallery",
"import_product.observer.clean.up"
]
}
]
},
{
"id": "import_product_media.subject.media",
"identifier": "files",
"file-resolver": {
"prefix": "media"
},
"observers": [
{
"import": [
"import.observer.attribute.set",
"import_product_media.observer.media.gallery.update",
"import_product_media.observer.media.gallery.value.update"
]
}
]
}
]
},
{
"id": "import.plugin.archive"
}
]
}
]
}
And save the configuration e. g. to <magento-install-dir>/var/importexport/techdivision-import.json.
For testing purposes, put your images in a folder (sufolders are needed), e. g. <magento-install-dir>/var/importexport/images of your Magento 2 Root Directory. Then download and install the PHAR, by moving it to the `bin` directory fo your Magento 2 installation, also make it executable with
bin/import-cli-simple.phar import:products \
--configuration=var/importexport/etc/techdivision-import.json \
--single-transaction=true \
&& bin/magento cache:flush \
&& bin/magento indexer:reindex
Don't forget to clear the cache and re-index after the import. Open the Frontend and Backend and check it everything where it should be.
This was the first part from our Best Practices how to import Images into your Magento 2 shop. Stay tuned for the second part comming soon!