summaryrefslogtreecommitdiff
path: root/StoneIsland/www/js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-11-23 04:54:04 -0500
committerJules Laplace <jules@okfoc.us>2015-11-23 04:54:04 -0500
commit69890f479cc9dc22bdf0a6a765135dfe9a98416c (patch)
tree438546edb34304f19d7e92017112ee5cbdcb3bca /StoneIsland/www/js
parent8e627ed25ae70556b839f00990ba700ccdb3a719 (diff)
prefetch cart
Diffstat (limited to 'StoneIsland/www/js')
-rw-r--r--StoneIsland/www/js/lib/account/AccountView.js12
-rw-r--r--StoneIsland/www/js/lib/cart/CartSummary.js15
-rw-r--r--StoneIsland/www/js/lib/cart/CartView.js9
-rw-r--r--StoneIsland/www/js/lib/products/ProductView.js1
-rw-r--r--StoneIsland/www/js/sdk/auth.js7
5 files changed, 35 insertions, 9 deletions
diff --git a/StoneIsland/www/js/lib/account/AccountView.js b/StoneIsland/www/js/lib/account/AccountView.js
index c6f68e88..e9022d64 100644
--- a/StoneIsland/www/js/lib/account/AccountView.js
+++ b/StoneIsland/www/js/lib/account/AccountView.js
@@ -47,8 +47,16 @@ var AccountView = View.extend({
else {
cb && cb()
}
- if (auth.deferred_product) {
- auth.add_deferred_product_to_cart()
+ if ( ! auth.has_cart() ) {
+ auth.create_cart(auth.add_deferred_product_to_cart)
+ }
+ else {
+ if (auth.deferred_product) {
+ auth.add_deferred_product_to_cart( app.cart.load.bind(app.cart) )
+ }
+ else {
+ app.cart.load()
+ }
}
},
diff --git a/StoneIsland/www/js/lib/cart/CartSummary.js b/StoneIsland/www/js/lib/cart/CartSummary.js
index 8201cc9a..ce7ae650 100644
--- a/StoneIsland/www/js/lib/cart/CartSummary.js
+++ b/StoneIsland/www/js/lib/cart/CartSummary.js
@@ -42,17 +42,15 @@ var CartSummary = ScrollableView.extend({
error: this.empty.bind(this),
})
},
-
+
populate: function(data){
this.data = data
-
+console.log(data)
this.$loader.hide()
app.footer.show("SHIPPING &gt;", "CANCEL")
- app.header.set_cart_count(data.Cart.Items.length)
-
- this.parent.$itemcount.html(pluralize(data.Cart.Items.length, "ITEM", "S"))
-
+ this.update_counts()
+
this.$rows.empty()
data.Cart.Items.forEach(function(item){
@@ -125,6 +123,11 @@ var CartSummary = ScrollableView.extend({
this.deferScrollToTop()
},
+ update_counts: function(){
+ app.header.set_cart_count(this.data.Cart.Items.length)
+ this.parent.$itemcount.html(pluralize(this.data.Cart.Items.length, "ITEM", "S"))
+ },
+
empty: function(){
this.$loader.hide()
app.footer.hide()
diff --git a/StoneIsland/www/js/lib/cart/CartView.js b/StoneIsland/www/js/lib/cart/CartView.js
index 465ffe50..7d0476e9 100644
--- a/StoneIsland/www/js/lib/cart/CartView.js
+++ b/StoneIsland/www/js/lib/cart/CartView.js
@@ -19,6 +19,15 @@ var CartView = View.extend({
},
load: function(){
+ sdk.cart.get_status({
+ success: function(data){
+ this.summary.data = data
+ this.summary.update_counts()
+ }.bind(this),
+ error: function(data){
+ console.log(data)
+ },
+ })
},
show: function(){
diff --git a/StoneIsland/www/js/lib/products/ProductView.js b/StoneIsland/www/js/lib/products/ProductView.js
index 0a00f365..cf6c1a90 100644
--- a/StoneIsland/www/js/lib/products/ProductView.js
+++ b/StoneIsland/www/js/lib/products/ProductView.js
@@ -214,6 +214,7 @@ var ProductView = ScrollableView.extend({
auth.create_cart(auth.add_deferred_product_to_cart)
}
else {
+ app.go("cart")
auth.add_deferred_product_to_cart()
}
},
diff --git a/StoneIsland/www/js/sdk/auth.js b/StoneIsland/www/js/sdk/auth.js
index 65505d81..1fbf48ec 100644
--- a/StoneIsland/www/js/sdk/auth.js
+++ b/StoneIsland/www/js/sdk/auth.js
@@ -86,12 +86,17 @@ var auth = sdk.auth = (function(){
}
})
}
- auth.add_deferred_product_to_cart = function(){
+ auth.add_deferred_product_to_cart = function(cb){
// auth.deferred_product
+ if (! auth.deferred_product) {
+ cb && cb()
+ return
+ }
sdk.cart.add_item({
data: auth.deferred_product,
success: function(){
console.log("ADDED")
+ cb && cb()
}
})
auth.deferred_product = null