From 1952655d75455d6338e869ca40803848fb1d7e9d Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 3 Jan 2025 15:14:50 +1100 Subject: [PATCH 1/3] Remove unnecessary storage of checkout zone --- app/helpers/spree/base_helper.rb | 2 +- config/application.rb | 1 - spec/base_spec_helper.rb | 2 -- spec/helpers/spree/base_helper_spec.rb | 7 ++++--- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/helpers/spree/base_helper.rb b/app/helpers/spree/base_helper.rb index 77e8378fac7..ecf0d2cc6e9 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/config/application.rb b/config/application.rb index 19cd559d977..05d7cef54e7 100644 --- a/config/application.rb +++ b/config/application.rb @@ -93,7 +93,6 @@ class Application < Rails::Application # 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 diff --git a/spec/base_spec_helper.rb b/spec/base_spec_helper.rb index 5579890b642..9c9d9a8f43c 100644 --- a/spec/base_spec_helper.rb +++ b/spec/base_spec_helper.rb @@ -235,14 +235,12 @@ 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 diff --git a/spec/helpers/spree/base_helper_spec.rb b/spec/helpers/spree/base_helper_spec.rb index 35511de2bef..050b1b61f2d 100644 --- a/spec/helpers/spree/base_helper_spec.rb +++ b/spec/helpers/spree/base_helper_spec.rb @@ -10,11 +10,12 @@ 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 @@ 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 @@ 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 From fe3c96e91543e007edbc8963cc249cdfe6bb65be Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 3 Jan 2025 15:32:58 +1100 Subject: [PATCH 2/3] Remove unnecessary storage of currency --- config/application.rb | 16 ---------------- spec/base_spec_helper.rb | 2 -- spec/lib/spree/money_spec.rb | 2 -- spec/models/spree/adjustment_spec.rb | 4 ++-- spec/models/spree/order_spec.rb | 2 +- spec/models/spree/variant_spec.rb | 4 ++-- spec/system/admin/reports_spec.rb | 2 +- 7 files changed, 6 insertions(+), 26 deletions(-) diff --git a/config/application.rb b/config/application.rb index 05d7cef54e7..a6e2dc3398f 100644 --- a/config/application.rb +++ b/config/application.rb @@ -81,22 +81,6 @@ class Application < Rails::Application ] 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['currency'] = ENV['CURRENCY'] - end - end - initializer "load_spree_calculators" do |app| # Register Spree calculators Rails.application.reloader.to_prepare do diff --git a/spec/base_spec_helper.rb b/spec/base_spec_helper.rb index 9c9d9a8f43c..a9fd8cadc7a 100644 --- a/spec/base_spec_helper.rb +++ b/spec/base_spec_helper.rb @@ -235,13 +235,11 @@ end default_country_id = DefaultCountry.id - 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.currency = currency spree_config.shipping_instructions = true end CurrentConfig.clear_all diff --git a/spec/lib/spree/money_spec.rb b/spec/lib/spree/money_spec.rb index e79443e9209..a32d8576c63 100644 --- a/spec/lib/spree/money_spec.rb +++ b/spec/lib/spree/money_spec.rb @@ -7,7 +7,6 @@ before do configure_spree_preferences do |config| - config.currency = "USD" config.currency_symbol_position = :before config.display_currency = false end @@ -97,7 +96,6 @@ 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 9682d045ee8..abf3bcfb408 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 00a0cdb6214..5abc19da12d 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -516,7 +516,7 @@ 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 70068b41645..73754aaa72a 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -292,7 +292,7 @@ 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 @@ 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 072c546646a..2d689ff7a04 100644 --- a/spec/system/admin/reports_spec.rb +++ b/spec/system/admin/reports_spec.rb @@ -737,7 +737,7 @@ def xero_invoice_row(sku, description, amount, quantity, tax_type, opts = {}) 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 From ed5cb00f45bda6315b84b1b1c68130fd3616fc67 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 3 Jan 2025 15:40:51 +1100 Subject: [PATCH 3/3] Remove unused app config options This has been defined in ENV for a while --- app/models/spree/app_configuration.rb | 3 --- ...delete_checkout_zone_and_currency_preferences.rb | 13 +++++++++++++ db/schema.rb | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20250103043626_delete_checkout_zone_and_currency_preferences.rb diff --git a/app/models/spree/app_configuration.rb b/app/models/spree/app_configuration.rb index f624928703b..ca6e71f17d2 100644 --- a/app/models/spree/app_configuration.rb +++ b/app/models/spree/app_configuration.rb @@ -33,9 +33,6 @@ class AppConfiguration < Preferences::Configuration 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/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 00000000000..0b6f5939eb6 --- /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/db/schema.rb b/db/schema.rb index be371a9499d..fbec4d3ac72 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_11_12_230401) do +ActiveRecord::Schema[7.0].define(version: 2025_01_03_043626) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "plpgsql"