Media files

Most, importing media files is complicated, as the amount of data to be moved can quickly become very large.

Pacemaker Community Edition offers an excellent solution because, generally, Pacemaker Community Edition does not care if images from the directory they uploaded get moved to the magento pub/media/catalog/product directory.

As a solution, the upload directory gets provided as a symlink to the Magento media directory

Directory structure

The proven directory structure looks like the following, which also includes the necessary directories for the 360° images, as these also get used 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/ (1)
                              │               │               ├── 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/ (2)
                              │                                 ├── 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
1 Necessary directories for the 360° images
2 Necessary directories for the 360° images

Magento demands a two-level folder structure for the image rendering to work.

  • After the SKU must exist an additional folder containing the image files, as an example, the folder general.

Magento creates by default the image cache on-the-fly, based on the \Magento\MediaStorage\App\Media::getOriginalImage() method, if this has not already been done with the bin/magento catalog:image:resize command, which uses a regular expression that truncates anything before those three levels.

It creates the problem that the path to the original file in the pub/media/catalog/product directory gets not found, and instead of the image, the placeholder gets rendered.

Path in CSV files

  • The image path in the CSV files must be relative to the Magento directory pub/media.

    • Equally, they must begin with a leading slash ( / ).

For example, the files in the above structure must have the following format in the CSV file product-import_20191204-140200_01.csv:
sku base_image small_image is_360 images_360

00490826

/00490826/general/base_image.jpg

/00490826/general/small_image.jpg

Yes

/00490826/360

00490794

/00490794/general/base_image.jpg

/00490794/general/small_image.jpg

Yes

/00490794/360

After creating the directory structure, symlinks can get created.

Use the 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 reasons, this can be very useful since, in some cases, error messages are output on the CLI, and debugging can be so much more comfortable this way:
cd <magento-install-dir> \ (1)
  && rm var/pacemaker/import/*.csv \ (2)
  && cp <sample-data-dir>/* var/pacemaker/import \ (3)
  && vendor/bin/pacemaker import:products add-update \ (4)
    --serial=import \ (5)
    --source-dir=var/pacemaker \ (6)
    --target-dir=var/pacemaker \ (7)
    --magento-version=2.3.4 \ (8)
    --magento-edition=EE (9)
1 Navigate into the Magento install directory
2 Remove all old CSV import files from the Pacemaker import directory
3 E.g., copy the Pacemaker Community Edition example data to the Pacemaker import directory
4 Call the import command import:products with the shortcut add-update
5 Add option --serial
6 Add option --source-dir
7 Add option --target-dir
8 Add option --magento-version
9 Add option --magento-edition