Skip to content
This repository has been archived by the owner on Apr 29, 2019. It is now read-only.

magento-engcom/import-export-improvements#103 Fail product import validation when multiselect columns contain duplicate values #117

Merged
merged 2 commits into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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