Search code examples
sap-commerce-cloudhybris-data-hub

Download Images/thumbnails of categories in hybris through groovy/export script


I want to download all the images and thumbnails attached to the categories present with the help of a groovy or export script whichever is possible in Hybris.

How to download Images/thumbnails of categories in Hybris through groovy/export script?


Solution

  • You can do this using the Backoffice export tool like so:

    Backoffice explorer tree

    • Paste the export script for the Media files you would like to download (example at the end)
    • Click Validate and then Save
    • Select 'Export (No re-import)'
    • Click 'Next'

    Export wizard step 1

    • Now select checkbox 'Export as zip'
    • Click Start

    Export as zip wizard step 2

    • Click DOWNLOAD under 'Exported Media zip'

    Save media zip step 3

    You should now have a zip of all the media files you want.

    Example export script, just replace the placeholder with your catalog name and adjust the flexible search statement to suit your needs:

    "#% impex.setTargetFile( ""Media.csv"" );"
    $catalogName=YOUR_CATALOG_ID
    $version=ONLINE
    $mimeType=image/jpeg
    INSERT_UPDATE Media;code[unique=true];catalogVersion(catalog(id),version)[unique=true];mime;realfilename;@media[translator=de.hybris.platform.impex.jalo.media.MediaDataTranslator][forceWrite=true]
    "#% impex.exportItems(""SELECT {itm.pk} FROM {Media as itm}, {CatalogVersion as cv}, {Catalog as c} WHERE {itm.catalogversion} = {cv.pk} AND {cv.catalog} = {c.PK} AND {c.id} = '$catalogName' AND {cv.version} = '$version' AND {itm.mime} = '$mimeType'"", Collections.EMPTY_MAP, Collections.singletonList( Item.class ), true, true, -1, -1  );"
    

    Unfortunately there's one final task required since the export will only be in .bin format. You'll need to customize the data media translator. The steps are in this SAP support note:

    https://launchpad.support.sap.com/#/notes/0002335426