summaryrefslogtreecommitdiff
path: root/StoneIsland/www/js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-11-28 20:13:05 -0500
committerJules Laplace <jules@okfoc.us>2015-11-28 20:13:05 -0500
commit72ba42fce0c81601ec8ea5e544f35de1fdbf708d (patch)
treec89b9485a3a262c02132e40c5aab61b6c9c056aa /StoneIsland/www/js
parent5374ce4ed870a5b007c21a880ffc0134dc676d89 (diff)
finalize shipping
Diffstat (limited to 'StoneIsland/www/js')
-rw-r--r--StoneIsland/www/js/lib/account/AccountView.js5
-rw-r--r--StoneIsland/www/js/lib/cart/CartShipping.js42
-rw-r--r--StoneIsland/www/js/lib/nav/AddressView.js3
3 files changed, 46 insertions, 4 deletions
diff --git a/StoneIsland/www/js/lib/account/AccountView.js b/StoneIsland/www/js/lib/account/AccountView.js
index fb22cf60..f76541be 100644
--- a/StoneIsland/www/js/lib/account/AccountView.js
+++ b/StoneIsland/www/js/lib/account/AccountView.js
@@ -17,6 +17,7 @@ var AccountView = View.extend({
},
addresses: [],
+ addressLookup: {},
listAddresses: function(cb){
sdk.address.list({
success: function(data){
@@ -35,7 +36,9 @@ var AccountView = View.extend({
}
this.addresses = data.AddressBook.addressBookItem
+ this.addressLookup = {}
data.AddressBook.addressBookItem.forEach(function(item){
+ this.addressLookup[ item.Id ] = item
if (item.IsDefault) {
console.log("SHIPPING ADDRESS", item)
app.shipping.populate(item)
@@ -44,7 +47,7 @@ var AccountView = View.extend({
console.log("BILLING ADDRESS")
app.payment.populate(item)
}
- })
+ }.bind(this))
app.cart.shipping.populate()
diff --git a/StoneIsland/www/js/lib/cart/CartShipping.js b/StoneIsland/www/js/lib/cart/CartShipping.js
index 7236347f..d1e1a97e 100644
--- a/StoneIsland/www/js/lib/cart/CartShipping.js
+++ b/StoneIsland/www/js/lib/cart/CartShipping.js
@@ -2,6 +2,8 @@ var CartShipping = FormView.extend({
el: "#cart_shipping",
+ action: sdk.cart.set_shipping_address,
+
list_mode: true,
template: $("#cart_shipping .template").html(),
@@ -18,6 +20,7 @@ var CartShipping = FormView.extend({
this.$msg = this.$(".msg")
this.address = new AddressView ({ parent: this })
this.scroller = new IScroll('#cart_shipping', app.iscroll_options)
+ this.address.disabled = true
},
show: function(){
@@ -50,6 +53,7 @@ var CartShipping = FormView.extend({
toggle_dropdown: function(state){
this.list_mode = typeof state == "boolean" ? state : ! this.list_mode
+ this.address.disabled = this.list_mode
this.$address_form.toggle(! this.list_mode)
this.$address_list.toggle(this.list_mode)
},
@@ -58,16 +62,48 @@ var CartShipping = FormView.extend({
// sdk.shipping.get_delivery_types
// sdk.shipping.set_delivery_type
+ shipping_types: {
+ Standard: 1,
+ Express: 2,
+ },
+
finalize: function(data){
- console.log(data)
- return
+ var shipping_info = {}, address_data, address_id
+ var shipping_type = $("[name=ShippingType]").filter(function(){ return $(this).prop("checked") }).val()
+ sdk.shipping.set_delivery_type({
+ id: this.shipping_types[shipping_type],
+ success: function(data){ console.log("set shipping type", data) },
+ error: function(data){ console.log("didnt set shipping type", data) },
+ })
+
+ if (this.list_mode) {
+ address_id = $("[name=AddressId]").filter(function(){ return $(this).prop("checked") }).val()
+ address_data = app.account.addressLookup[ address_id ]
+ }
+ else {
+ address_data = data
+ }
+
+ shipping_info.Name = address_data.Name
+ shipping_info.Surname = address_data.Surname
+ shipping_info.Email = address_data.Name
+ 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.Region = address_data.Province
+ shipping_info.CountryCode = "US"
+
+ return address_data
},
success: function(){
+ app.router.go('cart/payment')
},
cancel: function(){
- app.cart.cart_summary.show()
+ app.router.go('cart/summary')
},
}) \ No newline at end of file
diff --git a/StoneIsland/www/js/lib/nav/AddressView.js b/StoneIsland/www/js/lib/nav/AddressView.js
index 90520a1e..31e9d802 100644
--- a/StoneIsland/www/js/lib/nav/AddressView.js
+++ b/StoneIsland/www/js/lib/nav/AddressView.js
@@ -3,6 +3,8 @@ var AddressView = SerializableView.extend({
template: $("#address_template").html(),
+ disabled: false,
+
events: {
},
@@ -31,6 +33,7 @@ var AddressView = SerializableView.extend({
},
validate_fields: function(data, errors){
+ if (this.disabled) { return }
if (this.checkPhone && ! data.Phone) { errors.push([ "Phone", "Please enter your phone number." ]) }
if (this.checkPhone && data.Phone && data.Phone.replace(/[^0-9]/g, "").length < 10) { errors.push([ "Phone", "Phone numbers must be at least 10 digits." ]) }
if (! data.Province || data.Province == "NONE") { errors.push([ "Province", "Please choose your state." ]) }