0

I'm new in Magento 2 frontend development (and in development in general) and I am really lost at it, it's being hard to get arround some concepts, so I would like to ask for help in some specific things. I was asked to add the following functionality to my store:

Whenever someone enters a configurable product, the first option should be selected. That I achieved it with the help of this post: Magento 2: How to set default option in configurable options?

When someone in my store changes an options, the following ones have to update to the first option possible in the dropdown. I tried this post to achieve that: Magento 2: How to Keep Next Options value selected while changing previous option value on configurable dropdown

But, with this solution, I get the following result:

Product the first time I open it

When I first enter the product, everything works fine

Product after changing first attribute

But, when I change the option of the first attribute, what Magento 2 is trying to do is to select the same option it was selected before. That is not available, so the option puts itself blank and the following options do not update with the desired options. I'm really stuck in this, and this doesn't seem to have been asked before, as I have been reserching since yesterday with no luck. Can someone help me with this, please?

Thank you!

1 Answer 1

0

I think I have found a reliable solution, so I will post it in case someone needs it. Using this solution: Magento 2: How to Keep Next Options value selected while changing previous option value on configurable dropdown

I have replaced this:

           if (nextSelectedVal.length) {
                $("#" + nextId).val(nextSelectedVal);
                $("#" + nextId).change();
            }

For this:

           if (nextSelectedVal.length) {
                    $("#" + nextId + ' :nth-child(2)').prop('selected', true);
                    $("#" + nextId).change();
                }

With this change, in all the testing I have done, whenever I change an option, the following options update with the first available option, whatever its value may be

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.