diff options
| -rw-r--r-- | StoneIsland/www/css/index.css | 2 | ||||
| -rw-r--r-- | StoneIsland/www/js/lib/products/ProductView.js | 70 | ||||
| -rw-r--r-- | StoneIsland/www/js/sdk/auth.js | 2 | ||||
| -rw-r--r-- | StoneIsland/www/js/sdk/shipping.js | 7 | ||||
| -rw-r--r-- | test/test/04-cart.js | 22 |
5 files changed, 87 insertions, 16 deletions
diff --git a/StoneIsland/www/css/index.css b/StoneIsland/www/css/index.css index 79364e54..0988d8a4 100644 --- a/StoneIsland/www/css/index.css +++ b/StoneIsland/www/css/index.css @@ -22,7 +22,7 @@ body { width: 80px; height: 80px; position: absolute; - top: 50vw; + top: 50vh; left: 50%; margin-top: -60px; margin-left: -40px; 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", diff --git a/StoneIsland/www/js/sdk/auth.js b/StoneIsland/www/js/sdk/auth.js index 3b905ffb..134107c2 100644 --- a/StoneIsland/www/js/sdk/auth.js +++ b/StoneIsland/www/js/sdk/auth.js @@ -37,4 +37,4 @@ var auth = sdk.auth = (function(){ } return auth -})() +})()
\ No newline at end of file diff --git a/StoneIsland/www/js/sdk/shipping.js b/StoneIsland/www/js/sdk/shipping.js index 71e0267f..1a148b23 100644 --- a/StoneIsland/www/js/sdk/shipping.js +++ b/StoneIsland/www/js/sdk/shipping.js @@ -53,7 +53,10 @@ sdk.shipping = (function() { "x-yoox-cart-token": sdk.cart.token, }, success: function(data){ + console.log("delivery types") console.log(data) + // *returning an error here* + // [types] not valid.. investigate opt.success(data['DeliveryTypes']['Types']) }, error: opt.error, @@ -72,7 +75,7 @@ sdk.shipping = (function() { "Id": opt.id, }, success: function(data){ - console.log(data) + //console.log(data) opt.success(data) }, error: opt.error, @@ -80,4 +83,4 @@ sdk.shipping = (function() { } return shipping -})()
\ No newline at end of file +})() diff --git a/test/test/04-cart.js b/test/test/04-cart.js index 3526d19b..5f6c04d7 100644 --- a/test/test/04-cart.js +++ b/test/test/04-cart.js @@ -120,8 +120,26 @@ describe('shipping', function(){ }) }) describe('#set_box_type()', function(){ + it('set box types', function(done){ + // box might be hard coded to 'standard' ? + var box_type = { + "Type": "Standard" + } + promise(sdk.shipping.set_box_type, { data: box_type }).then(function(data){ + assert(data.Header.StatusCode == 200) + done() + }) + }) }) describe('#get_delivery_types()', function(){ + it('request delivery types', function(done){ + promise(sdk.shipping.get_delivery_types, { data: {} }).then(function(data){ + assert(data.Header.StatusCode == 200) + console.log(data) + done() + }) + }) + }) describe('#set_delivery_type()', function(){ }) @@ -207,7 +225,7 @@ describe('payment', function(){ "Type":"Visa", "Number":"0000567890124285", "ExpirationMonth":"02", - "ExpirationYear":"2015", + "ExpirationYear":"2017", "HolderIsoCountry":"IT", } promise(sdk.payment.add_credit_card, { data: new_card }).then(function(data){ @@ -254,4 +272,4 @@ describe('payment', function(){ describe('checkout', function(){ describe('#finalize()', function(){ }) -})
\ No newline at end of file +}) |
