Magento2: Default value for non required Drop Down product attribute

Created on 25 Feb 2016  Â·  22Comments  Â·  Source: magento/magento2

When creating a new Drop Down Product attribute that is not required, the first option added has the "Is Default" radio button selected. If the attribute is set to not be required, the radio button shouldn't automatically be set for any option either when first creating the attribute or later when coming back to edit it.

The attribute is being used in an attribute set where the particular attribute doesn't apply to a couple of products, though the other attributes in the set do. Because of "Is Default" being set automatically, all products using that attribute set end up having a value even if it doesn't apply.

Catalog Ready for Work bug report

Most helpful comment

As a fix, in file vendor/magento/module-catalog/view/adminhtml/web/js/options.js or app/code/Magento/Catalog/view/adminhtml/web/js/options.js go to lines 45 - 47 and comment them out:

//   if (!this.totalItems) {
//     data.checked = 'checked';
//   }

Check if pub/static/adminhtml/Magento/backend/en_US/Magento_Catalog/js/options.js (and the same file in other language sub folders in pub/static/adminhtml/Magento/backend/) reflects that change.

You may need to remove the already set default values from the database.
To do that, run SELECT * FROM eav_attribute WHERE default_value IS NOT NULL AND frontend_input != 'boolean'; to get possible affected attributes. Let's say you found that IDs 90 and 211 should be changed so that the have no default value anymore; run this query:
UPDATE eav_attribute SET default_value = NULL WHERE attribute_id IN (90,211);

For visual- and text-swatches you can do the same, the files are:
vendor/magento/module-swatches/view/adminhtml/web/js/visual.js or app/code/Magento/Swatches/view/adminhtml/web/js/visual.js
and
vendor/magento/module-swatches/view/adminhtml/web/js/text.js or app/code/Magento/Swatches/view/adminhtml/web/js/text.js

All 22 comments

Hi,

Thank you for reporting the issue.
Internal ticket MAGETWO-49780 is created for this issue.

In your case I think it's possible to add a new option 'None' and set it as default. Will it work for you?

Thanks,
Kateryna.

It is something we had talked about when finding this issue but it is causing additional work arounds that we have to do that we wouldn't if no value was there.

@katmoon solution You proposed sounds more like workaround not a proper fix

@werdlv You are right. It is a workaround.

For a workaround you can use the multi-select. It comes in to your product unselected by default.

The workaround of using multi-select does work. However, with a lot of options, the multi-select workaround makes for a potentially very long open list and ton of scrolling. The other problem is that if there is a fix down the road for drop down, you can not change the attribute from multi-select to drop down, so would cause a ton of work to set everything up again.

Alternatively, you can set the dropdown in the SQL database to "null" under the eav attribute. However, this also has some issues in that any time you make a change to an attribute, it resets the default and you need to again go to the SQL database to set to null set again. In addition, if a dropdown attribute is set in a product, and you want to later set it to the null set, you can not, you are forced to choose something.

I am in the process of setting up 7500+ skus, so want to know recommendation:

  1. Set all the attributes to multi-select and have very long lists of attribute options and making any fix by magento in the future not viable.
  2. Set all the attributes to drop down, use the null setting, and then wait for the fix from Magento.

Please advise - thanks!

As a fix, in file vendor/magento/module-catalog/view/adminhtml/web/js/options.js or app/code/Magento/Catalog/view/adminhtml/web/js/options.js go to lines 45 - 47 and comment them out:

//   if (!this.totalItems) {
//     data.checked = 'checked';
//   }

Check if pub/static/adminhtml/Magento/backend/en_US/Magento_Catalog/js/options.js (and the same file in other language sub folders in pub/static/adminhtml/Magento/backend/) reflects that change.

You may need to remove the already set default values from the database.
To do that, run SELECT * FROM eav_attribute WHERE default_value IS NOT NULL AND frontend_input != 'boolean'; to get possible affected attributes. Let's say you found that IDs 90 and 211 should be changed so that the have no default value anymore; run this query:
UPDATE eav_attribute SET default_value = NULL WHERE attribute_id IN (90,211);

For visual- and text-swatches you can do the same, the files are:
vendor/magento/module-swatches/view/adminhtml/web/js/visual.js or app/code/Magento/Swatches/view/adminhtml/web/js/visual.js
and
vendor/magento/module-swatches/view/adminhtml/web/js/text.js or app/code/Magento/Swatches/view/adminhtml/web/js/text.js

Any updates on this issue? The workaround of using multi-select doesn't work for me.

the same problem applies to text- and visual-swatches, too

Am waiting for a fix for this issue too. Thanks

I think this problem is fixed in Magento 2.1.0-rc2

The issue should be fixed by another internal ticket MAGETWO-50123 in the next release.

As far as I can see it's fixed in Magento 2.1, correct?

Any updates on this?

As far as we are using Magento 2.1 and it is not working I think here is a lack of releasing the patch?

MAGETWO-50123 is going to be fixed in 2.2 and 2.1.x versions.

Can you confirm this was fixed as part of 2.1.1 as I can't find any notification on this within the patch notes for 2.1.1?

Am waiting for a fix on this too.

Still have this issue in Magento CE ver. 2.1.2.
Any news on when this might go live?

Hi @jh-tom @measureddesigns will be fixed in internal ticket MAGETWO-57024 for 2.1 version

This issue has been fixed in 2.2.0, and will be delivered to 2.1.x soon.

@elenleonova Is this fixed for the 2.1.3? If not is there any intermediate solution we can implement (aside from the multiselect)

Thanks!

Hi

 

I will try this in the next couple of months.
 

Regards

Nathan

 
 

Sent: Thursday, February 02, 2017 at 1:43 AM
From: gabriel-sf notifications@github.com
To: magento/magento2 magento2@noreply.github.com
Cc: shires-boy nathan.todd@gmx.co.uk, Comment comment@noreply.github.com
Subject: Re: [magento/magento2] Default value for non required Drop Down product attribute (#3545)

@elenleonova Is this fixed for the 2.1.3? If not is there any intermediate solution we can implement (aside from the multiselect)

Thanks!

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

 

Was this page helpful?
0 / 5 - 0 ratings