问题描述
因此,我有一个可配置产品,其属性名为Size,带有文本色板选项S / M和L。在此属性上,我选择了大小M作为默认值。现在,当我进入可配置产品页面时,我想在前端预先选择此选项。
当前,我在我覆盖swatch-renderer.js文件的位置进行了混合,目前的临时解决方案是选择第二个div.swatch-option并触发点击,以便在每次加载页面时都对其进行预先选择。
define([
'jquery','underscore','mage/translate','jquery-ui-modules/widget'
],function ($,_) {
'use strict';
return function (widget) {
$.widget('mage.SwatchRenderer',widget,{
_init: function () {
if ($(this.element).attr('data-rendered')) {
return;
}
$(this.element).attr('data-rendered',true);
if (_.isEmpty(this.options.jsonConfig.images)) {
this.options.useAjax = true;
this._debouncedLoadProductMedia = _.debounce(this._LoadProductMedia.bind(this),500);
}
if (this.options.jsonConfig !== '' && this.options.jsonSwatchConfig !== '') {
this.options.jsonConfig.mappedAttributes = _.clone(this.options.jsonConfig.attributes);
this._sortAttributes();
this._RenderControls();
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) {
console.log(index);
let swatchOption;
if ($(item).find('div.swatch-option').attr("aria-label") === 'S') {
swatchOption = $(item).find('div.swatch-option').eq(1);
} else {
swatchOption = $(item).find('div.swatch-option').first();
}
if (swatchOption.length && !$(item).find('div.swatch-option').hasClass('selected')) {
swatchOption.trigger('click');
}
});
}
this._setPreSelectedgallery();
$(this.element).trigger('swatch.initialized');
} else {
console.log('SwatchRenderer: No input data received');
}
this.options.tierPriceTemplate = $(this.options.tierPriceTemplateSelector).html();
}
});
return $.mage.SwatchRenderer;
};
});
因为我不想对此进行硬编码,所以我正在寻找有关如何检入mixin的示例选项设置为默认值的解决方案。
我应该以哪种方式看待任何建议或提示。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)