Skip to content

Instantly share code, notes, and snippets.

@mborodov
Created January 14, 2019 06:13
Show Gist options
  • Save mborodov/c8abb2045d7d4b5730ed0665ab39821e to your computer and use it in GitHub Desktop.
Save mborodov/c8abb2045d7d4b5730ed0665ab39821e to your computer and use it in GitHub Desktop.
Pre-select first option for Magento 2 options swatcher
if (this.options.jsonConfig.attributes.length > 0) {
var selectswatch = this.element.find('.' + this.options.classes.attributeClass + ' .' + this.options.classes.attributeOptionsWrapper);
$.each(selectswatch, function (index, item) {
var swatchOption = $(item).find('div.swatch-option').first();
if (swatchOption.length && !$(item).find('div.swatch-option').hasClass('selected')) {
swatchOption.trigger('click');
}
});
}
@mborodov
Copy link
Author

Need add this code to function _onGalleryLoaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment