Convert state_id and country_id in serializer

This commit is contained in:
Bing Xie
2016-09-16 10:55:11 +10:00
parent 8d534041b2
commit 80d755da0d
4 changed files with 12 additions and 16 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.getOrder()
line_items: CurrentOrder.getOrder()?.line_items || []
order: CurrentOrder.order
line_items: CurrentOrder.order?.line_items || []
constructor: ->
for line_item in @line_items

View File

@@ -2,7 +2,7 @@ Darkswarm.factory 'Checkout', (CurrentOrder, ShippingMethods, PaymentMethods, $h
new class Checkout
errors: {}
secrets: {}
order: CurrentOrder.getOrder()
order: CurrentOrder.order
ship_address_same_as_billing: 'YES'
default_bill_address: 'NO'
default_ship_address: 'NO'

View File

@@ -1,16 +1,4 @@
Darkswarm.factory 'CurrentOrder', (currentOrder) ->
# Populate Currentorder.order from json in page. This is probably redundant now.
new class CurrentOrder
# 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 && currentOrder.ship_address
currentOrder.ship_address.state_id = currentOrder.ship_address.state_id + ''
currentOrder.ship_address.country_id = currentOrder.ship_address.country_id + ''
currentOrder
order: currentOrder

View File

@@ -9,4 +9,12 @@ class Api::AddressSerializer < ActiveModel::Serializer
def state_name
object.state.andand.abbr
end
def state_id
object.state_id.andand.to_s
end
def country_id
object.country_id.andand.to_s
end
end