Skip to content

Commit 5e98e6a

Browse files
author
Andrii Lugovyi
committed
MAGETWO-44825: Swatches does not update configurable product price
- refactoring, add undescorejs
1 parent 681bc1b commit 5e98e6a

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

app/code/Magento/Swatches/view/frontend/web/js/SwatchRenderer.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,15 @@
22
* Copyright © 2015 Magento. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5-
Number.prototype.formatMoney = function (c, d, t) { //this function helps format price
6-
var n = this,
7-
c = isNaN(c = Math.abs(c)) ? 2 : c,
8-
d = d == undefined ? "." : d,
9-
t = t == undefined ? "," : t,
10-
s = n < 0 ? "-" : "",
11-
i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
12-
j = (j = i.length) > 3 ? j % 3 : 0;
13-
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
14-
};
15-
16-
Array.prototype.intersection = function (a) {
17-
return this.filter(function (i) {
18-
return a.indexOf(i) >= 0;
19-
});
20-
};
215

22-
define(["jquery", "jquery/ui"], function ($) {
6+
define(['jquery', 'underscore', 'jquery/ui'], function ($, _) {
7+
'use strict';
8+
9+
/**
10+
* Parse params
11+
* @param {String} query
12+
* @returns {{}}
13+
*/
2314
$.parseParams = function (query) {
2415
var re = /([^&=]+)=?([^&]*)/g,
2516
decodeRE = /\+/g, // Regex for replacing addition symbol with a space
@@ -564,7 +555,7 @@ define(["jquery", "jquery/ui"], function ($) {
564555
return;
565556
}
566557

567-
if (products.intersection($widget.optionsMap[id][option].products).length <= 0) {
558+
if (_.intersection(products, $widget.optionsMap[id][option].products).length <= 0) {
568559
$this.attr('disabled', true).addClass('disabled');
569560
}
570561
});
@@ -597,7 +588,7 @@ define(["jquery", "jquery/ui"], function ($) {
597588
if (products.length == 0) {
598589
products = $widget.optionsMap[id][option].products;
599590
} else {
600-
products = products.intersection($widget.optionsMap[id][option].products);
591+
products = _.intersection(products, $widget.optionsMap[id][option].products);
601592
}
602593
});
603594

0 commit comments

Comments
 (0)