Checkout: Use validated_select for shipping address fields

This commit is contained in:
Rohan Mitchell
2014-11-06 14:50:20 +11:00
parent 7a0c291fc1
commit 433cf9dd9b
3 changed files with 11 additions and 7 deletions

View File

@@ -25,8 +25,14 @@ module CheckoutHelper
order.display_item_total.money.to_f + checkout_adjustments_total(order).money.to_f
end
def checkout_state_options
[[]] + @order.billing_address.country.states.map { |c| [c.name, c.id] }
def checkout_state_options(source_address)
if source_address == :billing
address = @order.billing_address
elsif source_address == :shipping
address = @order.shipping_address
end
[[]] + address.country.states.map { |c| [c.name, c.id] }
end
def checkout_country_options

View File

@@ -39,7 +39,7 @@
= validated_input "City", "order.bill_address.city"
.small-6.columns
= validated_select "State", "order.bill_address.state_id", checkout_state_options
= validated_select "State", "order.bill_address.state_id", checkout_state_options(:billing)
.row
.small-6.columns
= validated_input "Postcode", "order.bill_address.zipcode"

View File

@@ -66,14 +66,12 @@
.small-6.columns
= validated_input "City", "order.ship_address.city"
.small-6.columns
= sa.select :state_id, @order.shipping_address.country.states.map{|c|[c.name, c.id]}, {include_blank: false},
"ng-model" => "order.ship_address.state_id", required: true
= validated_select "State", "order.ship_address.state_id", checkout_state_options(:shipping)
.row
.small-6.columns
= validated_input "Postcode", "order.ship_address.zipcode"
.small-6.columns.right
= sa.select :country_id, available_countries.map{|c|[c.name, c.id]},
"ng-model" => "order.ship_address.country_id", required: true
= validated_select "Country", "order.ship_address.country_id", checkout_country_options
.row
.small-6.columns