diff options
Diffstat (limited to 'StoneIsland/platforms/ios/www/js/sdk/auth.js')
| -rwxr-xr-x | StoneIsland/platforms/ios/www/js/sdk/auth.js | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/StoneIsland/platforms/ios/www/js/sdk/auth.js b/StoneIsland/platforms/ios/www/js/sdk/auth.js index 87ce60ea..fa8dd71c 100755 --- a/StoneIsland/platforms/ios/www/js/sdk/auth.js +++ b/StoneIsland/platforms/ios/www/js/sdk/auth.js @@ -30,7 +30,12 @@ var auth = sdk.auth = (function(){ sdk.account.checkin({ success: function(data){ fn && fn( auth.logged_in() ) - } + }, + error: function(){ + auth.log_out() + fn && fn( false ) + // + }, }) auth.get_cart() } @@ -78,40 +83,54 @@ var auth = sdk.auth = (function(){ localStorage.removeItem("yoox.cart_id") cb && cb() } - auth.create_cart = function(cb){ - if (auth.has_cart()) { return cb() } + auth.create_cart = function(opt){ + opt = opt || {} + if (auth.has_cart()) { + opt.success && opt.success() + return + } sdk.cart.initialize({ success: function(data){ sdk.cart.set_user({ success: function(){ auth.set_cart(sdk.cart.id, sdk.cart.token, function(){ - cb && cb() + opt.success && opt.success() }) - } + }, + error: function(){ + opt.clear_cart() + opt.error && opt.error() + }, }) + }, + error: function(){ + opt.clear_cart() + opt.error && opt.error() } }) } - auth.add_deferred_product_to_cart = function(cb){ + + auth.add_deferred_product_to_cart = function(opt){ + opt = opt || {} // auth.deferred_product if (! auth.deferred_product) { - console.log("VV NO DEF PROD") - cb && cb() + console.log("VV NO DEFERRED PROD") + opt.success && opt.success() return } sdk.cart.add_item({ data: auth.deferred_product, success: function(){ console.log("ADDED ITEM") - cb && cb() + app.header.increment_cart_count() + opt.success && opt.success() }, error: function(data){ - console.log("ERROR ADDING ITEM", data) - cb && cb() + console.log("ERROR ADDING ITEM") + opt.error && opt.error() }, }) auth.deferred_product = null - app.header.increment_cart_count() } auth.log_out = function(){ |
