improved checkout country and state selectors code

This commit is contained in:
luisramos0
2018-05-31 23:00:14 +01:00
committed by Maikel Linke
parent 3cb0b76d21
commit ea9ea83fee
3 changed files with 4 additions and 21 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -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"