I would like to override Magento_Swatches/js/swatch-renderer.js
file using mixins concept.
I would like to club two functionalities in a single file. here is the code I have written please Note 2nd mixin functionality currently working
but the first mixin code is not working. But How do we combine two functionalities in a single mixin file?
Could you please correct me what is wrong here.
requirejs-config.js
var config = {
config: {
mixins: {
'Magento_Swatches/js/swatch-renderer': {
'Kensium_ConfigurableSku/js/model/configurable_swatch_pricerange': true
},
'Magento_Swatches/js/swatch-renderer': {
'Kensium_ConfigurableSku/js/model/configurable_swatch_pricerange2': true
}
}
}
};
configurable_swatch_pricerange.js
define(['jquery'], function ($) {
'use strict';
return function (configurable) {
$.widget('mage.SwatchRenderer', $['mage']['SwatchRenderer'], {
_init: function () {
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();
this._setPreSelectedGallery();
$(this.element).trigger('swatch.initialized');
} else {
console.log('SwatchRenderer: No input data received');
}
this.options.tierPriceTemplate = $(this.options.tierPriceTemplateSelector).html();
//custom code added here
$('div.product-info-main .product-info-price .price-container .price-label').html('');
$('div.product-info-main .product-info-price span .price').html(this.options.jsonConfig.final_price_range);
}
});
return $['mage']['SwatchRenderer'];
};
});
configurable_swatch_pricerange2.js
define([
'jquery',
'mage/utils/wrapper'
], function ($, wrapper) {
'use strict';
return function(targetModule) {
var updatePrice = targetModule.prototype._UpdatePrice;
var updatePriceWrapper = wrapper.wrap(updatePrice, function(original) {
var result = original();
var allSelected = true;
for(var i = 0; i < this.options.jsonConfig.attributes.length;i++) {
if (!$('div.product-info-main .product-options-wrapper .swatch-attribute.' + this.options.jsonConfig.attributes[i].code).attr('option-selected')){
allSelected = false;
}
}
if (allSelected) {
console.log("All swatch options selected");
}else {
console.log("Only one option selected");
$('div.product-info-main .product-info-price span .price').html(this.options.jsonConfig.final_price_range);
}
return result;
});
targetModule.prototype._UpdatePrice = updatePriceWrapper;
return targetModule;
};
});