mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Refactor js CurrentOrder
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)=>
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user