Skip to content

Commit

Permalink
Allowing admin to show all countries regardless checkout zone
Browse files Browse the repository at this point in the history
  • Loading branch information
softr8 committed Feb 20, 2018
1 parent 9cac529 commit 9d6722c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend/app/views/spree/admin/prices/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<%= f.field_container :country do %>
<%= f.label :country %>
<%= f.field_hint :country %>
<%= f.collection_select :country_iso, available_countries, :iso, :name,
<%= f.collection_select :country_iso, available_countries(restrict_to_zone: nil), :iso, :name,
{
include_blank: t(:any_country, scope: [:spree, :admin, :prices])
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@

<%= f.field_container :country_id do %>
<%= f.label :country_id %>
<span id="country"><%= f.collection_select :country_id, available_countries, :id, :name, { include_blank: true }, { class: 'custom-select js-country_id fullwidth' } %></span>
<span id="country"><%= f.collection_select :country_id, available_countries(restrict_to_zone: nil), :id, :name, { include_blank: true }, { class: 'custom-select js-country_id fullwidth' } %></span>
<% end %>

<%= f.field_container :state do %>
Expand Down
4 changes: 2 additions & 2 deletions core/app/helpers/spree/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def taxons_tree(root_taxon, current_taxon, max_level = 1)
end
end

def available_countries
checkout_zone = Zone.find_by(name: Spree::Config[:checkout_zone])
def available_countries(restrict_to_zone: Spree::Config[:checkout_zone])
checkout_zone = Zone.find_by(name: restrict_to_zone)

if checkout_zone && checkout_zone.kind == 'country'
countries = checkout_zone.country_list
Expand Down
4 changes: 4 additions & 0 deletions core/spec/helpers/base_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
it "return only the countries defined by the checkout zone" do
expect(available_countries).to eq([country])
end

it "returns only the countries defined by the checkout zone passed as parameter" do
expect(available_countries(restrict_to_zone: @country_zone.name)).to eq([country])
end
end

context "checkout zone is of type state" do
Expand Down

0 comments on commit 9d6722c

Please sign in to comment.