diff --git a/src/Mapping/Operator/Factory/Numeric.php b/src/Mapping/Operator/Factory/Numeric.php index 98250c1d..13446b78 100644 --- a/src/Mapping/Operator/Factory/Numeric.php +++ b/src/Mapping/Operator/Factory/Numeric.php @@ -21,11 +21,13 @@ class Numeric extends AbstractOperator { + private bool $returnNullIfEmpty = false; + /** * @param mixed $inputData * @param bool $dryRun * - * @return float + * @return float|null */ public function process($inputData, bool $dryRun = false) { @@ -33,6 +35,10 @@ public function process($inputData, bool $dryRun = false) $inputData = reset($inputData); } + if ($this->returnNullIfEmpty && empty($inputData)) { + return null; + } + return floatval($inputData); } @@ -60,6 +66,15 @@ public function evaluateReturnType(string $inputType, int $index = null): string */ public function generateResultPreview($inputData) { + if ($this->returnNullIfEmpty && empty($inputData)) { + return null; + } + return $inputData; } + + public function setSettings(array $settings): void + { + $this->returnNullIfEmpty = (bool) ($settings['returnNullIfEmpty'] ?? false); + } } diff --git a/src/Resources/public/js/pimcore/configuration/components/mapping/operator/numeric.js b/src/Resources/public/js/pimcore/configuration/components/mapping/operator/numeric.js index 964dd821..c1501ccb 100644 --- a/src/Resources/public/js/pimcore/configuration/components/mapping/operator/numeric.js +++ b/src/Resources/public/js/pimcore/configuration/components/mapping/operator/numeric.js @@ -24,4 +24,18 @@ pimcore.plugin.pimcoreDataImporterBundle.configuration.components.mapping.operat return "pimcore_icon_data_group_numeric"; }, + getFormItems: function() { + return [ + { + xtype: 'checkbox', + fieldLabel: t('plugin_pimcore_datahub_data_importer_configpanel_transformation_pipeline_numeric_return_null'), + value: this.data.settings ? this.data.settings.returnNullIfEmpty : ' ', + listeners: { + change: this.inputChangePreviewUpdate.bind(this) + }, + name: 'settings.returnNullIfEmpty' + } + ]; + } + }); \ No newline at end of file diff --git a/src/Resources/translations/admin.en.yml b/src/Resources/translations/admin.en.yml index 83ea71db..918854e2 100644 --- a/src/Resources/translations/admin.en.yml +++ b/src/Resources/translations/admin.en.yml @@ -207,4 +207,5 @@ plugin_pimcore_datahub_data_importer_configpanel_logs: Import Logs plugin_pimcore_datahub_data_importer_configpanel_mtm_relation_type_error: Type not supported for Many To Many Relation assignment. plugin_pimcore_datahub_data_importer_configpanel_mtm_relation_type: Make sure transformation results in a 'dataObjectArray' or an 'assetArray'. plugin_pimcore_datahub_data_importer_configpanel_type_sql: SQL -plugin_pimcore_datahub_data_importer_configpanel_sql_connection: Connection \ No newline at end of file +plugin_pimcore_datahub_data_importer_configpanel_sql_connection: Connection +plugin_pimcore_datahub_data_importer_configpanel_transformation_pipeline_numeric_return_null: Return null if empty \ No newline at end of file