@@ -167,7 +167,7 @@ protected function convertSwatchToDropdown(Attribute $attribute)
167167 $ additionalData = $ this ->serializer ->unserialize ($ additionalData );
168168 if (is_array ($ additionalData ) && isset ($ additionalData [Swatch::SWATCH_INPUT_TYPE_KEY ])) {
169169 if ($ additionalData [Swatch::SWATCH_INPUT_TYPE_KEY ] == Swatch::SWATCH_INPUT_TYPE_VISUAL ) {
170- $ this ->cleanEavAttributeOptionSwatchValues ($ attribute );
170+ $ this ->cleanEavAttributeOptionSwatchValues ($ attribute-> getOption () );
171171 }
172172 unset($ additionalData [Swatch::SWATCH_INPUT_TYPE_KEY ]);
173173 $ attribute ->setData ('additional_data ' , $ this ->serializer ->serialize ($ additionalData ));
@@ -176,22 +176,6 @@ protected function convertSwatchToDropdown(Attribute $attribute)
176176 }
177177 }
178178
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-
195179 /**
196180 * Creates array which link new option ids
197181 *
@@ -263,7 +247,7 @@ protected function saveSwatchParams(Attribute $attribute)
263247 {
264248 if ($ this ->swatchHelper ->isVisualSwatch ($ attribute )) {
265249 $ this ->processVisualSwatch ($ attribute );
266- $ this ->cleanTextSwatchValuesAfterSwitch ($ attribute );
250+ $ this ->cleanTextSwatchValuesAfterSwitch ($ attribute-> getOptiontext () );
267251 } elseif ($ this ->swatchHelper ->isTextSwatch ($ attribute )) {
268252 $ this ->processTextualSwatch ($ attribute );
269253 }
@@ -296,23 +280,34 @@ protected function processVisualSwatch(Attribute $attribute)
296280 }
297281 }
298282
283+
299284 /**
300- * Cleaning the text type of swatch option values after switching.
285+ * Clean swatch option values after switching to the dropdown type .
301286 *
302- * @param $attribute
287+ * @param array $attributeOptions
288+ * @param null $swatchType
289+ * @throws \Magento\Framework\Exception\LocalizedException
303290 */
304- private function cleanTextSwatchValuesAfterSwitch ( Attribute $ attribute )
291+ private function cleanEavAttributeOptionSwatchValues ( $ attributeOptions , $ swatchType = null )
305292 {
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 );
313297 }
314298 }
315299
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+
316311 /**
317312 * @param string $value
318313 * @return int
0 commit comments