diff options
Diffstat (limited to 'StoneIsland/www/js/lib')
| -rw-r--r-- | StoneIsland/www/js/lib/cart/CartSummary.js | 45 | ||||
| -rw-r--r-- | StoneIsland/www/js/lib/cart/CartView.js | 2 |
2 files changed, 35 insertions, 12 deletions
diff --git a/StoneIsland/www/js/lib/cart/CartSummary.js b/StoneIsland/www/js/lib/cart/CartSummary.js index e70f152a..209e3102 100644 --- a/StoneIsland/www/js/lib/cart/CartSummary.js +++ b/StoneIsland/www/js/lib/cart/CartSummary.js @@ -48,8 +48,12 @@ var CartSummary = ScrollableView.extend({ this.data = data console.log("CART", data) + + if (! data.Cart.Items || data.Cart.Items.length == 0) { + return this.empty() + } - this.update_counts() + this.updateCounts() this.$rows.empty() @@ -104,29 +108,34 @@ var CartSummary = ScrollableView.extend({ .replace(/{{color}}/, color_name) .replace(/{{quantity}}/, 1) .replace(/{{price}}/, as_cash(details.Item.Price.DiscountedPrice)) + $el.data("price", details.Item.Price.DiscountedPrice) $el.html(t) this.deferScrollToTop() }.bind(this)) }.bind(this)) - var subtotal = data.Cart.Totals.TotalWithoutPromotions - var shipping_cost = data.Cart.DeliveryMethod.Selected.Amount.Total - var tax = 0 - var total = data.Cart.Totals.TotalToPay - - this.$subtotal.html( as_cash(subtotal) ) - this.$shipping.html( as_cash(shipping_cost) ) - this.$tax.html( as_cash(tax) ) - this.$total.html( as_cash(total) ) + this.updateTotals() this.el.className = "full" this.deferScrollToTop() }, - update_counts: function(){ + updateCounts: function(){ app.header.set_cart_count(this.data.Cart.Items.length) this.parent.$itemcount.html(pluralize(this.data.Cart.Items.length, "ITEM", "S")) }, + + updateTotals: function(){ + var subtotal = this.data.Cart.Totals.TotalWithoutPromotions + var shipping_cost = this.data.Cart.DeliveryMethod.Selected.Amount.Total + var tax = 0 + var total = this.data.Cart.Totals.TotalToPay + + this.$subtotal.html( as_cash(subtotal) ) + this.$shipping.html( as_cash(shipping_cost) ) + this.$tax.html( as_cash(tax) ) + this.$total.html( as_cash(total) ) + }, empty: function(){ app.footer.hide() @@ -146,7 +155,21 @@ var CartSummary = ScrollableView.extend({ remove_item: function(e){ var $el = $( e.currentTarget ).closest(".cart_item_row") var data = $el.data() + data.Cart.Totals.TotalWithoutPromotions -= data.price + data.Cart.Totals.TotalToPay -= data.price + + this.data.Cart.Items = this.data.Cart.Items.filter(function(item){ + return ( item['Code10'] !== data.code || item['Size'] !== data.size) + }) + + this.updateTotals() + this.updateCounts() $el.remove() + + if (this.data.Cart.Items.length == 0) { + this.empty() + } + sdk.cart.delete_item({ data: { Code10: data.code, diff --git a/StoneIsland/www/js/lib/cart/CartView.js b/StoneIsland/www/js/lib/cart/CartView.js index 7d0476e9..8bea43dc 100644 --- a/StoneIsland/www/js/lib/cart/CartView.js +++ b/StoneIsland/www/js/lib/cart/CartView.js @@ -22,7 +22,7 @@ var CartView = View.extend({ sdk.cart.get_status({ success: function(data){ this.summary.data = data - this.summary.update_counts() + this.summary.updateCounts() }.bind(this), error: function(data){ console.log(data) |
