Skip to content

Commit d159921

Browse files
author
nmalevanec
committed
Fix incorrect language on swatch error. Fix failed tests.
1 parent 0f28b61 commit d159921

File tree

7 files changed

+18
-16
lines changed

7 files changed

+18
-16
lines changed

app/code/Magento/Swatches/Model/Plugin/EavAttribute.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ protected function convertSwatchToDropdown(Attribute $attribute)
167167
if (!empty($additionalData)) {
168168
$additionalData = $this->serializer->unserialize($additionalData);
169169
if (is_array($additionalData) && isset($additionalData[Swatch::SWATCH_INPUT_TYPE_KEY])) {
170-
$this->cleanEavAttributeOptionSwatchValues($attribute->getOption());
170+
$option = $attribute->getOption() ?: [];
171+
$this->cleanEavAttributeOptionSwatchValues($option);
171172
unset($additionalData[Swatch::SWATCH_INPUT_TYPE_KEY]);
172173
$attribute->setData('additional_data', $this->serializer->serialize($additionalData));
173174
}
@@ -246,7 +247,8 @@ protected function saveSwatchParams(Attribute $attribute)
246247
{
247248
if ($this->swatchHelper->isVisualSwatch($attribute)) {
248249
$this->processVisualSwatch($attribute);
249-
$this->cleanTextSwatchValuesAfterSwitch($attribute->getOptiontext());
250+
$attributeOptions = $attribute->getOptiontext() ?: [];
251+
$this->cleanTextSwatchValuesAfterSwitch($attributeOptions);
250252
} elseif ($this->swatchHelper->isTextSwatch($attribute)) {
251253
$this->processTextualSwatch($attribute);
252254
}
@@ -283,10 +285,10 @@ protected function processVisualSwatch(Attribute $attribute)
283285
* Clean swatch option values after switching to the dropdown type.
284286
*
285287
* @param array $attributeOptions
286-
* @param null $swatchType
288+
* @param int|null $swatchType
287289
* @throws \Magento\Framework\Exception\LocalizedException
288290
*/
289-
private function cleanEavAttributeOptionSwatchValues($attributeOptions, $swatchType = null)
291+
private function cleanEavAttributeOptionSwatchValues(array $attributeOptions, int $swatchType = null)
290292
{
291293
if (count($attributeOptions) && isset($attributeOptions['value'])) {
292294
$optionsIDs = array_keys($attributeOptions['value']);
@@ -301,7 +303,7 @@ private function cleanEavAttributeOptionSwatchValues($attributeOptions, $swatchT
301303
* @param array $attributeOptions
302304
* @throws \Magento\Framework\Exception\LocalizedException
303305
*/
304-
private function cleanTextSwatchValuesAfterSwitch($attributeOptions)
306+
private function cleanTextSwatchValuesAfterSwitch(array $attributeOptions)
305307
{
306308
$this->cleanEavAttributeOptionSwatchValues($attributeOptions, Swatch::SWATCH_TYPE_TEXTUAL);
307309
}

app/code/Magento/Swatches/Model/ResourceModel/Swatch.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ public function saveDefaultSwatchOption($id, $defaultValue)
3939
}
4040

4141
/**
42-
* Cleaned swatch option values when switching to dropdown input type
42+
* Cleaned swatch option values when switching to dropdown input type.
4343
*
44-
* @param $optionIDs
45-
* @param $type
44+
* @param array $optionIDs
45+
* @param int $type
4646
* @throws \Magento\Framework\Exception\LocalizedException
4747
*/
48-
public function clearSwatchOptionByOptionIdAndType($optionIDs, $type = null)
48+
public function clearSwatchOptionByOptionIdAndType(array $optionIDs, int $type = null)
4949
{
5050
if (count($optionIDs)) {
5151
foreach ($optionIDs as $optionId) {

app/code/Magento/Swatches/Test/Unit/Model/Plugin/EavAttributeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function testBeforeSaveTextSwatch()
191191

192192
/**
193193
* @expectedException \Magento\Framework\Exception\InputException
194-
* @expectedExceptionMessage Admin is a required field in the each row
194+
* @expectedExceptionMessage Admin is a required field in each row
195195
*/
196196
public function testBeforeSaveWithFailedValidation()
197197
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"Admin is a required field in the each row","Admin is a required field in the each row"
1+
"Admin is a required field in each row","Admin is a required field in each row"
22
"Update Product Preview Image","Update Product Preview Image"
33
"Filtering by this attribute will update the product image on catalog page","Filtering by this attribute will update the product image on catalog page"
44
"Use Product Image for Swatch if Possible","Use Product Image for Swatch if Possible"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ CSV,CSV
180180
"Please enter a valid value from list","Please enter a valid value from list"
181181
"Please enter valid SKU key.","Please enter valid SKU key."
182182
"Please enter a valid number.","Please enter a valid number."
183-
"Admin is a required field in the each row.","Admin is a required field in the each row."
183+
"Admin is a required field in each row.","Admin is a required field in each row."
184184
"Please fix this field.","Please fix this field."
185185
"Please enter a valid date (ISO).","Please enter a valid date (ISO)."
186186
"Please enter only digits.","Please enter only digits."

lib/web/i18n/en_US.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Submit,Submit
9595
"Please enter valid SKU key.","Please enter valid SKU key."
9696
"Please enter a valid number.","Please enter a valid number."
9797
"This is required field","This is required field"
98-
"Admin is a required field in the each row.","Admin is a required field in the each row."
98+
"Admin is a required field in each row.","Admin is a required field in each row."
9999
"Password cannot be the same as email address.","Password cannot be the same as email address."
100100
"Please fix this field.","Please fix this field."
101101
"Please enter a valid email address.","Please enter a valid email address."

lib/web/mage/validation.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,15 +1562,15 @@
15621562
],
15631563
'required-text-swatch-entry': [
15641564
tableSingleValidation,
1565-
$.mage.__('Admin is a required field in the each row.')
1565+
$.mage.__('Admin is a required field in each row.')
15661566
],
15671567
'required-visual-swatch-entry': [
15681568
tableSingleValidation,
1569-
$.mage.__('Admin is a required field in the each row.')
1569+
$.mage.__('Admin is a required field in each row.')
15701570
],
15711571
'required-dropdown-attribute-entry': [
15721572
tableSingleValidation,
1573-
$.mage.__('Admin is a required field in the each row.')
1573+
$.mage.__('Admin is a required field in each row.')
15741574
],
15751575
'validate-item-quantity': [
15761576
function (value, element, params) {

0 commit comments

Comments
 (0)