Refactor js CurrentOrder

This commit is contained in:
Bing Xie
2016-09-08 18:46:58 +10:00
parent e91c313f1e
commit 8d534041b2
4 changed files with 12 additions and 9 deletions

View File

@@ -4,8 +4,8 @@ Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http, $modal, $roo
dirty: false
update_running: false
update_enqueued: false
order: CurrentOrder.order
line_items: CurrentOrder.order?.line_items || []
order: CurrentOrder.getOrder()
line_items: CurrentOrder.getOrder()?.line_items || []
constructor: ->
for line_item in @line_items

View File

@@ -2,12 +2,11 @@ Darkswarm.factory 'Checkout', (CurrentOrder, ShippingMethods, PaymentMethods, $h
new class Checkout
errors: {}
secrets: {}
order: CurrentOrder.order
order: CurrentOrder.getOrder()
ship_address_same_as_billing: 'YES'
default_bill_address: 'NO'
default_ship_address: 'NO'
submit: ->
Loading.message = t 'submitting_order'
$http.put('/checkout', {order: @preprocess()}).success (data, status)=>

View File

@@ -1,13 +1,16 @@
Darkswarm.factory 'CurrentOrder', (currentOrder) ->
# Populate Currentorder.order from json in page. This is probably redundant now.
new class CurrentOrder
constructor: ->
if currentOrder.bill_address
# order: currentOrder
getOrder: ->
if currentOrder && currentOrder.bill_address
currentOrder.bill_address.state_id = currentOrder.bill_address.state_id + ''
currentOrder.bill_address.country_id = currentOrder.bill_address.country_id + ''
if currentOrder.ship_address
if currentOrder && currentOrder.ship_address
currentOrder.ship_address.state_id = currentOrder.ship_address.state_id + ''
currentOrder.ship_address.country_id = currentOrder.ship_address.country_id + ''
@order = currentOrder
currentOrder

View File

@@ -156,7 +156,8 @@ class CheckoutController < Spree::CheckoutController
last_used_bill_address = lua.last_used_bill_address.andand.clone
last_used_ship_address = lua.last_used_ship_address.andand.clone
preferred_bill_address, preferred_ship_address = spree_current_user.bill_address, spree_current_user.ship_address
preferred_bill_address, preferred_ship_address = spree_current_user.bill_address, spree_current_user.ship_address if spree_current_user
@order.bill_address ||= preferred_bill_address || last_used_bill_address || Spree::Address.default
@order.ship_address ||= preferred_ship_address || last_used_ship_address || Spree::Address.default
end