Skip to content

Commit a765ec7

Browse files
committed
magento-engcom/import-export-improvements#103: Add validation error when a multiselect attribute is supplied with duplicate values.
1 parent 9bfb67e commit a765ec7

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
294294
ValidatorInterface::ERROR_MEDIA_PATH_NOT_ACCESSIBLE => 'Imported resource (image) does not exist in the local media storage',
295295
ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE => 'Imported resource (image) could not be downloaded from external resource due to timeout or access permissions',
296296
ValidatorInterface::ERROR_INVALID_WEIGHT => 'Product weight is invalid',
297-
ValidatorInterface::ERROR_DUPLICATE_URL_KEY => 'Url key: \'%s\' was already generated for an item with the SKU: \'%s\'. You need to specify the unique URL key manually'
297+
ValidatorInterface::ERROR_DUPLICATE_URL_KEY => 'Url key: \'%s\' was already generated for an item with the SKU: \'%s\'. You need to specify the unique URL key manually',
298+
ValidatorInterface::ERROR_DUPLICATE_MULTISELECT_VALUES => "Value for multiselect attribute %s contains duplicated values",
298299
];
299300
//@codingStandardsIgnoreEnd
300301

app/code/Magento/CatalogImportExport/Model/Import/Product/RowValidatorInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ interface RowValidatorInterface extends \Magento\Framework\Validator\ValidatorIn
8585

8686
const ERROR_DUPLICATE_URL_KEY = 'duplicatedUrlKey';
8787

88+
const ERROR_DUPLICATE_MULTISELECT_VALUES = 'duplicatedMultiselectValues';
89+
8890
/**
8991
* Value that means all entities (e.g. websites, groups etc.)
9092
*/

app/code/Magento/CatalogImportExport/Model/Import/Product/Validator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ public function isAttributeValid($attrCode, array $attrParams, array $rowData)
219219
break;
220220
}
221221
}
222+
223+
$uniqueValues = array_unique($values);
224+
if (count($uniqueValues) != count($values)) {
225+
$valid = false;
226+
$this->_addMessages([RowValidatorInterface::ERROR_DUPLICATE_MULTISELECT_VALUES]);
227+
}
222228
break;
223229
case 'datetime':
224230
$val = trim($rowData[$attrCode]);

0 commit comments

Comments
 (0)