SAP Hybris Commerce – Export and import the data (Online->Staged)
Objective : The intent of this article is to provide the solution for the use case –“Export the data from Online catalog version and import to Staged catalog version” .
Problem Summary : There are the instances where business wants to edit/update the Content/Product data such as name, description , media etc in dedicated Hybris system before go live and doesn’t want to update the data via hybris impex file . Since online version would have the verified data to move to higher hybris environments hence it becomes necessary to export the data from online catalog version and import to Stage version on other environments (followed by sync process) .
Solution : One of the ready to use solution is to write export-import script . This article explains all the steps to write/export/import the script . Steps are as follows ,
step-1 : HAC – Data Export
- Export the data with the help of export script .
- Example : export Media from content catalog Online version .
$catalog=shakleeUSContentCatalog
$version=Online
# ---- Extension: core ---- Type: Media ----
"#% impex.setTargetFile( ""Media.csv"" );"
insert_update Media;URL;altText;catalog(id)[allownull=true];catalogVersion(catalog(id),version)[unique=true,allownull=true];code[unique=true,allownull=true];description;folder(qualifier);internalURL;location;locationHash;mediaContainer(catalogVersion(catalog(id),version),qualifier);mediaFormat(qualifier);mime;realFileName;removable[allownull=true];size;subFolderPath
"#% impex.exportItems(""SELECT {M:pk} FROM {Media as M}, {CatalogVersion as CV}, {Catalog as C} WHERE {M:catalogversion}={CV:PK} AND {CV:catalog}={C:PK} AND {C:id}='$catalog' AND {CV:version}='$version'"", Collections.EMPTY_MAP, Collections.singletonList( Item.class ), true, true, -1, -1 );"
- Go to Hybris admin console ->Export . Copy paste above script in content area of Export Content tab and follow the steps mentioned in below image .
- Download exported data and extract the zip file .
step-2 : **Edit importscript.impex and create a zip file
- Open importscript.impex file in text editor .Before edit , file content would look like ,
- Edit the file and add below line before Line “#% impex.includeExternalDataMedia(….
"#% beforeEach: import org.apache.commons.lang.StringUtils;int size = line.size()+1;for (i=1; i<size; i++){String value = line.get(Integer.valueOf(i));if(StringUtils.contains(value, ""Online"")){String newValue = StringUtils.replace(value, "" Online "","" Staged "");line.put(Integer.valueOf(i), newValue);}} ;"
- *After edit and save , file content would look like,
#-----------------------------------------------------------
insert_update Media;URL;altText;catalog(id)[allownull=true];catalogVersion(catalog(id),version)[unique=true,allownull=true];code[unique=true,allownull=true];description;folder(qualifier);internalURL;location;locationHash;mediaContainer(catalogVersion(catalog(id),version),qualifier);mediaFormat(qualifier);mime;realFileName;removable[allownull=true];size;subFolderPath
"#% beforeEach: import org.apache.commons.lang.StringUtils;int size = line.size()+1;for (i=1; i<size; i++){String value = line.get(Integer.valueOf(i));if(StringUtils.contains(value, ""Online"")){String newValue = StringUtils.replace(value, ""Online"",""Staged"");line.put(Integer.valueOf(i), newValue);}} ;"
"#% impex.includeExternalDataMedia( ""Media.csv"" , ""UTF-8"", ';', 1 , -1 );"
#-----------------------------------------------------------
- Create a zip file again . To create a zip file ,
- Select the importscript.impex file and *.csv file/files .
- Right click and compress the items .
- Newly zipped file would be used to import the data into Staged version.
step-3 : HAC – Data Import
- Go to import script and follow the steps motioned in below image to import the same data.
- Data would be successfully loaded to Stage version.
**This step is manual step . we can also introduce automation script to generate the zip file rather manually editing it.
Thank you Priti Mittal,
Providing an example how the use the ImpEx export functionality was exactly what we needed. We have lot's of product references in our SAP Commerce solution. For identifying any rogue references this export is great. References are not tied to online/staged version. Here is our adaption of your export ImpEx:
$catalog=productCatalog
# ---- Extension: core ---- Type: ProductReference ----
"#% impex.setTargetFile( ""References.csv"" );"
insert_update ProductReference;source(code);source(name[lang=en]);target(code);target(name[lang=en]);qualifier;referenceType(code)
"#% impex.exportItems(""SELECT {M:pk} FROM {ProductReference as M}, {Catalog as C} WHERE {C:id}='$catalog'"", Collections.EMPTY_MAP, Collections.singletonList( Item.class ), true, true, -1, -1 );"
Perhaps someone can benefit from it.
Bye
How do you go about transferring the media files themselves (jpg, pdf, etc). What about exporting/importing then entire content catalog?