From 06a9110e95e730bd41c20a57f03d1a66c44c80e7 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 6 Nov 2014 14:40:22 +1100 Subject: [PATCH] Extract checkout select options to helpers --- app/helpers/checkout_helper.rb | 8 ++++++++ app/views/checkout/_billing.html.haml | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb index f5c10c3649..e47b393998 100644 --- a/app/helpers/checkout_helper.rb +++ b/app/helpers/checkout_helper.rb @@ -25,6 +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] } + end + + def checkout_country_options + available_countries.map { |c| [c.name, c.id] } + end + def validated_input(name, path, args = {}) attributes = { diff --git a/app/views/checkout/_billing.html.haml b/app/views/checkout/_billing.html.haml index c1cafa6161..07faa3d442 100644 --- a/app/views/checkout/_billing.html.haml +++ b/app/views/checkout/_billing.html.haml @@ -39,13 +39,13 @@ = validated_input "City", "order.bill_address.city" .small-6.columns - = validated_select "State", "order.bill_address.state_id", [[]]+@order.billing_address.country.states.map{|c|[c.name, c.id]} + = validated_select "State", "order.bill_address.state_id", checkout_state_options .row .small-6.columns = validated_input "Postcode", "order.bill_address.zipcode" .small-6.columns.right - = ba.select :country_id, available_countries.map{|c|[c.name, c.id]}, + = ba.select :country_id, checkout_country_options, "ng-model" => "order.bill_address.country_id", required: true .row