diff --git a/Helper/ImportHelper.php b/Helper/ImportHelper.php index 8dadc3d..cd340e4 100644 --- a/Helper/ImportHelper.php +++ b/Helper/ImportHelper.php @@ -274,8 +274,7 @@ public function downloadVisualFromUrl($attributeValue, $attributeCode) // Check visual if (filesize($visualPath) < self::EXIF_IMAGETYPE_FILE_MIN_SIZE || exif_imagetype($visualPath) === false) { - $errorMessage = sprintf('Visual not valid for url %s', $attributeValue); - throw new \Exception($errorMessage); + return null; } } diff --git a/README.md b/README.md index 5bad51c..b6fc3ee 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,8 @@ Import mapping example: { "attributeCode": "lens_height", "dataCode": "hauteurVerre", - "callback": "setMetricUnitAsSuffix" + "callback": "setMetricUnitAsSuffix", + "deleteIfNull": true }, { "attributeCode": "universe", @@ -126,6 +127,7 @@ Mapping explanation: * `onlyOnCreation`: Set attribute value only if product is new (checked with `identifier` attribute) * `locales`: Used to set same attribute value for different locales * `completeCallback`: Used to add some more fields with **ImportHelper** +* `deleteIfNull': Remove key from item mapping if value is null ### Export diff --git a/Reader/File/Csv/ProductAdvancedReader.php b/Reader/File/Csv/ProductAdvancedReader.php index e00429d..cc2c7c6 100644 --- a/Reader/File/Csv/ProductAdvancedReader.php +++ b/Reader/File/Csv/ProductAdvancedReader.php @@ -106,6 +106,13 @@ class ProductAdvancedReader extends ProductReader implements InitializableInterf */ const MAPPING_MAX_LENGTH_KEY = 'maxLength'; + /** + * Delete if null key + * + * @var string + */ + const MAPPING_DELETE_IF_NULL = 'deleteIfNull'; + /** * Import helper * @@ -359,6 +366,15 @@ protected function updateByMapping($item) $value = mb_substr($value, 0, $attributeMapping[self::MAPPING_MAX_LENGTH_KEY]); } + // Don't add value if value is null + if ( + isset($attributeMapping[self::MAPPING_DELETE_IF_NULL]) + && $attributeMapping[self::MAPPING_DELETE_IF_NULL] === true + && $value === null + ) { + continue; + } + $newItem[$attributesCode] = $value; } }