6
6
namespace Magento \Swatches \Model \Plugin ;
7
7
8
8
use Magento \Catalog \Model \ResourceModel \Eav \Attribute ;
9
- use Magento \Swatches \Model \Swatch ;
10
9
use Magento \Framework \Exception \InputException ;
10
+ use Magento \Swatches \Model \Swatch ;
11
11
12
12
/**
13
13
* Plugin model for Catalog Resource Attribute
@@ -118,9 +118,17 @@ protected function setProperOptionsArray(Attribute $attribute)
118
118
$ swatchesArray = $ attribute ->getData ('swatchtext ' );
119
119
}
120
120
if ($ canReplace == true ) {
121
- $ attribute ->setData ('option ' , $ optionsArray );
122
- $ attribute ->setData ('default ' , $ defaultValue );
123
- $ attribute ->setData ('swatch ' , $ swatchesArray );
121
+ if (!empty ($ optionsArray )) {
122
+ $ attribute ->setData ('option ' , $ optionsArray );
123
+ }
124
+ if (!empty ($ defaultValue )) {
125
+ $ attribute ->setData ('default ' , $ defaultValue );
126
+ } else {
127
+ $ attribute ->setData ('default ' , [0 => $ attribute ->getDefaultValue ()]);
128
+ }
129
+ if (!empty ($ swatchesArray )) {
130
+ $ attribute ->setData ('swatch ' , $ swatchesArray );
131
+ }
124
132
}
125
133
}
126
134
@@ -316,7 +324,7 @@ protected function getAttributeOptionId($optionId)
316
324
*/
317
325
protected function isOptionForDelete (Attribute $ attribute , $ optionId )
318
326
{
319
- $ isOptionForDelete = $ attribute ->getData ('option/delete/ ' . $ optionId );
327
+ $ isOptionForDelete = $ attribute ->getData ('option/delete/ ' . $ optionId );
320
328
return isset ($ isOptionForDelete ) && $ isOptionForDelete ;
321
329
}
322
330
@@ -333,7 +341,7 @@ protected function loadSwatchIfExists($optionId, $storeId)
333
341
$ collection ->addFieldToFilter ('option_id ' , $ optionId );
334
342
$ collection ->addFieldToFilter ('store_id ' , $ storeId );
335
343
$ collection ->setPageSize (1 );
336
-
344
+
337
345
$ loadedSwatch = $ collection ->getFirstItem ();
338
346
if ($ loadedSwatch ->getId ()) {
339
347
$ this ->isSwatchExists = true ;
@@ -356,7 +364,6 @@ protected function saveSwatchData($swatch, $optionId, $storeId, $type, $value)
356
364
if ($ this ->isSwatchExists ) {
357
365
$ swatch ->setData ('type ' , $ type );
358
366
$ swatch ->setData ('value ' , $ value );
359
-
360
367
} else {
361
368
$ swatch ->setData ('option_id ' , $ optionId );
362
369
$ swatch ->setData ('store_id ' , $ storeId );
0 commit comments