summaryrefslogtreecommitdiff
path: root/StoneIsland/www/js/lib/cart
diff options
context:
space:
mode:
authorRene Ae <aehtyb@gmail.com>2015-12-01 00:51:02 -0600
committerRene Ae <aehtyb@gmail.com>2015-12-01 00:51:02 -0600
commit6415f506034262dd7151be2e35e1e1c1e97f4dfa (patch)
treec6e564e374967725a40fd87f7c5f3a1ba8019089 /StoneIsland/www/js/lib/cart
parent5e07e273e18a609978253c45f3c5f702b0de4991 (diff)
parent9497b50fa02f3cfa9cb263ce3a96fa725282d60d (diff)
Merge branch 'master' of https://github.com/okfocus/stone-island
Diffstat (limited to 'StoneIsland/www/js/lib/cart')
-rw-r--r--StoneIsland/www/js/lib/cart/CartConfirm.js107
-rw-r--r--StoneIsland/www/js/lib/cart/CartPayment.js61
-rw-r--r--StoneIsland/www/js/lib/cart/CartShipping.js23
-rw-r--r--StoneIsland/www/js/lib/cart/CartSummary.js6
4 files changed, 177 insertions, 20 deletions
diff --git a/StoneIsland/www/js/lib/cart/CartConfirm.js b/StoneIsland/www/js/lib/cart/CartConfirm.js
index aa6ec9e4..171f41a1 100644
--- a/StoneIsland/www/js/lib/cart/CartConfirm.js
+++ b/StoneIsland/www/js/lib/cart/CartConfirm.js
@@ -2,11 +2,26 @@ var CartConfirm = FormView.extend({
el: "#cart_confirm",
+ template: $("#cart_confirm .template").html(),
+
events: {
},
initialize: function(opt){
this.parent = opt.parent
+ this.$rows = this.$(".rows")
+ this.$subtotal = this.$(".subtotal")
+ this.$shipping = this.$(".shipping")
+ this.$tax = this.$(".tax")
+ this.$total = this.$(".total")
+
+ this.$shipping_address = this.$(".shipping_address")
+ this.$shipping_method = this.$(".shipping_method")
+
+ this.$payment_name = this.$(".payment_name")
+ this.$payment_method = this.$(".payment_method")
+ this.$payment_address = this.$(".payment_address")
+
this.scroller = new IScroll('#cart_confirm', app.iscroll_options)
},
@@ -16,9 +31,99 @@ var CartConfirm = FormView.extend({
app.footer.show("PLACE ORDER", "CANCEL")
window.location.hash = "#/cart/confirm"
this.deferScrollToTop()
+
+ app.curtain.show("loading")
+ promise(sdk.cart.get_status).then( this.populate.bind(this) )
},
- populate: function(){
+ populate: function(data){
+ console.log(data)
+
+ data = data.Cart
+
+ this.$rows.empty()
+
+ data.Items.forEach(function(item){
+ var $el = $("<div class='item'><img src='img/spinner.gif'></div>")
+ this.$rows.append($el)
+ var code_ten = item.Code10
+ var size_id = item.Size
+
+ var code = code_ten.substr(0, 8)
+ app.product.find(code, function(data, details){
+ var descriptions = app.product.get_descriptions( details )
+
+ 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
+
+ details.Item.ModelColors.some(function(color){
+ if (color['Code10'] == code_ten) {
+ color_name = color['ColorDescription']
+ 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
+ if (! size_name && ! size['Default']['Labeled']) {
+ size_name = size['Default']['Text'] + " " + size['Default']['ClassFamily']
+ }
+
+ return true
+ }
+ return false
+ })
+
+// size_name = item.DefaultSize + " " + item.DefaultSizeClassFamily
+
+ 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 || "DEFAULT")
+ .replace(/{{color}}/, color_name || "DEFAULT")
+ .replace(/{{quantity}}/, 1)
+ .replace(/{{price}}/, as_cash(details.Item.Price.DiscountedPrice))
+ $el.data("price", details.Item.Price.DiscountedPrice)
+ $el.html(t)
+ this.refreshScroller()
+ }.bind(this))
+ }.bind(this))
+
+ var subtotal = data.Totals.TotalWithoutPromotions
+ var shipping_cost = data.DeliveryMethod.Selected.Amount.Total
+ var tax = data.Totals.TotalSalesTax
+ var total = data.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) )
+
+ var street = data.Receiver.StreetWithNumber.replace(/\n$/,"").replace("\n", ", ")
+ var address = data.Receiver.Name.toUpperCase() + " " + data.Receiver.Surname.toUpperCase() + "<br>" + street + ", "
+ address += data.Receiver.City + ", " + data.Receiver.Region + " " + data.Receiver.PostalCode
+
+ this.$shipping_address.html(address)
+ this.$shipping_method.html(data.DeliveryMethod.Selected.Type == 1 ? "* STANDARD SHIPPING" : "* EXPRESS SHIPPING")
+
+ var cc = data.Payment.CreditCard
+ var cc_street = cc.HolderAddress.replace(/\n$/,"").replace("\n", ", ")
+ var cc_type = cc.Type == "AmericanExpress" ? "American Express" : cc.Type
+
+ this.$payment_name.html( cc.HolderName.toUpperCase() + " " + cc.HolderSurname.toUpperCase() )
+ this.$payment_method.html( cc_type.toUpperCase() + " XXXX-XXXX-XXXX-" + cc.Last4 )
+
+ app.curtain.hide("loading")
},
save: function(){
diff --git a/StoneIsland/www/js/lib/cart/CartPayment.js b/StoneIsland/www/js/lib/cart/CartPayment.js
index fec5e1d1..11d6cddf 100644
--- a/StoneIsland/www/js/lib/cart/CartPayment.js
+++ b/StoneIsland/www/js/lib/cart/CartPayment.js
@@ -9,6 +9,7 @@ var CartPayment = FormView.extend({
address_list_mode: false,
cc_list_mode: false,
+ data: {},
events: {
"change [name=SameAsShipping]": "toggle_shipping",
@@ -28,6 +29,7 @@ var CartPayment = FormView.extend({
this.$cc_list = this.$(".cc_list")
this.$cc_form = this.$(".cc")
this.$cc_dropdown = this.$(".cc_dropdown")
+ this.$cc_confirm = this.$(".cc_confirm")
this.address = new AddressView ({ parent: this, checkPhone: false })
this.cc = new CreditCardView ({ parent: this })
@@ -50,6 +52,7 @@ var CartPayment = FormView.extend({
setTimeout(function(){
var state = this.$same_as_shipping.prop("checked")
this.$billing_address_rapper.toggle( ! state )
+ this.address.disabled = state
}.bind(this))
},
@@ -75,6 +78,7 @@ var CartPayment = FormView.extend({
this.cc.disabled = this.cc_list_mode
this.$cc_form.toggle(! this.cc_list_mode)
this.$cc_list.toggle(this.cc_list_mode)
+ this.$cc_confirm.toggle(this.cc_list_mode)
},
populate: function(){
@@ -107,37 +111,62 @@ var CartPayment = FormView.extend({
},
finalize: function(data){
- var shipping_info = {}, address_data, address_id, cc_info = {}, cc_data, cc_id
+ var shipping_info = {}, address_data, address_id, cc_info = {}, cc_data, cc_id
var shipping_type = $("[name=ShippingType]").filter(function(){ return $(this).prop("checked") }).val()
- if (this.list_mode) {
- address_id = $("[name=AddressId]").filter(function(){ return $(this).prop("checked") }).val()
+ if (this.$same_as_shipping.prop("checked")) {
+ address_data = app.cart.shipping.data
+ }
+ else if (this.address_list_mode) {
+ address_id = this.$("[name=AddressId]").filter(function(){ return $(this).prop("checked") }).val()
address_data = app.account.addressLookup[ address_id ]
}
else {
address_data = data
}
+
if (this.cc_list_mode) {
- cc_id = $("[name=CCId]").filter(function(){ return $(this).prop("checked") }).val()
+ cc_id = this.$("[name=CCId]").filter(function(){ return $(this).prop("checked") }).val()
cc_data = app.account.ccLookup[ cc_id ]
+
+ var card_on_file = {
+ "guid": cc_data.Guid,
+ "cvv": this.$("[name=CvvConfirm]"),
+ }
+
+ app.curtain.show("loading")
+ promise(sdk.cart.use_stored_credit_card, { data: card_on_file }).then(function(data){
+ app.curtain.hide("loading")
+ this.success()
+ }.bind(this)).error(function(data){
+ app.curtain.hide("loading")
+ }.bind(this))
+
+ return
}
else {
cc_data = data
}
- shipping_info.Name = address_data.Name
- shipping_info.Surname = address_data.Surname
- shipping_info.Email = auth.user.Email
- shipping_info.Phone = address_data.Phone
- shipping_info.Mobile = address_data.Phone
- shipping_info.StreetWithNumber = address_data.Address
- shipping_info.PostalCode = address_data.ZipCode
- shipping_info.City = address_data.City
- shipping_info.Province = address_data.Province
- shipping_info.Region = address_data.Province
- shipping_info.CountryCode = "US"
+ var credit_info = {
+ "HolderName": address_data.Name,
+ "HolderSurname": address_data.Surname,
+ "HolderAddress": address_data.Address || address_data.StreetWithNumber,
+ "HolderCity": address_data.City,
+ "HolderProvince": address_data.Province,
+ "HolderZip": address_data.PostalCode || address_data.ZipCode,
+ "HolderISOCountry": CANADIAN_LOOKUP[ address_data.Province ] ? "CA" : "US",
+ "HolderEmail": auth.user.Email,
+ "CardNumber": cc_data['Number'],
+ "Type": cc_data.Type,
+ "ExpirationMonth": cc_data.ExpirationMonth,
+ "ExpirationYear": cc_data.ExpirationYear.substr(2,3),
+ "Cvv": cc_data.Cvv,
+ }
- return shipping_info
+ console.log( credit_info )
+
+ return credit_info
},
success: function(){
diff --git a/StoneIsland/www/js/lib/cart/CartShipping.js b/StoneIsland/www/js/lib/cart/CartShipping.js
index 1a9653e1..ef906804 100644
--- a/StoneIsland/www/js/lib/cart/CartShipping.js
+++ b/StoneIsland/www/js/lib/cart/CartShipping.js
@@ -5,6 +5,7 @@ var CartShipping = FormView.extend({
action: sdk.cart.set_shipping_address,
list_mode: true,
+ data: {},
template: $("#cart_shipping .template").html(),
@@ -53,6 +54,22 @@ var CartShipping = FormView.extend({
}.bind(this))
},
+ load_form: function(cart_data){
+ var data = cart_data.Cart.Receiver
+ var addy = data.StreetWithNumber.split("\n")
+ data.Address1 = addy[0] || ""
+ data.Address2 = addy[1] || ""
+ data.ZipCode = data.PostalCode
+ data.Province = data.Region
+ this.load_data(data)
+
+ this.data = data
+ if (cart_data.Cart.DeliveryMethod && cart_data.Cart.DeliveryMethod.Selected && cart_data.Cart.DeliveryMethod.Type) {
+ $("#standard-shipping").prop("checked", cart_data.Cart.DeliveryMethod.Type == 1)
+ $("#express-shipping").prop("checked", cart_data.Cart.DeliveryMethod.Type == 2)
+ }
+ },
+
toggle_dropdown: function(state){
if (! app.account.addresses.length) {
state = false
@@ -84,7 +101,7 @@ var CartShipping = FormView.extend({
})
if (this.list_mode) {
- address_id = $("[name=AddressId]").filter(function(){ return $(this).prop("checked") }).val()
+ address_id = this.$("[name=AddressId]").filter(function(){ return $(this).prop("checked") }).val()
address_data = app.account.addressLookup[ address_id ]
}
else {
@@ -101,7 +118,9 @@ var CartShipping = FormView.extend({
shipping_info.City = address_data.City
shipping_info.Province = address_data.Province
shipping_info.Region = address_data.Province
- shipping_info.CountryCode = "US"
+ shipping_info.CountryCode = CANADIAN_LOOKUP[ address_data.Province ] ? "CA" : "US"
+
+ this.data = shipping_info
return shipping_info
},
diff --git a/StoneIsland/www/js/lib/cart/CartSummary.js b/StoneIsland/www/js/lib/cart/CartSummary.js
index 72c44405..0ad57020 100644
--- a/StoneIsland/www/js/lib/cart/CartSummary.js
+++ b/StoneIsland/www/js/lib/cart/CartSummary.js
@@ -119,6 +119,10 @@ var CartSummary = ScrollableView.extend({
}.bind(this))
}.bind(this))
+ if (data.Cart.Receiver && data.Cart.Receiver.City) {
+ app.cart.shipping.load_form( data )
+ }
+
this.updateTotals()
this.el.className = "full"
@@ -133,7 +137,7 @@ var CartSummary = ScrollableView.extend({
updateTotals: function(){
var subtotal = this.data.Cart.Totals.TotalWithoutPromotions
var shipping_cost = this.data.Cart.DeliveryMethod.Selected.Amount.Total
- var tax = 0
+ var tax = this.data.Cart.Totals.TotalSalesTax
var total = this.data.Cart.Totals.TotalToPay
this.$subtotal.html( as_cash(subtotal) )