diff --git a/app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js b/app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js index ae564610e4b0b..4aeafd72aa8ee 100644 --- a/app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js +++ b/app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js @@ -26,9 +26,9 @@ define([ state: {}, priceFormat: {}, optionTemplate: '<%- data.label %>' + - '<% if (typeof data.finalPrice.value !== "undefined") { %>' + - ' <%- data.finalPrice.formatted %>' + - '<% } %>', + '<% if (typeof data.finalPrice.value !== "undefined") { %>' + + ' <%- data.finalPrice.formatted %>' + + '<% } %>', mediaGallerySelector: '[data-gallery-role=gallery-placeholder]', mediaGalleryInitial: null, slyOldPriceSelector: '.sly-old-price', @@ -123,8 +123,6 @@ define([ if (this.options.spConfig.inputsInitialized) { this._setValuesByAttribute(); } - - this._setInitialOptionsLabels(); }, /** @@ -160,18 +158,6 @@ define([ }, this)); }, - /** - * Set additional field with initial label to be used when switching between options with different prices. - * @private - */ - _setInitialOptionsLabels: function () { - $.each(this.options.spConfig.attributes, $.proxy(function (index, element) { - $.each(element.options, $.proxy(function (optIndex, optElement) { - this.options.spConfig.attributes[index].options[optIndex].initialLabel = optElement.label; - }, this)); - }, this)); - }, - /** * Set up .on('change') events for each option element to configure the option. * @private @@ -385,18 +371,13 @@ define([ prevConfig, index = 1, allowedProducts, - allowedProductsByOption, - allowedProductsAll, i, j, - finalPrice = parseFloat(this.options.spConfig.prices.finalPrice.amount), + basePrice = parseFloat(this.options.spConfig.prices.basePrice.amount), optionFinalPrice, optionPriceDiff, optionPrices = this.options.spConfig.optionPrices, - allowedOptions = [], - indexKey, - allowedProductMinPrice, - allowedProductsAllMinPrice; + allowedProductMinPrice; this._clearSelect(element); element.options[0] = new Option('', ''); @@ -408,61 +389,39 @@ define([ } if (options) { - for (indexKey in this.options.spConfig.index) { - /* eslint-disable max-depth */ - if (this.options.spConfig.index.hasOwnProperty(indexKey)) { - allowedOptions = allowedOptions.concat(_.values(this.options.spConfig.index[indexKey])); - } - } - - if (prevConfig) { - allowedProductsByOption = {}; - allowedProductsAll = []; + for (i = 0; i < options.length; i++) { + allowedProducts = []; + optionPriceDiff = 0; - for (i = 0; i < options.length; i++) { - /* eslint-disable max-depth */ + /* eslint-disable max-depth */ + if (prevConfig) { for (j = 0; j < options[i].products.length; j++) { // prevConfig.config can be undefined if (prevConfig.config && prevConfig.config.allowedProducts && prevConfig.config.allowedProducts.indexOf(options[i].products[j]) > -1) { - if (!allowedProductsByOption[i]) { - allowedProductsByOption[i] = []; - } - allowedProductsByOption[i].push(options[i].products[j]); - allowedProductsAll.push(options[i].products[j]); + allowedProducts.push(options[i].products[j]); } } - } - - if (typeof allowedProductsAll[0] !== 'undefined' && - typeof optionPrices[allowedProductsAll[0]] !== 'undefined') { - allowedProductsAllMinPrice = this._getAllowedProductWithMinPrice(allowedProductsAll); - finalPrice = parseFloat(optionPrices[allowedProductsAllMinPrice].finalPrice.amount); - } - } - - for (i = 0; i < options.length; i++) { - allowedProducts = prevConfig ? allowedProductsByOption[i] : options[i].products.slice(0); - optionPriceDiff = 0; - - if (typeof allowedProducts[0] !== 'undefined' && - typeof optionPrices[allowedProducts[0]] !== 'undefined') { - allowedProductMinPrice = this._getAllowedProductWithMinPrice(allowedProducts); - optionFinalPrice = parseFloat(optionPrices[allowedProductMinPrice].finalPrice.amount); - optionPriceDiff = optionFinalPrice - finalPrice; - options[i].label = options[i].initialLabel; - - if (optionPriceDiff !== 0) { - options[i].label += ' ' + priceUtils.formatPrice( - optionPriceDiff, - this.options.priceFormat, - true - ); + } else { + allowedProducts = options[i].products.slice(0); + + if (typeof allowedProducts[0] !== 'undefined' && + typeof optionPrices[allowedProducts[0]] !== 'undefined') { + allowedProductMinPrice = this._getAllowedProductWithMinPrice(allowedProducts); + optionFinalPrice = parseFloat(optionPrices[allowedProductMinPrice].finalPrice.amount); + optionPriceDiff = optionFinalPrice - basePrice; + + if (optionPriceDiff !== 0) { + options[i].label = options[i].label + ' ' + priceUtils.formatPrice( + optionPriceDiff, + this.options.priceFormat, + true); + } } } - if (allowedProducts.length > 0 || _.include(allowedOptions, options[i].id)) { + if (allowedProducts.length > 0) { options[i].allowedProducts = allowedProducts; element.options[index] = new Option(this._getOptionLabel(options[i]), options[i].id); @@ -470,16 +429,20 @@ define([ element.options[index].setAttribute('price', options[i].price); } - if (allowedProducts.length === 0) { - element.options[index].disabled = true; - } - element.options[index].config = options[i]; index++; } + if (i === 0) { + this.options.values[attributeId] = options[i].id; + } /* eslint-enable max-depth */ } + + if (window.location.href.indexOf('#') !== -1) { + this._parseQueryParams(window.location.href.substr(window.location.href.indexOf('#') + 1)); + } + } }, diff --git a/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js b/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js index 250141a942b10..78e569a862957 100644 --- a/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js +++ b/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js @@ -362,7 +362,7 @@ define([ isInProductView = false; productId = this.element.parents('.product-item-details') - .find('.price-box.price-final_price').attr('data-product-id'); + .find('.price-box.price-final_price').attr('data-product-id'); if (!productId) { // Check individual product. @@ -386,6 +386,8 @@ define([ container = this.element, classes = this.options.classes, chooseText = this.options.jsonConfig.chooseText, + selectedArray = []; // Variable declation for autoselect element array + showTooltip = this.options.showTooltip; $widget.optionsMap = {}; @@ -407,7 +409,7 @@ define([ if ($widget.options.enableControlLabel) { label += '' + - $('').text(item.label).html() + + item.label + '' + ''; } @@ -415,7 +417,7 @@ define([ if ($widget.inProductList) { $widget.productForm.append(input); input = ''; - listLabel = 'aria-label="' + $('').text(item.label).html() + '"'; + listLabel = 'aria-label="' + item.label + '"'; } else { listLabel = 'aria-labelledby="' + controlLabelId + '"'; } @@ -423,17 +425,17 @@ define([ // Create new control container.append( '