BlackbitDigitalCommerce / pimcore-data-director

Import Bundle for Pimcore
16 stars 3 forks source link

Create object only for specific condition #56

Open betterapp opened 1 year ago

betterapp commented 1 year ago

I have such scenerio: My dataport is configured to create only new objects.

Lets imagine that we have 4 field in Excel import file but two fields are mandatory for create object. If one of those two fields will be empty the whole object should not be created. We do not want objects without those two field's data.

Is it possible ?

BlackbitDevs commented 1 year ago

Yes. Check in one of the key fields' callback function if any of the 2 raw data fields is empty. If one is empty, return null. This way the raw data item processing will get skipped. Example:

if(empty($params['rawItemData']['mandatoryField1']['value']) || empty($params['rawItemData']['mandatoryField2']['value']) {
  return null;
}
return $params['value'];
betterapp commented 1 year ago

I thought that Key field is used only for update object data and the key field will be used to find object by Key ?

BlackbitDevs commented 1 year ago

Actually the main purpose of the key fields in attribute mapping is to find existing objects. It has nothing to do with object keys (for this reason the field which Pimcore calls key is named Object name in Data Director's attribute mapping). The key fields in attribute mapping can be set by clicking the settings icon for the field and then check the checkbox Key field