Extension Guide
When an entity like product is extended, new joined table is created. These new table name differs from the table name defined in the default Fields therefore new Field class is required. At least 1 field from extended entity needs to be defined, otherwise default broadleaf entitiy will be created and persisted without extension.
public class CustomProductField extends ProductField {
// New Fields being added
public static CustomProductField FIELD_ONE = new CustomProductField("FIELD_ONE");
public static CustomProductField FIELD_TWO = new CustomProductField("FIELD_ONE", FieldDataType.INTEGER);
public CustomProductField(String columnName) {
super(columnName);
}
public CustomProductField(String columnName, FieldDataType fieldDataType) {
super(columnName, fieldDataType);
}
@Override
public String getTableName() {
return "MY_PRODUCT";
}
}
Use the custom Field class in the custom import specification.
@Component("CustomProductSpec")
public class CustomProductSpec extends DefaultProductImportSpecification {
@Override
protected void initializeFieldConfigMap() {
super.initializeFieldConfigMap();
Map<String, ImportFieldConfig> fcMap = getFieldConfigMap();
fcMap.put("FIELD_ONE Header", new ImportFieldConfig(CustomProductField.FIELD_ONE, RequiredIndicator.FALSE, null));
fcMap.put("FIELD_TWO Header", new ImportFieldConfig(CustomProductField.FIELD_TWO, RequiredIndicator.FALSE, null));
}
}
There is ability to skip a column from the import file. Simply define the ImportFieldConfig
with nulls for the column header.
fcMap.put("FIELD_SKIP Header", new ImportFieldConfig(null, null, null));
Then override the bean in the Core Config to replace the Default Product Import Specification.
@Bean
public CustomProductSpec blDefaultProductImportSpecification(CustomProductSpec CustomProductSpec) {
return CustomProductSpec;
}