Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ct import validation when multiselect columns contain duplicate values #117
  • Loading branch information
Stanislav Idolov authored Jul 24, 2018
2 parents 96ea429 + 7e0e39b commit bc80284
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
ValidatorInterface::ERROR_MEDIA_PATH_NOT_ACCESSIBLE => 'Imported resource (image) does not exist in the local media storage',
ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE => 'Imported resource (image) could not be downloaded from external resource due to timeout or access permissions',
ValidatorInterface::ERROR_INVALID_WEIGHT => 'Product weight is invalid',
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'
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',
ValidatorInterface::ERROR_DUPLICATE_MULTISELECT_VALUES => "Value for multiselect attribute %s contains duplicated values",
];
//@codingStandardsIgnoreEnd

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ interface RowValidatorInterface extends \Magento\Framework\Validator\ValidatorIn

const ERROR_DUPLICATE_URL_KEY = 'duplicatedUrlKey';

const ERROR_DUPLICATE_MULTISELECT_VALUES = 'duplicatedMultiselectValues';

/**
* Value that means all entities (e.g. websites, groups etc.)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ public function isAttributeValid($attrCode, array $attrParams, array $rowData)
break;
}
}

$uniqueValues = array_unique($values);
if (count($uniqueValues) != count($values)) {
$valid = false;
$this->_addMessages([RowValidatorInterface::ERROR_DUPLICATE_MULTISELECT_VALUES]);
}
break;
case 'datetime':
$val = trim($rowData[$attrCode]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,26 @@ public function attributeValidationProvider()
['product_type' => 'any', 'attribute_code' => 'Option 1|Option 2'],
true
],
[
Import::BEHAVIOR_APPEND,
['is_required' => true, 'type' => 'multiselect',
'options' => ['option 1' => 0, 'option 2' => 1, 'option 3']],
['product_type' => 'any', 'attribute_code' => 'Option 1|Option 2|Option 1'],
false
],
[
Import::BEHAVIOR_APPEND,
['is_required' => true, 'type' => 'multiselect',
'options' => ['option 1' => 0, 'option 2' => 1, 'option 3']],
['product_type' => 'any', 'attribute_code' => 'Option 3|Option 3|Option 3|Option 1'],
false
],
[
Import::BEHAVIOR_APPEND,
['is_required' => true, 'type' => 'multiselect', 'options' => ['option 1' => 0]],
['product_type' => 'any', 'attribute_code' => 'Option 1|Option 1|Option 1|Option 1'],
false
],
[
Import::BEHAVIOR_APPEND,
['is_required' => true, 'type' => 'datetime'],
Expand Down

0 comments on commit bc80284

Please sign in to comment.