Skip to content

Commit bbf0aed

Browse files
committed
[Backport 2.3] add swatch option: prevent loosing data and default value if data is not populated via adminhtml
1 parent 927a6e2 commit bbf0aed

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,17 @@ protected function setProperOptionsArray(Attribute $attribute)
130130
$swatchesArray = $attribute->getData('swatchtext');
131131
}
132132
if ($canReplace == true) {
133-
$attribute->setData('option', $optionsArray);
134-
$attribute->setData('default', $defaultValue);
135-
$attribute->setData('swatch', $swatchesArray);
133+
if (!empty($optionsArray)) {
134+
$attribute->setData('option', $optionsArray);
135+
}
136+
if (!empty($defaultValue)) {
137+
$attribute->setData('default', $defaultValue);
138+
} else {
139+
$attribute->setData('default', [0 => $attribute->getDefaultValue()]);
140+
}
141+
if (!empty($swatchesArray)) {
142+
$attribute->setData('swatch', $swatchesArray);
143+
}
136144
}
137145
}
138146

0 commit comments

Comments
 (0)