Introduction

This is a guide that explains how you can use the media-module to map category- and product-images to Shopware.

Please note that the procedure of this guide may be different in your individual use case. But it should be able to provide a first impression on what to consider if you plan to map media files to Shopware.

In general the steps performed in this guide are the following:

  • Set up file system(s) for your images
  • Use the image bundle to read all available images from that filesystem(s)
  • Use the image bundle to assign those images as assets to your documents
  • Use the media module to transfer the assigned assets as images to Shopware

Step 1: Filesystem Configuration

We will set up two local file systems. The first contains the product images, the other one contains category images.

[
    {
        "identifier": "productFilesystemIdentifier",
        "config": {
            "adapter": "local",
            "adapterConfig": {
                "path": "/var/www/html/local-filesystem/product/images"
            }
        }
    },
    {
        "identifier": "categoryFilesystemIdentifier",
        "config": {
            "adapter": "local",
            "adapterConfig": {
                "path": "/var/www/html/local-filesystem/category/images"
            }
        }
    }
]

Of course, you are able to use remote file systems as well. This is an example for a remote filesystem:

{
    "identifier": "exampleRemoteFilesystem",
    "config": {
        "adapter": "sftp",
        "adapterConfig": {
            "host": "assets.some-customer.example.io",
            "port": 22,
            "root": "/home/assets/public_html/assets",
            "password": "...",
            "username": "..."
        },
        "publicUrlPrefix": "http://assets.some-customer.io/assets/",
        "publicUrlUseFullPath": false
    }
}

Step 2: Generate Indexed Files

This step will read all files that are available on your filesystems. Use the following job_dispatcher_mapping:

  • process_step_identifier: input
  • message_fqcn: Synqup\Modules\ImageBundle\Input\ReadAvailableImagesFromFilesystem\ReadAvailableImagesFromFilesystemMessage
  • configuration: see below
{
    "inputs": [
        {
            "path": "/",
            "filesystemIdentifier": "productFilesystemIdentifier"
        },
        {
            "path": "/",
            "filesystemIdentifier": "categoryFilesystemIdentifier"
        }
    ],
    "batchSize": "50",
    "clearIndex": true
}

This creates IndexedFile documents from your images of the filesystem.

Step 3: Assign Indexed Files

This step links the previously generated IndexedFile documents as Asset to the products and categories. Use the following job_dispatcher_mapping:

  • process_step_identifier: transformations
  • message_fqcn: Synqup\Modules\ImageBundle\Transformations\EmbedIndexedFileIntoDocument\StartEmbedIndexedFileIntoDocumentMessage
  • configuration: see below
{
    "targetDocument": "Synqup\\CommerceBundle\\Document\\Product\\Product",
    "targetAssetGroupType": "PRODUCT_IMAGE",
    "filesystemIdentifiers": [
        "productFilesystemIdentifier"
    ],
    "strategyConfiguration": {
        "batchSize": 200,
        "documentCompareField": "identifier",
        "extractDocumentSearchValueFromFilenameRegex": "/([^_.\n]+)(_.+){0,}\\.((?:JPE?G)|(?:PNG))/i"
    }
}

Step 4: Media Module

The last step is to execute the media module. This will transfer the assets to Shopware.