forked from ivanramosnet/prestashop-color-and-size
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HideUnavailableSizes.js
31 lines (27 loc) · 1.3 KB
/
HideUnavailableSizes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var colorAttributteID='3'; // Set your color attribute ID
var sizeAttributteID='2'; // Set your size attribute ID
$(document).ready(function(){
var sizeList={};
$('select[name="group_'+sizeAttributteID+'"] option').each(function(){
if (sizeList[this.text]==undefined){
sizeList[this.text]=$(this).val(); // get size list option values
}
});
var currentColor=combination.attributes_values[colorAttributteID]; // get current color
renewSizeList(sizeList, currentColor);
$('[name=group_'+ colorAttributteID +']').parent().children('ul').children('li').children('a').click(function(){
var currentColor=$(this ).attr('name');
renewSizeList(sizeList, currentColor);
});
});
function renewSizeList(sizeList, currentColor){
$('select[name="group_'+sizeAttributteID+'"]').empty(); //clear list
var theSize;
for(var key in combinationsFromController) {
if (combinationsFromController[key].attributes_values[colorAttributteID]==currentColor){ //if this combination with current color
theSize=combinationsFromController[key].attributes_values[sizeAttributteID];
$('select[name="group_'+sizeAttributteID+'"]').append('<option value="'+sizeList[theSize]+ '">' +theSize+'</option>');
}
}
$('select[name="group_'+sizeAttributteID+'"] :first').attr("selected", "selected");
};