diff --git a/app/helpers/spree/base_helper.rb b/app/helpers/spree/base_helper.rb index 77e8378fac..ecf0d2cc6e 100644 --- a/app/helpers/spree/base_helper.rb +++ b/app/helpers/spree/base_helper.rb @@ -3,7 +3,7 @@ module Spree module BaseHelper def available_countries - checkout_zone = Zone.find_by(name: Spree::Config[:checkout_zone]) + checkout_zone = Zone.find_by(name: ENV.fetch("CHECKOUT_ZONE", nil)) countries = if checkout_zone && checkout_zone.kind == 'country' checkout_zone.countries diff --git a/app/models/spree/app_configuration.rb b/app/models/spree/app_configuration.rb index f624928703..ca6e71f17d 100644 --- a/app/models/spree/app_configuration.rb +++ b/app/models/spree/app_configuration.rb @@ -33,9 +33,6 @@ module Spree preference :allow_backorder_shipping, :boolean, default: false preference :allow_checkout_on_gateway_error, :boolean, default: false preference :allow_guest_checkout, :boolean, default: true - # Replace with the name of a zone if you would like to limit the countries - preference :checkout_zone, :string, default: nil - preference :currency, :string, default: "USD" preference :currency_decimal_mark, :string, default: "." preference :currency_symbol_position, :string, default: "before" preference :currency_thousands_separator, :string, default: "," diff --git a/config/application.rb b/config/application.rb index 19cd559d97..a6e2dc3398 100644 --- a/config/application.rb +++ b/config/application.rb @@ -81,23 +81,6 @@ module Openfoodnetwork ] end - # Settings dependent on locale - # - # We need to set this config before the promo environment gets loaded and - # after the spree environment gets loaded... - # This is because Spree uses `Spree::Config` while evaluating classes :scream: - # - # https://github.com/spree/spree/blob/2-0-stable/core/app/models/spree/calculator/per_item.rb#L6 - # - # TODO: move back to spree initializer once we upgrade to a more recent version - # of Spree - initializer 'ofn.spree_locale_settings', before: 'spree.promo.environment' do |app| - Rails.application.reloader.to_prepare do - Spree::Config['checkout_zone'] = ENV['CHECKOUT_ZONE'] - Spree::Config['currency'] = ENV['CURRENCY'] - end - end - initializer "load_spree_calculators" do |app| # Register Spree calculators Rails.application.reloader.to_prepare do diff --git a/db/migrate/20250103043626_delete_checkout_zone_and_currency_preferences.rb b/db/migrate/20250103043626_delete_checkout_zone_and_currency_preferences.rb new file mode 100644 index 0000000000..0b6f5939eb --- /dev/null +++ b/db/migrate/20250103043626_delete_checkout_zone_and_currency_preferences.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class DeleteCheckoutZoneAndCurrencyPreferences < ActiveRecord::Migration[7.0] + def up + execute <<~SQL + DELETE FROM spree_preferences + WHERE key IN ( + '/spree/app_configuration/checkout_zone', + '/spree/app_configuration/currency' + ) + SQL + end +end diff --git a/spec/base_spec_helper.rb b/spec/base_spec_helper.rb index 026e538315..c4cb929a7e 100644 --- a/spec/base_spec_helper.rb +++ b/spec/base_spec_helper.rb @@ -235,15 +235,11 @@ RSpec.configure do |config| end default_country_id = DefaultCountry.id - checkout_zone = Spree::Config[:checkout_zone] - currency = Spree::Config[:currency] # Ensure we start with consistent config settings config.before(:each) do reset_spree_preferences do |spree_config| # These are all settings that differ from Spree's defaults spree_config.default_country_id = default_country_id - spree_config.checkout_zone = checkout_zone - spree_config.currency = currency spree_config.shipping_instructions = true end CurrentConfig.clear_all diff --git a/spec/helpers/spree/base_helper_spec.rb b/spec/helpers/spree/base_helper_spec.rb index 35511de2be..050b1b61f2 100644 --- a/spec/helpers/spree/base_helper_spec.rb +++ b/spec/helpers/spree/base_helper_spec.rb @@ -10,11 +10,12 @@ RSpec.describe Spree::BaseHelper do before do 3.times { create(:country) } + allow(ENV).to receive(:fetch).and_call_original end context "with no checkout zone defined" do before do - Spree::Config[:checkout_zone] = nil + allow(ENV).to receive(:fetch).and_return(nil) end it "return complete list of countries" do @@ -27,7 +28,7 @@ RSpec.describe Spree::BaseHelper do before do @country_zone = create(:zone, name: "CountryZone") @country_zone.members.create(zoneable: country) - Spree::Config[:checkout_zone] = @country_zone.name + allow(ENV).to receive(:fetch).and_return(@country_zone.name) end it "return only the countries defined by the checkout zone" do @@ -40,7 +41,7 @@ RSpec.describe Spree::BaseHelper do state_zone = create(:zone, name: "StateZone") state = create(:state, country:) state_zone.members.create(zoneable: state) - Spree::Config[:checkout_zone] = state_zone.name + allow(ENV).to receive(:fetch).and_return(state_zone.name) end it "return complete list of countries" do diff --git a/spec/lib/spree/money_spec.rb b/spec/lib/spree/money_spec.rb index e79443e920..a32d8576c6 100644 --- a/spec/lib/spree/money_spec.rb +++ b/spec/lib/spree/money_spec.rb @@ -7,7 +7,6 @@ RSpec.describe Spree::Money do before do configure_spree_preferences do |config| - config.currency = "USD" config.currency_symbol_position = :before config.display_currency = false end @@ -97,7 +96,6 @@ RSpec.describe Spree::Money do context "EUR" do before do configure_spree_preferences do |config| - config.currency = "EUR" config.currency_symbol_position = :after config.display_currency = false end diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index 9682d045ee..abf3bcfb40 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -133,7 +133,7 @@ module Spree before { Spree::Config[:display_currency] = true } it "shows the currency" do - expect(adjustment.display_amount.to_s).to eq "$10.55 #{Spree::Config[:currency]}" + expect(adjustment.display_amount.to_s).to eq "$10.55 AUD" end end @@ -167,7 +167,7 @@ module Spree context '#currency' do it 'returns the globally configured currency' do - expect(adjustment.currency).to eq Spree::Config[:currency] + expect(adjustment.currency).to eq "AUD" end end diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 00a0cdb621..5abc19da12 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -516,7 +516,7 @@ RSpec.describe Spree::Order do before { order.currency = nil } it "returns the globally configured currency" do - expect(order.currency).to eq Spree::Config[:currency] + expect(order.currency).to eq "AUD" end end end diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index 70068b4164..73754aaa72 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -292,7 +292,7 @@ RSpec.describe Spree::Variant do context "#currency" do it "returns the globally configured currency" do variant.save! - expect(variant.currency).to eq Spree::Config[:currency] + expect(variant.currency).to eq "AUD" end end @@ -309,7 +309,7 @@ RSpec.describe Spree::Variant do it "populates cost currency with the default value on save" do variant.save! - expect(variant.cost_currency).to eq Spree::Config[:currency] + expect(variant.cost_currency).to eq "AUD" end end end diff --git a/spec/system/admin/reports_spec.rb b/spec/system/admin/reports_spec.rb index 072c546646..2d689ff7a0 100644 --- a/spec/system/admin/reports_spec.rb +++ b/spec/system/admin/reports_spec.rb @@ -737,7 +737,7 @@ RSpec.describe ' sku, description, quantity, - amount.to_s, '', opts[:account_code], tax_type, '', '', '', '', Spree::Config.currency, + amount.to_s, '', opts[:account_code], tax_type, '', '', '', '', "AUD", '', 'N'] end end