diff --git a/app/controllers/api/v1/customers_controller.rb b/app/controllers/api/v1/customers_controller.rb index 7e56ab6b28..da3037ff75 100644 --- a/app/controllers/api/v1/customers_controller.rb +++ b/app/controllers/api/v1/customers_controller.rb @@ -77,7 +77,8 @@ module Api :phone, :latitude, :longitude, :first_name, :last_name, :street_address_1, :street_address_2, - :postal_code, :locality, :region, :country, + :postal_code, :locality, + { region: [:name, :code], country: [:name, :code] }, ] ).to_h @@ -112,11 +113,11 @@ module Api end if address[:state_name].present? - address[:state] = Spree::State.find_by(name: address[:state_name]) + address[:state] = Spree::State.find_by(name: address[:state_name][:name]) end if address[:country].present? - address[:country] = Spree::Country.find_by(name: address[:country]) + address[:country] = Spree::Country.find_by(name: address[:country][:name]) end attributes["#{to}_attributes"] = address diff --git a/app/json_schemas/customer_schema.rb b/app/json_schemas/customer_schema.rb index 553f4cd522..264caf93fc 100644 --- a/app/json_schemas/customer_schema.rb +++ b/app/json_schemas/customer_schema.rb @@ -41,8 +41,8 @@ class CustomerSchema < JsonApiSchema street_address_2: "", postal_code: "1234", locality: "Melbourne", - region: "Victoria", - country: "Australia", + region: { code: "Vic", name: "Victoria" }, + country: { code: "AUS", name: "Australia" }, } end diff --git a/app/serializers/api/v1/address_serializer.rb b/app/serializers/api/v1/address_serializer.rb index da53af79f2..91dff2d701 100644 --- a/app/serializers/api/v1/address_serializer.rb +++ b/app/serializers/api/v1/address_serializer.rb @@ -11,8 +11,18 @@ module Api attribute :street_address_2, &:address2 attribute :postal_code, &:zipcode attribute :locality, &:city - attribute :region, &:state_name - attribute :country, ->(object, _) { object.country.name } + attribute :region do |object| + { + name: object.state.name, + code: object.state.abbr, + } + end + attribute :country do |object| + { + name: object.country.name, + code: object.country.iso3, + } + end end end end