mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Moving to a switch
This commit is contained in:
@@ -7,31 +7,28 @@ Darkswarm.factory 'Order', ($resource, Product, order, $http)->
|
||||
@order.shipping_method_id ||= parseInt(Object.keys(@order.shipping_methods)[0])
|
||||
|
||||
navigate: (path)->
|
||||
console.log path
|
||||
window.location.pathname = path
|
||||
|
||||
submit: ->
|
||||
$http.put('/shop/checkout', {order: @preprocess()}).success (data, status)=>
|
||||
@navigate(data.path)
|
||||
.error (errors, status)=>
|
||||
console.log "error"
|
||||
@errors = errors
|
||||
|
||||
|
||||
|
||||
# Rails wants our Spree::Address data to be provided with _attributes
|
||||
preprocess: ->
|
||||
munged_order = {}
|
||||
for name, value of @order # Clone all data from the order JSON object
|
||||
if name == "bill_address"
|
||||
munged_order["bill_address_attributes"] = value
|
||||
else if name == "ship_address"
|
||||
munged_order["ship_address_attributes"] = value
|
||||
else if name == "payment_method_id"
|
||||
munged_order["payments_attributes"] = [{payment_method_id: value}]
|
||||
else
|
||||
munged_order[name] = value
|
||||
# TODO: this
|
||||
switch name
|
||||
when "bill_address"
|
||||
munged_order["bill_address_attributes"] = value
|
||||
when "ship_address"
|
||||
munged_order["ship_address_attributes"] = value
|
||||
when "payment_method_id"
|
||||
munged_order["payments_attributes"] = [{payment_method_id: value}]
|
||||
else
|
||||
munged_order[name] = value
|
||||
|
||||
if munged_order.ship_address_same_as_billing
|
||||
munged_order.ship_address_attributes = munged_order.bill_address_attributes
|
||||
munged_order
|
||||
|
||||
Reference in New Issue
Block a user