Skip to content

Commit bc80284

Browse files
author
Stanislav Idolov
authored
ENGCOM-2468: magento-engcom/import-export-improvements#103 Fail product import validation when multiselect columns contain duplicate values #117
2 parents 96ea429 + 7e0e39b commit bc80284

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-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]);

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/ValidatorTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,26 @@ public function attributeValidationProvider()
167167
['product_type' => 'any', 'attribute_code' => 'Option 1|Option 2'],
168168
true
169169
],
170+
[
171+
Import::BEHAVIOR_APPEND,
172+
['is_required' => true, 'type' => 'multiselect',
173+
'options' => ['option 1' => 0, 'option 2' => 1, 'option 3']],
174+
['product_type' => 'any', 'attribute_code' => 'Option 1|Option 2|Option 1'],
175+
false
176+
],
177+
[
178+
Import::BEHAVIOR_APPEND,
179+
['is_required' => true, 'type' => 'multiselect',
180+
'options' => ['option 1' => 0, 'option 2' => 1, 'option 3']],
181+
['product_type' => 'any', 'attribute_code' => 'Option 3|Option 3|Option 3|Option 1'],
182+
false
183+
],
184+
[
185+
Import::BEHAVIOR_APPEND,
186+
['is_required' => true, 'type' => 'multiselect', 'options' => ['option 1' => 0]],
187+
['product_type' => 'any', 'attribute_code' => 'Option 1|Option 1|Option 1|Option 1'],
188+
false
189+
],
170190
[
171191
Import::BEHAVIOR_APPEND,
172192
['is_required' => true, 'type' => 'datetime'],

0 commit comments

Comments
 (0)