Magento2: Color attribute taking swatch instead of Drop down option for configurable options,

Created on 19 Apr 2017  路  31Comments  路  Source: magento/magento2

Preconditions

  1. Magento: 2.1.6

Steps to reproduce

  1. Login to admin-panel and go to the Product >> Attributes.
  2. Created color attribute with Catalog Input Type for Store Owner to "Drop down"
  3. Go to the front-end and open any configurable product with COLOR options.

    Expected result

  4. It should display Dropdown select box.

Actual result

  1. It is showing swatch.

Kindly see screenshots.
screenshot-10 16 16 212 2017-04-19 14-37-19
screenshot-10 16 16 212 2017-04-19 14-30-41

Fixed in 2.2.x Fixed in 2.3.x Clear Description Confirmed Format is valid Ready for Work Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x bug report

Most helpful comment

Using your preferred database editor, navigate and find the table eav_attribute_option_swatch

Magento will store a row for each of the swatches you have configured in the Magento Admin.
Pay attention to the option_id select each row you want to remove as a swatch not forgetting to remove any other associated rows which contain the same option_id.

Once deleted. Head over to your Magento admin panel, clear the magento cache and static file cache.

I was able to solve my issue in 5 minutes. I hope this helps somebody else

All 31 comments

I am also experiencing this issue, after upgrade from 2.1.4 to 2.1.6.

+1 I had it working originally as a dropdown. Then changed it to a swatch, now I can't go back to a dropdown. The setting saves but the front end ignores it. I assume is is because the extra attributes are created for the options when it is turned into a swatch, then not removed. No amount of cache clearing fixes it.

+1 Also had this issue after switching to swatch then back to dropdown. When the product detail page is showing, we're seeing markup with 'swatch-input'. Note, we upgraded from Magento 1.9 to Magento 2.1.6 and imported the data using the magento import tool. It was appearing fine as a drop down until we changed the "Catalog Input Type for Store Owner" from dropdown to Text Swatch.

Markup that appeared after switching to text swatch, and remained after switching back to dropdown:
input class="swatch-input super-attribute-select" name="super_attribute[133]" type="text" value="" data-selector="super_attribute[133]" data-validate="{required:true}" aria-required="true" aria-invalid="true" style="visibility: hidden; position:absolute; left:-1000px"

Any one get resolution ?

I traced the code back to the isProductHasSwatchAttribute in the Magento\Swatches\Block\Product\Renderer\Configurable class. It's using the SwatchAttributesProvider class to check for swatch data.

It looks like there is some leftover data in the eav_attribute_option_swatch table after switching back to the dropdown. Once I cleaned out the swatch values that were created when we switched to the text swatch, it worked as expected again.

To see if there is data, and get the swatch_ids, use this sql query:
Note: Change _YOUR_ATTRIBUTE_ID_ to the id of your attribute.
SQL

SELECT o.option_id, o.attribute_id, s.swatch_id
FROM eav_attribute_option AS o
JOIN eav_attribute_option_swatch AS s ON(o.option_id = s.option_id)
WHERE o.attribute_id = YOUR_ATTRIBUTE_ID
ORDER BY s.swatch_id ASC;

Having this issue also on 2.1.7.

Me too, same issue in 2.1.7

We are also facing the same issues on Magento 2.1.7. If anyone finds a solution for this issue then please share it with all.

@gclift gave a manual solution above. It will need some db editing.

Hi @vishveskrish.
Thanks for reporting this issue.
Internal ticket MAGETWO-70321 was created.

Using your preferred database editor, navigate and find the table eav_attribute_option_swatch

Magento will store a row for each of the swatches you have configured in the Magento Admin.
Pay attention to the option_id select each row you want to remove as a swatch not forgetting to remove any other associated rows which contain the same option_id.

Once deleted. Head over to your Magento admin panel, clear the magento cache and static file cache.

I was able to solve my issue in 5 minutes. I hope this helps somebody else

Thanks @sanjeshsodha !!

I can confirm this works.

Thanks @sanjeshsodha your solution worked for us.
@magento-team is there any update as to why this happens and when it will be fixed?

@wildcard27, well, I could tell you why it happens is this scenario: https://github.com/magento/magento2/issues/9923#issuecomment-310601303

But an official fix might take a couple more months to get implemented and released, speaking optimistically.

@korostii So not as simple as programmatically deleting all of the entries in the eav_attribute_option_swatch table relating to the attribute being saved if the frontend type is changed? If so, this could be implemented in a plugin as a 'quick' fix for now.

@wildcard27, That might break the actual swatch attributes that should _not_ look like dropdown, so be careful down that road. But yeah, that _might_ work.

Personally, I don't think there's a "quick" solutions here. I mean, there were whole classes written around implementing some parts of the swatches' rendering, it seems to be an interdependent a fragile thing.

I wish the guys at Magento would test this better though. I mean, they have the resources for it and ytet they release this piece of buggy functionality in a patch version while ignoring hundreds of safe one-liners that await months for a backport. Frankly, that whole routine makes me somewhat angry every time I stumble upon its results, again and again.

I was able to fix this by:

Step 1: Finding my attribute id by:
SELECT * FROM magento_store.eav_attribute where attribute_code = 'you_attribute_code'

Step 2: Running the SQL Query referenced above to confirm the swatch entries:
SELECT o.option_id, o.attribute_id, s.swatch_id FROM eav_attribute_option AS o JOIN eav_attribute_option_swatch AS s ON(o.option_id = s.option_id) WHERE o.attribute_id = 'you_attribute_id' ORDER BY o.option_id ASC;

Step 3: Delete the swatch entries.
For me I didn't have any attributes that should be swatches, so I truncated the eav_attribute_option_swatch table and then cleared all the caches, and my swatches turned into dropdowns.

If you have more complicated setup with legit swatches, you may want to only delete the results from the query in step 2.

@vishveskrish, thank you for your report.
We've created internal ticket(s) MAGETWO-70321 to track progress on the issue.

Hello @magento-engcom-team,

Do we get the resolution?

I am also experiencing this issue, after upgrade from 2.1.3 to 2.2.0
Any update for this issue?

website

What are these blank fields (super attribute) - unwanted fields showing not sure what is wrong with M2.2.1

@RakeshJesadiya , Yes I got the resolution

mageconf

Closed because duplicate #12695

Thank you very much @saeohioalpha . You save my day. your solution is working fine but i am confused like each time when i will create configurable product then i need to do this step?

Still magento not resolved this issue?

Temporary work around:

Change your attribute to dropdown from swatch from admin

go to database >> table eav_attribute_option_swatch

delete all related swatch attribute row from this table

deploy static content and flush cache.

Hi @vishveskrish. Thank you for your report.
The issue has been fixed in magento/magento2#17750 by @nmalevanec in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

@ishakhsuvarov I'm still having this issue on 2.3.0. I'm unable to change my attribute type from Text Swatch to Dropdown, even if I truncate the swatch options table.

I also had a similar issue but believe the attribute was changed from a dropdown to a text swatch. On the front end, it looks like below. I only found out about this issue by looking through bug reports. After I saw this report, I changed it back to a dropdown and it works again.
Magento 2.3.3
2020-03-10_23-55-37

Was this page helpful?
0 / 5 - 0 ratings