diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-11-11 19:17:52 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-11-11 19:17:52 -0500 |
| commit | 9dbef9843e2a63c04ed26f7c11d184d8925f2eb5 (patch) | |
| tree | 6aa98dde61530f5b2401ad16b0f881fa9dc9e132 /StoneIsland/www/js/lib/products/ProductView.js | |
| parent | e49d68aa34532bbdf9d8d942f9d7e2532454e55d (diff) | |
| parent | 26c059e0e459aa2088355c82fccfb637991ec229 (diff) | |
determine whats in inventory from ModelColorSize arrays
Diffstat (limited to 'StoneIsland/www/js/lib/products/ProductView.js')
| -rw-r--r-- | StoneIsland/www/js/lib/products/ProductView.js | 70 |
1 files changed, 60 insertions, 10 deletions
diff --git a/StoneIsland/www/js/lib/products/ProductView.js b/StoneIsland/www/js/lib/products/ProductView.js index 8e14c193..9b7912aa 100644 --- a/StoneIsland/www/js/lib/products/ProductView.js +++ b/StoneIsland/www/js/lib/products/ProductView.js @@ -31,9 +31,13 @@ var ProductView = ScrollableView.extend({ }, item: null, + details: null, size: null, color: null, code: null, + + sizes: null, + colors: null, cache: {}, @@ -74,27 +78,34 @@ var ProductView = ScrollableView.extend({ descriptions[pair.Key] = pair.Value }) this.gallery.populate( data['Code8'], details['Item']['ImageTypes'] ) - + var name_partz = data['ModelNames'].split(' ') var num = name_partz.shift() var title = name_partz.join(' ') var type = data['MicroCategory'].toUpperCase() var price = "$" + data['DiscountedPrice'] + ".00" + var body = descriptions['EditorialDescription'].replace(/<br>/g, "<br><br>") + + var default_color_id = this.populate_selectors(data, details) + + var color = this.colors[default_color_id] + var color_label = color.label var size = data['Sizes'][0] var size_label = SIZE_LOOKUP[size] - var color = data['Colors'].length && data['Colors'][0] - var color_label = color && color['Text'] - var body = descriptions['EditorialDescription'].replace(/<br>/g, "<br><br>") - + this.item = data + this.details = details['Item'] + this.code = data['DefaultCode10'] + this.color = color this.size = size - this.code = data['DefaultCode10'] this.$num.html(num) this.$title.html(title) this.$type.html(type) this.$price.html(price) + this.$body.html(body) + this.$size.html(size_label) if (color_label) { this.$color.show().html(color_label) @@ -102,7 +113,46 @@ var ProductView = ScrollableView.extend({ else { this.$color.hide() } - this.$body.html(body) + }, + + find_sizes_for_color: function(color_id){ + return Object.keys( this.colors[color_id].sizes ).sort(function(a,b){ + var ao = SIZE_ORDER[ a.label ], bo = SIZE_ORDER[ b.label ] + return ao<bo?-1:ao==bo?0:1 + }) + }, + find_colors_for_size: function(size_id){ + return Object.keys( this.sizes[size_id].colors ) + }, + + populate_selectors: function(data, details){ + var sizes = {}, colors = {}, size_lookup = {}, default_color + details['Item']['ModelColors'].forEach(function(color, index){ + if (! default_color || color['Code10'] == data['DefaultCode10']) { + default_color = color['ColorId'] + } + colors[ color['ColorId'] ] = { + code: color['Code10'], + label: color['ColorDescription'], + sizes: {}, + } + }) + details['Item']['ModelSizes'].forEach(function(size){ + var label = SIZE_LOOKUP[ size['Default']['Text'] ] + size_lookup[ label ] = size['SizeId'] + sizes[ size['SizeId'] ] = { + label: label, + colors: {}, + } + }) + details['Item']['ModelColorSize'].forEach(function(cs){ + colors[ cs['IdColor'] ].sizes[ cs['IdSize'] ] = true + sizes[ cs['IdSize'] ].colors[ cs['IdColor'] ] = true + }) + + this.sizes = sizes + this.colors = colors + return default_color }, select_size: function(){ @@ -155,12 +205,12 @@ var SIZE_LOOKUP = { "L": "LARGE", "XL": "X-LARGE", "XXL": "XX-LARGE", - "XXXL": "XXX-LARGE", -}; + "3XL": "3X-LARGE", +} +var SIZE_ORDER = "XS S M L XL XXL 3XL".split(" ") /* - { "Code8": "41504876", "BrandName": "STONE ISLAND", |
