diff --git a/.gitignore b/.gitignore index e7a653d..1d2ccd3 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ sdk/test/unit/index.html node_modules src/**/*.templates.js src/**/*.tpl.js +angular-sofa-variant-selector.iml diff --git a/src/sofa-variant-selector.tpl.html b/src/sofa-variant-selector.tpl.html index 4e5d44e..a256e94 100644 --- a/src/sofa-variant-selector.tpl.html +++ b/src/sofa-variant-selector.tpl.html @@ -1,11 +1,52 @@ diff --git a/src/sofaVariantSelector.js b/src/sofaVariantSelector.js index 51d24d7..569d1d8 100644 --- a/src/sofaVariantSelector.js +++ b/src/sofaVariantSelector.js @@ -31,14 +31,25 @@ angular.module('sofa.variantSelector') } }; + var contains = function (data,key) { + for (var i=0;i 0) { - result.push(variant.properties[key].value); + if (!contains(result,variant.properties[key].value) && variant.stock > 0) { + result.push({value:variant.properties[key].value, + selected:false, + available: true}); } }); @@ -68,13 +79,45 @@ angular.module('sofa.variantSelector') scope.selectedProperties = scope.selectedProperties || {}; scope.data = {}; + scope.images = {}; + + scope.selectProperty = function(property, variant) { + console.log('Selected '+property+':'+variant); + if (!variant.available) { + scope.selectedProperties = {}; + } + scope.selectedProperties[property]=variant.value; + }; + var getDataByProperty = function (property) { - return $filter('sofaVariantFilter')(scope.variants, scope.selectedProperties, property); + console.debug('Filtering for '+JSON.stringify(property)); + var rawResult = $filter('sofaVariantFilter')(scope.variants, {}, property); + var filteredResult = $filter('sofaVariantFilter')(scope.variants, scope.selectedProperties, property); + + // Apply selection + var selection = scope.selectedProperties[property]; + for (var i=0;i