Overview Of Impex
Impex stands for Import and export
As the name suggests, Impex in hybris is used for importing data from CSV file / impex file to hybris system and exporting data from hybris system to CSV file.
Hybris has come up with an extension called “Impex” inside platform/ext folder which helps in Inserting,updating,deleting and exporting data.
Impex import means always data flows into Hybris system.
Impex export means always data flows out of Hybris system
Why do we need to import ?
We need to import data multiple times into Hybris system.
As we all know that any ecommerce site will have a data like products,customer,regions,countries,promotions etc…
All this data has to be inserted into Hybris system to display it on the site.
So to insert this kind of data into hybris system, we go for Impex Import.
We can insert data either at the run time or during initialization or during update process.
Why do we need to export?
Whenever we need to take the backup of data, we have to export the data into csv files so that later it can be imported into Hybris system.
If we are doing initialization,it is recommended to take data backup using Impex Export.
Once the initialization is done, we can import the data back to hybris system.
2) Value lines
Header in impex will have below structure
- Mode itemType[modifier=value];attribute1[modifier=value];attribute2[modifier=value];attribute3[modifier=value]
We can see below things in header
It specifies what operation we are going to perform on the values(Insert,update,remove)
There are 4 mode types possible in Header
1) INSERT :
This Mode is used to insert a new record into Database.
If the record already exists it will throw an exception.
2) UPDATE :
This Mode is used to update the existing record.
If the record does not exist then exception will be thrown.
3) INSERT_UPDATE :
This Mode is the most preferred one for insertion or update.
This header will insert the record if its new one and update the record if it is already exists.
So there will be no exception if we use this mode.
4) REMOVE :
This mode is used to remove the existing records.
We need to specify one unique attribute to remove the record.
specifies the item type on which the Mode is applied (Example:Product,Category,Customer etc )
Basically it impacts the table associated with this Type.
It defines the attributes of the item type which are defined in items.xml file.
Each attribute specified will get the values affected on corresponding columns in DB.
It is used to specify the additional information for the attributes like specifying attribute uniqueness using unique=true.
We can specify multiple modifers in 2 ways
1) Comma separated modifiers within single bracket  as below
Single bracket has all the modifiers separated by comma.
2) each modifier with separate bracket  as below
Separate bracket for each modifier
- INSERT_UPDATE category;code[unique=true];name[lang=de];name[lang=en];$supercategories;$thumbnail;description[lang=de];order
In the above header line,
INSERT_UPDATE is the mode
Category is the item type
Code,name etc are the attributes
[unique=true] is the modifier
This header is applicable for all the value lines till the next header appears in the file.
One file can have any number of headers.
Value lines in Impex
There could be one or more value lines in the file.
Each value line represents one row of data in table.
Each field in the value line is separated by semicolon and represents the data into one column.
Space is also considered as value of the field.
Each line should have the same number of fields.
If field contains any line breaks or quotes, then enclose such fields in double quotes.
Macros are basically used to define the value at one place and use the macro in all the places.
It helps to eliminate writing same lines again and again.
Macros starts with “$” and they are referenced by $macroName
Defined a macro called “catalog” and can be referenced as $catalog wherever required.
Defined a macro called “catalogVersion” and can be referenced as $catalogVersion wherever required.
Now the macros $catalogVersion and $catalog are replaced by their actual value as below
If we don’t use macros then we have to write above line in all the places wherever required.
Comments in impex file starts with # symbol.
- #Inserting product details
- INSERT_UPDATE Product;code[unique=true]; varianttype(code);name[lang=en];
#Inserting product details INSERT_UPDATE Product;code[unique=true]; varianttype(code);name[lang=en];
In the above lines, we have one comment line starts with # which will be ignored while importing.