0

Can anyone let me know that in the configurable product dropdown attribute have only one option available so it should be auto select ?

enter image description here

In the screenshot you can see that only A is available so after selection of other attribute it should auto select.

4
  • community.magento.com/t5/Magento-2-x-Programming/…
    – Pramod
    Commented Aug 17, 2020 at 11:20
  • this is not the solution, I have to auto select if have only one option available. The above link is by default first option will be selected. Commented Aug 17, 2020 at 11:47
  • 1
    if you have only one option then why are you making configurable product ?just a curiosity
    – Pramod
    Commented Aug 17, 2020 at 11:50
  • there is 4 to 5 attribute, and after selection of other attribute this need to be auto select. I think you are not getting my question. Commented Aug 17, 2020 at 11:56

1 Answer 1

0

Maybe try replacing

if (i == 0) {this.options.values[attributeId] = options[i].id;}  

with

if (options.length == 1 ) {this.options.values[attributeId] = options[i].id;} 

app/design/frontend/Vendorname/themenamme/Magento_ConfigurableProduct/web/js/configurable.js

just before the end of for loop as explained in this example.

Note: In my case, configurable products are only with selectable dropdown and with these as options

Colors and Sizes, few of the colors have only one option like black. So, the above code works well by pre-selecting if the Colors options have only one option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.