summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/www/js/lib/cart
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/platforms/ios/www/js/lib/cart')
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/cart/CartBilling.js11
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/cart/CartConfirm.js29
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js40
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/cart/CartShipping.js28
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/cart/CartSummary.js179
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/cart/CartThanks.js23
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/cart/CartView.js38
7 files changed, 328 insertions, 20 deletions
diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartBilling.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartBilling.js
deleted file mode 100644
index f3c9cbe2..00000000
--- a/StoneIsland/platforms/ios/www/js/lib/cart/CartBilling.js
+++ /dev/null
@@ -1,11 +0,0 @@
-var CartBilling = View.extend({
-
- el: "#billing",
-
- events: {
- },
-
- initialize: function(){
- },
-
-}) \ No newline at end of file
diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartConfirm.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartConfirm.js
new file mode 100644
index 00000000..687f3a93
--- /dev/null
+++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartConfirm.js
@@ -0,0 +1,29 @@
+var CartConfirm = FormView.extend({
+
+ el: "#cart_confirm",
+
+ events: {
+ },
+
+ initialize: function(opt){
+ this.parent = opt.parent
+ this.scroller = new IScroll('#cart_confirm', app.iscroll_options)
+ },
+
+ show: function(){
+ document.body.className = "cart"
+ app.cart.el.className = "confirm"
+ app.footer.show("PLACE ORDER", "CANCEL")
+ this.deferScrollToTop()
+ },
+
+ populate: function(){
+ },
+
+ save: function(){
+ },
+
+ cancel: function(){
+ },
+
+}) \ No newline at end of file
diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js
new file mode 100644
index 00000000..19d21ffd
--- /dev/null
+++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js
@@ -0,0 +1,40 @@
+var CartPayment = FormView.extend({
+
+ el: "#cart_payment",
+
+ events: {
+ },
+
+ initialize: function(opt){
+ this.parent = opt.parent
+ this.$form = this.$("form")
+ this.$msg = this.$(".msg")
+ this.address = new AddressView ({ parent: this })
+ this.cc = new CreditCardView ({ parent: this })
+ this.scroller = new IScroll('#cart_payment', app.iscroll_options)
+ },
+
+ // sdk.cart.set_credit_card
+ // sdk.payment.list_credit_cards
+ // sdk.payment.add_credit_card
+ // sdk.payment.delete_credit_card
+ // sdk.payment.get_payment_types
+ // sdk.cart.use_stored_credit_card
+
+ show: function(){
+ document.body.className = "cart"
+ app.cart.el.className = "payment"
+ app.footer.show("CONFIRM >", "CANCEL")
+
+ this.deferScrollToTop()
+
+ sdk.cart.set_payment_type({ data: payment_id })
+ },
+
+ save: function(){
+ },
+
+ cancel: function(){
+ },
+
+}) \ No newline at end of file
diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartShipping.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartShipping.js
index beaf6bd2..7d7c8540 100644
--- a/StoneIsland/platforms/ios/www/js/lib/cart/CartShipping.js
+++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartShipping.js
@@ -1,11 +1,33 @@
-var CartShipping = View.extend({
+var CartShipping = FormView.extend({
- el: "#shipping",
+ el: "#cart_shipping",
events: {
},
+
+ initialize: function(opt){
+ this.parent = opt.parent
+ this.$form = this.$("form")
+ this.$msg = this.$(".msg")
+ this.address = new AddressView ({ parent: this })
+ this.scroller = new IScroll('#cart_shipping', app.iscroll_options)
+ },
+
+ show: function(){
+ document.body.className = "cart"
+ app.cart.el.className = "shipping"
+ app.footer.show("PAYMENT >", "CANCEL")
+ this.deferScrollToTop()
+ },
+
+ // sdk.cart.set_shipping_address
+ // sdk.shipping.get_delivery_types
+ // sdk.shipping.set_delivery_type
+
+ save: function(){
+ },
- initialize: function(){
+ cancel: function(){
},
}) \ No newline at end of file
diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartSummary.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartSummary.js
index 37400dd0..209e3102 100644
--- a/StoneIsland/platforms/ios/www/js/lib/cart/CartSummary.js
+++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartSummary.js
@@ -1,11 +1,184 @@
-var CartSummary = View.extend({
+var CartSummary = ScrollableView.extend({
- el: "#summary",
+ el: "#cart_summary",
+
+ template: $("#cart_summary .template").html(),
events: {
+ "click .remove": "remove_item",
+ },
+
+ data: null,
+
+ initialize: function(opt){
+ this.parent = opt.parent
+ this.$loader = this.$(".loader")
+ this.$cart_body = this.$(".cart_body")
+ this.$cart_empty = this.$(".cart_empty")
+ this.scroller = new IScroll('#cart_summary', app.iscroll_options)
+
+ this.$rows = this.$(".rows")
+ this.$subtotal = this.$(".subtotal")
+ this.$shipping = this.$(".shipping")
+ this.$tax = this.$(".tax")
+ this.$total = this.$(".total")
+ },
+
+ show: function(){
+ document.body.className = "cart"
+ app.cart.el.className = "summary"
+ if (auth.has_cart()) {
+ this.load()
+ }
+ else {
+ this.empty()
+ }
+ },
+
+ load: function(){
+ this.el.className = "loading"
+ app.footer.show("SHIPPING >", "CANCEL")
+ sdk.cart.get_status({
+ success: this.populate.bind(this),
+ error: this.empty.bind(this),
+ })
+ },
+
+ populate: function(data){
+ this.data = data
+
+ console.log("CART", data)
+
+ if (! data.Cart.Items || data.Cart.Items.length == 0) {
+ return this.empty()
+ }
+
+ this.updateCounts()
+
+ this.$rows.empty()
+
+ data.Cart.Items.forEach(function(item){
+ var code_ten = item['Code10']
+ var code = code_ten.substr(0, 8)
+ var size_id = item['Size']
+
+ var $el = $("<div>").addClass("cart_item_row")
+ $el.data({
+ code: code_ten,
+ size: size_id,
+ })
+ this.$rows.append($el)
+ app.product.find(code, function(data, details){
+ // console.log(data, details)
+
+ var descriptions = app.product.get_descriptions( details )
+ // console.log(descriptions)
+
+ var name_partz = descriptions['ModelNames'].split(' ')
+ var num = name_partz.shift()
+ var title = name_partz.join(' ')
+ var type = title_case( descriptions['MicroCategory'] )
+
+ var color_name, size_name
+ // console.log(code)
+ details.Item.ModelColors.some(function(color){
+ if (color['Code10'] == code_ten) {
+ color_name = color['ColorDescription']
+ // console.log(color)
+ return true
+ }
+ return false
+ })
+ details.Item.ModelSizes.some(function(size){
+ if (size['SizeId'] == size_id) {
+ // console.log(size)
+ size_name = size['Default']['Text']
+ size_name = SIZE_LOOKUP[ size_name ] || size_name
+ return true
+ }
+ return false
+ })
+
+ var t = this.template
+ .replace(/{{image}}/, sdk.image(item['Code10'], '11_f'))
+ .replace(/{{sku}}/, num)
+ .replace(/{{title}}/, title)
+ .replace(/{{type}}/, type)
+ .replace(/{{size}}/, size_name)
+ .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))
+
+ this.updateTotals()
+
+ this.el.className = "full"
+ this.deferScrollToTop()
+ },
+
+ 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()
+ app.header.set_cart_count(0)
+ this.parent.$itemcount.html("0 ITEMS")
+ this.el.className = "empty"
+ },
+
+ save: function(){
+ app.router.go('cart/shipping')
+ },
+
+ cancel: function(){
+ app.router.go('intro')
},
- initialize: function(){
+ 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,
+ Size: data.size,
+ },
+ success: function(){
+ console.log("damn")
+ },
+ })
},
}) \ No newline at end of file
diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartThanks.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartThanks.js
new file mode 100644
index 00000000..993fd9ac
--- /dev/null
+++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartThanks.js
@@ -0,0 +1,23 @@
+var CartThanks = View.extend({
+
+ el: "#cart_thanks",
+
+ events: {
+ },
+
+ initialize: function(opt){
+ this.parent = opt.parent
+ },
+
+ show: function(){
+ document.body.className = "cart"
+ app.cart.el.className = "thanks"
+ app.footer.show("&lt; BACK TO COLLECTION")
+ app.footer.hide()
+ },
+
+ ok: function(){
+ app.router.go("store")
+ },
+
+}) \ No newline at end of file
diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartView.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartView.js
index 5d741492..8bea43dc 100644
--- a/StoneIsland/platforms/ios/www/js/lib/cart/CartView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartView.js
@@ -3,16 +3,48 @@ var CartView = View.extend({
el: "#cart",
events: {
+ "click .summary_step": "show_summary",
+ "click .shipping_step": "show_shipping",
+ "click .payment_step": "show_payment",
},
initialize: function(){
- this.summary = new CartSummary ()
- this.billing = new CartBilling ()
- this.shipping = new CartShipping ()
+ this.summary = new CartSummary ({ parent: this })
+ this.payment = new CartPayment ({ parent: this })
+ this.shipping = new CartShipping ({ parent: this })
+ this.confirm = new CartConfirm ({ parent: this })
+ this.thanks = new CartThanks ({ parent: this })
+
+ this.$itemcount = this.$(".itemcount")
+ },
+
+ load: function(){
+ sdk.cart.get_status({
+ success: function(data){
+ this.summary.data = data
+ this.summary.updateCounts()
+ }.bind(this),
+ error: function(data){
+ console.log(data)
+ },
+ })
},
show: function(){
document.body.className = "cart"
+ this.show_summary()
+ },
+
+ show_summary: function(){
+ this.summary.show()
+ },
+
+ show_shipping: function(){
+ this.shipping.show()
+ },
+
+ show_payment: function(){
+ this.payment.show()
},
}) \ No newline at end of file