diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-09-25 15:07:12 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-09-25 15:07:12 -0400 |
| commit | 028174b202c8ff8ed62b7e008f42a1f39797ce9d (patch) | |
| tree | d514281ef2799551b0d399cd6a162fe499e83cff /StoneIsland/www/js | |
| parent | 3a4ccaade954bc8d9bc54bafa8a492ca75124979 (diff) | |
cart
Diffstat (limited to 'StoneIsland/www/js')
| -rw-r--r-- | StoneIsland/www/js/sdk/account.js | 2 | ||||
| -rw-r--r-- | StoneIsland/www/js/sdk/auth.js | 7 | ||||
| -rw-r--r-- | StoneIsland/www/js/sdk/cart.js | 104 |
3 files changed, 110 insertions, 3 deletions
diff --git a/StoneIsland/www/js/sdk/account.js b/StoneIsland/www/js/sdk/account.js index bc37020f..7af505b8 100644 --- a/StoneIsland/www/js/sdk/account.js +++ b/StoneIsland/www/js/sdk/account.js @@ -20,8 +20,6 @@ sdk.account = (function(){ auth.set_user(user_id, access_token, name) - sdk.headers['x-yoox-account-token'] = access_token - opt.success(data) }, error: opt.error, diff --git a/StoneIsland/www/js/sdk/auth.js b/StoneIsland/www/js/sdk/auth.js index a8489b5d..911da902 100644 --- a/StoneIsland/www/js/sdk/auth.js +++ b/StoneIsland/www/js/sdk/auth.js @@ -16,11 +16,16 @@ var auth = (function(){ auth.access_token = "" auth.user_id = -1 + auth.name = name - // integrate keychain/cordova.file.externalRootDirectory api + // ios: integrate keychain api + // android: cordova.file.externalRootDirectory api auth.set_user = function(user_id, access_token, name){ // persist user data + auth.user_id = user_id + auth.access_token = access_token + auth.name = name } auth.get_user = function(cb){ // fetch user data diff --git a/StoneIsland/www/js/sdk/cart.js b/StoneIsland/www/js/sdk/cart.js new file mode 100644 index 00000000..9c36a222 --- /dev/null +++ b/StoneIsland/www/js/sdk/cart.js @@ -0,0 +1,104 @@ +sdk.cart = (function(){ + var cart = {} + + var cart_id, cart_token + + // https://gist.github.com/fanfare/9a50c524aea417d0bf3e + cart.initialize = function(opt){ + $.ajax({ + method: "POST", + url: sdk.path("Cart.API/1.6", "carts.json"), + headers: { + "x-yoox-appname": auth.appname, + "x-yoox-device": auth.device, + }, + data: opt.data, + success: function(data){ + console.log(data) + cart_id = data["CartSession"]["CartId"] + cart_token = data["CartSession"]["CartToken"] + opt.success(data) + }, + error: opt.error, + }) + } + + cart.set_user = function(opt){ + $.ajax({ + method: "PUT", + url: sdk.path("Cart.API/1.6", "carts.json"), + headers: { + "x-yoox-appname": auth.appname, + "x-yoox-cart-token": cart_token, + }, + data: { + "UserId": auth.user_id, + "UserToken": auth.access_token, + }, + success: function(data){ + console.log(data) + opt.success(data) + }, + error: opt.error, + }) + } + + // Code10, Size, Section + cart.add_item = function(opt){ + $.ajax({ + method: "POST", + url: sdk.path("Cart.API/1.6", "carts/" + cart_id + "/items.json"), + headers: { + "x-yoox-appname": auth.appname, + "x-yoox-cart-token": cart_token, + }, + data: opt.data, + success: function(data){ + console.log(data) + opt.success(data) + }, + error: opt.error, + }) + } + + cart.delete_item = function(opt){ + $.ajax({ + method: "DELETE", + url: sdk.path("Cart.API/1.6", "carts/" + cart_id + + "/items/" + opt.code10 + + "/" + opt.size + ".json"), + headers: { + "x-yoox-appname": auth.appname, + "x-yoox-cart-token": cart_token, + }, + success: function(data){ + console.log(data) + opt.success(data) + }, + error: opt.error, + }) + } + + cart.get_status = function(opt){ + $.ajax({ + method: "GET", + url: sdk.path("Cart.API/1.6", "carts/" + cart_id), + headers: { + "x-yoox-appname": auth.appname, + "x-yoox-cart-token": cart_token, + "x-yoox-device": auth.device, + }, + data: { + "UserId": auth.user_id, + "UserToken": auth.access_token, + }, + success: function(data){ + console.log(data) + opt.success(data) + }, + error: opt.error, + }) + } + + return cart +})()
\ No newline at end of file |
