Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Remove default checkout zone

Przemek Kosakowski1e9c20d263c4
diff --git a/backend/app/helpers/spree/admin/stores_helper.rb b/backend/app/helpers/spree/admin/stores_helper.rb
index 161579f628..72c64e4a8d 100644
--- a/backend/app/helpers/spree/admin/stores_helper.rb
+++ b/backend/app/helpers/spree/admin/stores_helper.rb
@@ -2,9 +2,7 @@ module Spree
module Admin
module StoresHelper
def selected_checkout_zone(store)
- return Spree::Zone.find_by(id: store.checkout_zone_id) unless store.checkout_zone_id.nil?
-
- Spree::Zone.default_checkout_zone
+ store&.checkout_zone || Spree::Zone.default_checkout_zone
end
end
end
diff --git a/backend/app/views/spree/admin/stores/_form.html.erb b/backend/app/views/spree/admin/stores/_form.html.erb
index 80f89096c7..cdbd76afbd 100644
--- a/backend/app/views/spree/admin/stores/_form.html.erb
+++ b/backend/app/views/spree/admin/stores/_form.html.erb
@@ -118,7 +118,7 @@
<% end %>
<%= f.field_container :checkout_zone_id, class: ['form-group'] do %>
<%= f.label :checkout_zone_id, Spree.t(:zone) %>
- <%= f.select :checkout_zone_id, options_for_select(@zones, selected_checkout_zone(@store).id), {}, { class: 'select2' } %>
+ <%= f.select :checkout_zone_id, options_for_select(@zones, selected_checkout_zone(@store)&.id), { include_blank: Spree.t(:no_limits_zone) }, { class: 'select2' } %>
<%= f.label :checkout_zone_id, Spree.t('i18n.checkout_zone_warning_html'), class: 'alert alert-warning col-12' %>
<%= f.error_message_on :checkout_zone_id %>
<% end %>
diff --git a/backend/spec/features/admin/store_spec.rb b/backend/spec/features/admin/store_spec.rb
index ecbf5525bf..98a62477b6 100644
--- a/backend/spec/features/admin/store_spec.rb
+++ b/backend/spec/features/admin/store_spec.rb
@@ -129,9 +129,8 @@ describe 'Stores', type: :feature, js: true do
end
end
- context 'without checkout_zone_id attribute and checkout_zone preference' do
+ context 'without checkout_zone_id attribute and checkout_zone preference' do
let!(:store) { create(:store, name: 'Some existing store', checkout_zone_id: nil) }
- let!(:zone) { create(:zone, name: 'No Limits') }
before do
Spree::Config.preference_default(:checkout_zone)
diff --git a/backend/spec/helpers/spree/admin/stores_helper_spec.rb b/backend/spec/helpers/spree/admin/stores_helper_spec.rb
index c8865fe2b5..a4a44a216a 100644
--- a/backend/spec/helpers/spree/admin/stores_helper_spec.rb
+++ b/backend/spec/helpers/spree/admin/stores_helper_spec.rb
@@ -30,16 +30,14 @@ describe Spree::Admin::StoresHelper, type: :helper do
end
end
- context 'return No Limits zone' do
+ context 'checkout_zone is not set via preference or store' do
before do
Spree::Config.preference_default(:checkout_zone)
store.update(checkout_zone_id: nil)
- country_zone.update(name: 'No Limits')
- country_zone.members.create(zoneable: country)
end
- it 'return countries' do
- expect(selected_checkout_zone(store)).to eq country_zone
+ it 'return nil' do
+ expect(selected_checkout_zone(store)).to eq nil
end
end
end
diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb
index 28631293e3..780a6872d6 100644
--- a/core/app/helpers/spree/base_helper.rb
+++ b/core/app/helpers/spree/base_helper.rb
@@ -1,7 +1,7 @@
module Spree
module BaseHelper
def available_countries
- checkout_zone = current_store.zone || Spree::Zone.default_checkout_zone
+ checkout_zone = current_store.checkout_zone || Spree::Zone.default_checkout_zone
countries = if checkout_zone && checkout_zone.kind == 'country'
checkout_zone.country_list
@@ -212,7 +212,7 @@ module Spree
def meta_robots
return unless current_store.respond_to?(:seo_robots)
return if current_store.seo_robots.blank?
-
+
tag('meta', name: 'robots', content: current_store.seo_robots)
end
end
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rb
index 231d716b10..85ac8cc7a5 100644
--- a/core/app/models/spree/store.rb
+++ b/core/app/models/spree/store.rb
@@ -3,7 +3,7 @@ module Spree
has_many :orders, class_name: 'Spree::Order'
has_many :payment_methods, class_name: 'Spree::PaymentMethod'
belongs_to :default_country, class_name: 'Spree::Country'
- belongs_to :zone, class_name: 'Spree::Zone', foreign_key: 'checkout_zone_id'
+ belongs_to :checkout_zone, class_name: 'Spree::Zone'
with_options presence: true do
validates :name, :url, :mail_from_address, :default_currency, :code
diff --git a/core/app/models/spree/zone.rb b/core/app/models/spree/zone.rb
index 1a5fd4dd8f..84f4597d6d 100644
--- a/core/app/models/spree/zone.rb
+++ b/core/app/models/spree/zone.rb
@@ -71,7 +71,7 @@ module Spree
end
def self.default_checkout_zone
- find_by(name: Spree::Config[:checkout_zone]) || find_by(name: Spree.t(:default_zone))
+ find_by(name: Spree::Config[:checkout_zone])
end
def kind
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index 4d01450509..eec83f463a 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -1812,4 +1812,4 @@ en:
zipcode_required: Zip Code Required
zone: Zone
zones: Zones
- default_zone: No Limits
+ no_limits_zone: No Limits
diff --git a/core/db/default/spree/zones.rb b/core/db/default/spree/zones.rb
index e06e63769b..e32f14a9c8 100644
--- a/core/db/default/spree/zones.rb
+++ b/core/db/default/spree/zones.rb
@@ -3,9 +3,6 @@ north_america = Spree::Zone.where(name: 'North America', description: 'USA + Can
south_america = Spree::Zone.where(name: 'South America', description: 'South America', kind: 'country').first_or_create!
middle_east = Spree::Zone.where(name: 'Middle East', description: 'Middle East', kind: 'country').first_or_create!
asia = Spree::Zone.where(name: 'Asia', description: 'Asia', kind: 'country').first_or_create!
-no_limits = Spree::Zone.where(name: 'No Limits', description: 'Includes all the countries of the world!', kind: 'country').first_or_create!
-
-Spree::Country.pluck(:iso).each { |iso| no_limits.zone_members.where(zoneable: Spree::Country.find_by!(iso: iso)).first_or_create! }
%w(PL FI PT RO DE FR SK HU SI IE AT ES IT BE SE LV BG GB LT CY LU MT DK NL EE HR CZ GR).each do |name|
eu_vat.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
diff --git a/core/db/migrate/20201006110150_add_checkout_zone_field_to_store.rb b/core/db/migrate/20201006110150_add_checkout_zone_field_to_store.rb
index 8bca041d99..aea8ff9df1 100644
--- a/core/db/migrate/20201006110150_add_checkout_zone_field_to_store.rb
+++ b/core/db/migrate/20201006110150_add_checkout_zone_field_to_store.rb
@@ -1,10 +1,12 @@
class AddCheckoutZoneFieldToStore < ActiveRecord::Migration[6.0]
def change
unless column_exists?(:spree_stores, :checkout_zone_id)
- add_reference :spree_stores, :checkout_zone, { references: :spree_zones, index: true }
+ add_column :spree_stores, :checkout_zone_id, :integer
Spree::Store.reset_column_information
- Spree::Store.update_all(checkout_zone_id: Spree::Zone.find_by(name: Spree::Config[:checkout_zone])&.id)
+
+ default_zone = Spree::Zone.default_checkout_zone
+ Spree::Store.update_all(checkout_zone_id: default_zone.id) if default_zone.present?
end
end
end
diff --git a/core/spec/models/spree/zone_spec.rb b/core/spec/models/spree/zone_spec.rb
index 990f6a8dc9..746123a025 100644
--- a/core/spec/models/spree/zone_spec.rb
+++ b/core/spec/models/spree/zone_spec.rb
@@ -483,7 +483,7 @@ describe Spree::Zone, type: :model do
before { Spree::Config[:checkout_zone] = nil }
it 'return default checkout zone object' do
- expect(Spree::Zone.default_checkout_zone).to eq default_zone
+ expect(Spree::Zone.default_checkout_zone).to eq nil
end
end
end