@@ -167,7 +167,7 @@ protected function convertSwatchToDropdown(Attribute $attribute)
167
167
$ additionalData = $ this ->serializer ->unserialize ($ additionalData );
168
168
if (is_array ($ additionalData ) && isset ($ additionalData [Swatch::SWATCH_INPUT_TYPE_KEY ])) {
169
169
if ($ additionalData [Swatch::SWATCH_INPUT_TYPE_KEY ] == Swatch::SWATCH_INPUT_TYPE_VISUAL ) {
170
- $ this ->cleanEavAttributeOptionSwatchValues ($ attribute );
170
+ $ this ->cleanEavAttributeOptionSwatchValues ($ attribute-> getOption () );
171
171
}
172
172
unset($ additionalData [Swatch::SWATCH_INPUT_TYPE_KEY ]);
173
173
$ attribute ->setData ('additional_data ' , $ this ->serializer ->serialize ($ additionalData ));
@@ -176,22 +176,6 @@ protected function convertSwatchToDropdown(Attribute $attribute)
176
176
}
177
177
}
178
178
179
- /**
180
- * Clean swatch option values after switching to the dropdown type.
181
- *
182
- * @param Attribute $attribute
183
- * @throws \Magento\Framework\Exception\LocalizedException
184
- */
185
- private function cleanEavAttributeOptionSwatchValues (Attribute $ attribute )
186
- {
187
- if (count ($ attribute ->getOption ())) {
188
- $ options = $ attribute ->getOption ();
189
- $ optionsIDs = array_keys ($ options ['value ' ]);
190
-
191
- $ this ->swatchResource ->clearSwatchOptionByOptionId ($ optionsIDs );
192
- }
193
- }
194
-
195
179
/**
196
180
* Creates array which link new option ids
197
181
*
@@ -263,7 +247,7 @@ protected function saveSwatchParams(Attribute $attribute)
263
247
{
264
248
if ($ this ->swatchHelper ->isVisualSwatch ($ attribute )) {
265
249
$ this ->processVisualSwatch ($ attribute );
266
- $ this ->cleanTextSwatchValuesAfterSwitch ($ attribute );
250
+ $ this ->cleanTextSwatchValuesAfterSwitch ($ attribute-> getOptiontext () );
267
251
} elseif ($ this ->swatchHelper ->isTextSwatch ($ attribute )) {
268
252
$ this ->processTextualSwatch ($ attribute );
269
253
}
@@ -296,23 +280,34 @@ protected function processVisualSwatch(Attribute $attribute)
296
280
}
297
281
}
298
282
283
+
299
284
/**
300
- * Cleaning the text type of swatch option values after switching.
285
+ * Clean swatch option values after switching to the dropdown type .
301
286
*
302
- * @param $attribute
287
+ * @param array $attributeOptions
288
+ * @param null $swatchType
289
+ * @throws \Magento\Framework\Exception\LocalizedException
303
290
*/
304
- private function cleanTextSwatchValuesAfterSwitch ( Attribute $ attribute )
291
+ private function cleanEavAttributeOptionSwatchValues ( $ attributeOptions , $ swatchType = null )
305
292
{
306
- $ optionsIDs = [];
307
- if (count ($ attribute ->getOptiontext ())) {
308
- $ options = $ attribute ->getOptiontext ();
309
- if (count ($ options ) && isset ($ options ['value ' ])) {
310
- $ optionsIDs = array_keys ($ options ['value ' ]);
311
- $ this ->swatchResource ->clearSwatchOptionTextByOptionId ($ optionsIDs , Swatch::SWATCH_TYPE_TEXTUAL );
312
- }
293
+ if (count ($ attributeOptions ) && isset ($ attributeOptions ['value ' ])) {
294
+ $ optionsIDs = array_keys ($ attributeOptions ['value ' ]);
295
+
296
+ $ this ->swatchResource ->clearSwatchOptionByOptionIdAndType ($ optionsIDs , $ swatchType );
313
297
}
314
298
}
315
299
300
+ /**
301
+ * Cleaning the text type of swatch option values after switching.
302
+ *
303
+ * @param array $attributeOptions
304
+ * @throws \Magento\Framework\Exception\LocalizedException
305
+ */
306
+ private function cleanTextSwatchValuesAfterSwitch ($ attributeOptions )
307
+ {
308
+ $ this ->cleanEavAttributeOptionSwatchValues ($ attributeOptions , Swatch::SWATCH_TYPE_TEXTUAL );
309
+ }
310
+
316
311
/**
317
312
* @param string $value
318
313
* @return int
0 commit comments