From 9d6722c2ecf8dd6917f453259d052b02e4a0b051 Mon Sep 17 00:00:00 2001 From: Edwin Cruz Date: Tue, 20 Feb 2018 00:13:37 -0600 Subject: [PATCH] Allowing admin to show all countries regardless checkout zone --- backend/app/views/spree/admin/prices/_form.html.erb | 2 +- backend/app/views/spree/admin/stock_locations/_form.html.erb | 2 +- core/app/helpers/spree/base_helper.rb | 4 ++-- core/spec/helpers/base_helper_spec.rb | 4 ++++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/app/views/spree/admin/prices/_form.html.erb b/backend/app/views/spree/admin/prices/_form.html.erb index 60538cd5ef3..7f6bb65a067 100644 --- a/backend/app/views/spree/admin/prices/_form.html.erb +++ b/backend/app/views/spree/admin/prices/_form.html.erb @@ -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]) }, diff --git a/backend/app/views/spree/admin/stock_locations/_form.html.erb b/backend/app/views/spree/admin/stock_locations/_form.html.erb index 87a8e04e998..d79fc166afc 100644 --- a/backend/app/views/spree/admin/stock_locations/_form.html.erb +++ b/backend/app/views/spree/admin/stock_locations/_form.html.erb @@ -107,7 +107,7 @@ <%= f.field_container :country_id do %> <%= f.label :country_id %> - <%= f.collection_select :country_id, available_countries, :id, :name, { include_blank: true }, { class: 'custom-select js-country_id fullwidth' } %> + <%= f.collection_select :country_id, available_countries(restrict_to_zone: nil), :id, :name, { include_blank: true }, { class: 'custom-select js-country_id fullwidth' } %> <% end %> <%= f.field_container :state do %> diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb index d6ced9b15af..fbc67218b28 100644 --- a/core/app/helpers/spree/base_helper.rb +++ b/core/app/helpers/spree/base_helper.rb @@ -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 diff --git a/core/spec/helpers/base_helper_spec.rb b/core/spec/helpers/base_helper_spec.rb index d81f5488bfa..567bff00f1b 100644 --- a/core/spec/helpers/base_helper_spec.rb +++ b/core/spec/helpers/base_helper_spec.rb @@ -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