Skip to content

Commit 7746c17

Browse files
author
Pieter Cappelle
committed
Display duplicate Admin elements in error message
1 parent e751bcc commit 7746c17

File tree

7 files changed

+29
-11
lines changed

7 files changed

+29
-11
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private function isUniqueAdminValues(array $optionsValues, array $deletedOptions
128128
}
129129
}
130130
$uniqueValues = array_unique($adminValues);
131-
return ($uniqueValues === $adminValues);
131+
return array_diff_assoc($adminValues, $uniqueValues);
132132
}
133133

134134
/**
@@ -157,10 +157,16 @@ private function checkUniqueOption(DataObject $response, array $options = null)
157157
if (is_array($options)
158158
&& !empty($options['value'])
159159
&& !empty($options['delete'])
160-
&& !$this->isUniqueAdminValues($options['value'], $options['delete'])
161160
) {
162-
$this->setMessageToResponse($response, [__("The value of Admin must be unique.")]);
163-
$response->setError(true);
161+
$duplicates = $this->isUniqueAdminValues($options['value'], $options['delete']);
162+
if ($duplicates) {
163+
$this->setMessageToResponse(
164+
$response,
165+
[__('The value of Admin must be unique. (%1)', implode(', ', $duplicates))]
166+
);
167+
168+
$response->setError(true);
169+
}
164170
}
165171
return $this;
166172
}

app/code/Magento/Catalog/i18n/en_US.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,4 +716,4 @@ Disable,Disable
716716
none,none
717717
Overview,Overview
718718
Details,Details
719-
"The value of Admin must be unique.", "The value of Admin must be unique."
719+
"The value of Admin must be unique. (%1)", "The value of Admin must be unique. (%1)"

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/options.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ $stores = $block->getStoresSortedBySortOrder();
101101
},
102102
"Magento_Catalog/catalog/product/attribute/unique-validate": {
103103
"element": "required-dropdown-attribute-unique",
104-
"message": "<?= $block->escapeHtml(__("The value of Admin must be unique.")) ?>"
104+
"message": "<?= $block->escapeHtml(__("The value of Admin must be unique. (%1)")) ?>"
105105
}
106106
}
107107
}

app/code/Magento/Catalog/view/adminhtml/web/catalog/product/attribute/unique-validate.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ define([
1717
}, config);
1818

1919
if (typeof _config.element === 'string') {
20+
var msg = '';
21+
22+
var messager = function() {
23+
return msg;
24+
};
25+
2026
jQuery.validator.addMethod(
2127
_config.element,
2228

@@ -25,21 +31,27 @@ define([
2531
.closest('table')
2632
.find('.' + _config.uniqueClass + ':visible'),
2733
valuesHash = {},
28-
isValid = true;
34+
isValid = true,
35+
duplicates = [];
2936

3037
inputs.each(function (el) {
3138
var inputValue = inputs[el].value;
3239

3340
if (typeof valuesHash[inputValue] !== 'undefined') {
3441
isValid = false;
42+
duplicates.push(inputValue);
3543
}
3644
valuesHash[inputValue] = el;
3745
});
3846

47+
if (!isValid) {
48+
msg = _config.message.replace('%1', duplicates.join(', '));
49+
}
50+
3951
return isValid;
4052
},
4153

42-
_config.message
54+
messager
4355
);
4456
}
4557
};

app/code/Magento/Swatches/i18n/en_US.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ Image,Image
3333
"Image Size","Image Size"
3434
"Example format: 200x300.","Example format: 200x300."
3535
"Image Position","Image Position"
36-
"The value of Admin must be unique.","The value of Admin must be unique."
36+
"The value of Admin must be unique. (%1)","The value of Admin must be unique. (%1)"
3737
Description,Description

app/code/Magento/Swatches/view/adminhtml/templates/catalog/product/attribute/text.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ $stores = $block->getStoresSortedBySortOrder();
108108
"Magento_Swatches/js/text": <?= /* @escapeNotVerified */ $block->getJsonConfig() ?> ,
109109
"Magento_Catalog/catalog/product/attribute/unique-validate": {
110110
"element": "required-text-swatch-unique",
111-
"message": "<?= $block->escapeHtml(__("The value of Admin must be unique.")) ?>"
111+
"message": "<?= $block->escapeHtml(__("The value of Admin must be unique. (%1)")) ?>"
112112
}
113113
}
114114
}

app/code/Magento/Swatches/view/adminhtml/templates/catalog/product/attribute/visual.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ $stores = $block->getStoresSortedBySortOrder();
113113
"Magento_Swatches/js/visual": <?= /* @noEscape */ $block->getJsonConfig() ?> ,
114114
"Magento_Catalog/catalog/product/attribute/unique-validate": {
115115
"element": "required-visual-swatch-unique",
116-
"message": "<?= $block->escapeHtml(__("The value of Admin must be unique.")) ?>"
116+
"message": "<?= $block->escapeHtml(__("The value of Admin must be unique. (%1)")) ?>"
117117
}
118118
}
119119
}

0 commit comments

Comments
 (0)