From ea9ea83fee377e7534b5c6b6584b983905fcd64a Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Thu, 31 May 2018 23:00:14 +0100 Subject: [PATCH] improved checkout country and state selectors code --- app/helpers/checkout_helper.rb | 10 ---------- app/views/checkout/_billing.html.haml | 7 ++----- app/views/checkout/_shipping_ship_address.html.haml | 8 ++------ 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb index b0bca2c05e..bc885bd5dc 100644 --- a/app/helpers/checkout_helper.rb +++ b/app/helpers/checkout_helper.rb @@ -66,16 +66,6 @@ module CheckoutHelper Spree::Money.new order.total - order.total_tax, currency: order.currency end - 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 validated_input(name, path, args = {}) attributes = { required: true, diff --git a/app/views/checkout/_billing.html.haml b/app/views/checkout/_billing.html.haml index 4e451b51cd..07b0d0f251 100644 --- a/app/views/checkout/_billing.html.haml +++ b/app/views/checkout/_billing.html.haml @@ -32,16 +32,13 @@ = validated_input t(:city), "order.bill_address.city" .small-6.columns - %label{ for: 'order.bill_address.state_id' } {{ "state" | t }} - %select.chunky{ id: 'order.bill_address.state_id', ng: { model: 'order.bill_address.state_id', options: 's.id as s.name for s in countriesById[order.bill_address.country_id].states' } } - + = validated_select t(:state), "order.bill_address.state_id", {}, {"ng-options" => "s.id as s.name for s in countriesById[order.bill_address.country_id].states"} .row .small-6.columns = validated_input t(:postcode), "order.bill_address.zipcode" .small-6.columns.right - %label{ for: 'order.bill_address.country_id' } {{ "country" | t }} - %select.chunky{ id: 'order.bill_address.country_id', required: false, ng: { init: "order.bill_address.country_id = #{Spree::Config[:default_country_id]}", model: 'order.bill_address.country_id', options: 'c.id as c.name for c in countries' } } + = validated_select t(:country), "order.bill_address.country_id", {}, {"ng-init" => "order.bill_address.country_id = order.bill_address.country_id || #{Spree::Config[:default_country_id]}", "ng-options" => "c.id as c.name for c in countries"} .row .small-12.columns.text-right diff --git a/app/views/checkout/_shipping_ship_address.html.haml b/app/views/checkout/_shipping_ship_address.html.haml index aa64e6c521..1119886a47 100644 --- a/app/views/checkout/_shipping_ship_address.html.haml +++ b/app/views/checkout/_shipping_ship_address.html.haml @@ -17,16 +17,12 @@ .small-6.columns = validated_input t(:city), "order.ship_address.city" .small-6.columns - %label{ for: 'order.ship_address.state_id' } {{ "state" | t }} - %select.chunky{ id: 'order.ship_address.state_id', ng: { model: 'order.ship_address.state_id', options: 's.id as s.name for s in countriesById[order.ship_address.country_id].states' } } - + = validated_select t(:state), "order.ship_address.state_id", {}, {"ng-options" => "s.id as s.name for s in countriesById[order.ship_address.country_id].states"} .row .small-6.columns = validated_input t(:postcode), "order.ship_address.zipcode" .small-6.columns.right - %label{ for: 'order.ship_address.country_id' } {{ "country" | t }} - %select.chunky{ id: 'order.ship_address.country_id', required: false, ng: { init: "order.ship_address.country_id = #{Spree::Config[:default_country_id]}", model: 'order.ship_address.country_id', options: 'c.id as c.name for c in countries' } } - + = validated_select t(:country), "order.ship_address.country_id", {}, {"ng-init" => "order.ship_address.country_id = order.ship_address.country_id || #{Spree::Config[:default_country_id]}", "ng-options" => "c.id as c.name for c in countries"} .row .small-6.columns = validated_input t(:phone), "order.ship_address.phone"