Media files
In most cases, the import of media files will be complicated, as the amount of data that has to be moved can quickly be large. Pacemaker offers an excellent solution to handle that comprehensively.
In general, that implies that Pacemaker doesn’t take care, that the images will be moved from the directory, where they have been uploaded,
to the magento pub/media/catalog/product
directory.
Instead, the upload directory will be provided as a symlink to Magento’s media directory.
Directory structure
The proven directory structure looks like the following one, whereas this one also contains the necessary directories for the 360° images, which may also be of interest in many cases.
/
└--var/
└--www/
└--sftp/
└--import/
|--media/
| └--images/
| |--00490826/
| | |--general/
| | | |--base_image.jpg
| | | └--small_image.jpg
| | |--additional/
| | | |--additional_image_01.jpg
| | | └--additional_image_02.jpg
| | └--360/
| | |--10584391-SPK-001--_01.JPG
| | |--10584391-SPK-001--_02.JPG
| | |--10584391-SPK-001--_03.JPG
| | |--10584391-SPK-001--_04.JPG
| | |--10584391-SPK-001--_05.JPG
| | └--10584391-SPK-001--_06.JPG
| └--00490794/
| |--general/
| | |--base_image.jpg
| | └--small_image.jpg
| |--additional/
| | |--additional_image_01.jpg
| | └--additional_image_02.jpg
| └--360/
| |--10584352-SAK-001-G_01.JPG
| |--10584352-SAK-001-G_02.JPG
| |--10584352-SAK-001-G_03.JPG
| |--10584352-SAK-001-G_04.JPG
| |--10584352-SAK-001-G_05.JPG
| └--10584352-SAK-001-G_06.JPG
└--data/
|--category-import_20191204-140200_01.csv
|--category-import_20191204-140200_01.ok
|--product-import_20191204-140200_01.csv
└--product-import_20191204-140200_01.ok
Magento requires exactly a two-level folder structure to make the image rendering work.
After the SKU, exactly one additional folder that finally contains the image files, e.g. the folder It’s because Magento creates the image cache on-the-fly, based on the method \Magento\MediaStorage\App\Media::getOriginalImage()
(if this has not already been done with the It leads to the issue of the path to the original file under the directory |
Path in CSV files
The path to the images in the CSV files has to be relative to the Magento pub/media
directory.
Additionally, they have to start with a slash.
For example, the files in the structure above must
have the following format in the CSV file product-import_20191204-140200_01.csv
sku | base_image | small_image | is_360 | images_360 |
---|---|---|---|---|
|
|
|
Yes |
|
00490794 |
|
|
Yes |
|
Symlinks
When the directory structure has been created, symlinks can be created as well. It can be done by following command
ln -s <magento-install-dir>/var/pacemaker/import /var/www/sftp/import/data \
&& ln -s <magento-install-dir>/pub/media/catalog/product /var/www/sftp/import/media/images \
&& ln -s <magento-install-dir>/pub/media/magic360 /var/www/sftp/import/media/images
Import
Besides the automatic import by the appropriate pipeline, it is also possible to import the data manually.
For debugging purposes, this can be useful, as in some cases, error messages will be rendered on the CLI, and finding errors can then be more comfortable.
cd <magento-install-dir> \
&& rm var/pacemaker/import/*.csv \
&& cp <sample-data-dir>/* var/pacemaker/import \
&& vendor/bin/pacemaker import:products add-update \
--serial=import \
--source-dir=var/pacemaker \
--target-dir=var/pacemaker \
--magento-version=2.3.4 \
--magento-edition=EE