From 3ed98b0406d66d1ae4767e0b966aaf9d554562a7 Mon Sep 17 00:00:00 2001 From: btolarz Date: Fri, 18 Oct 2019 15:12:45 +0200 Subject: [PATCH] Moved supported currencies from preferencies to store --- .../concerns/spree/api/v2/storefront/order_concern.rb | 4 +--- .../controllers/spree/api/v1/stores_controller_spec.rb | 3 ++- api/spec/requests/spree/api/v2/storefront/cart_spec.rb | 6 +----- .../spree/admin/general_settings_controller.rb | 2 +- .../views/spree/admin/general_settings/_form.html.erb | 6 ------ backend/app/views/spree/admin/stores/_form.html.erb | 5 +++++ .../spec/features/admin/configuration/stores_spec.rb | 6 +++++- .../general_settings/prices_settings_presence_spec.rb | 1 - .../general_settings/prices_settings_updating_spec.rb | 5 +---- .../features/admin/products/variant_prices_spec.rb | 3 +-- core/app/models/spree/app_configuration.rb | 1 - core/app/models/spree/store.rb | 10 ++++++++++ ...20191017121054_add_supported_currencies_to_store.rb | 8 ++++++++ .../spree/core/controller_helpers/currency_helpers.rb | 2 +- core/lib/spree/core/controller_helpers/store.rb | 4 +--- core/lib/spree/permitted_attributes.rb | 5 +++-- .../spree/testing_support/factories/store_factory.rb | 9 +++++---- .../lib/spree/core/controller_helpers/store_spec.rb | 9 +++++++++ core/spec/models/spree/store_spec.rb | 10 ++++++++++ frontend/spec/features/order_prices_spec.rb | 3 ++- frontend/spec/features/product_prices_spec.rb | 4 +--- frontend/spec/features/template_rendering_spec.rb | 3 ++- 22 files changed, 69 insertions(+), 40 deletions(-) create mode 100644 core/db/migrate/20191017121054_add_supported_currencies_to_store.rb diff --git a/api/app/controllers/concerns/spree/api/v2/storefront/order_concern.rb b/api/app/controllers/concerns/spree/api/v2/storefront/order_concern.rb index 520be6bb900..37f907a7155 100644 --- a/api/app/controllers/concerns/spree/api/v2/storefront/order_concern.rb +++ b/api/app/controllers/concerns/spree/api/v2/storefront/order_concern.rb @@ -35,9 +35,7 @@ def find_spree_current_order end def supported_currencies - Spree::Config[:supported_currencies].split(',').map do |code| - ::Money::Currency.find(code.strip) - end + spree_current_store.supported_currencies_list end def serialize_order(order) diff --git a/api/spec/controllers/spree/api/v1/stores_controller_spec.rb b/api/spec/controllers/spree/api/v1/stores_controller_spec.rb index 4b5ebeb253a..86c959b7a0e 100644 --- a/api/spec/controllers/spree/api/v1/stores_controller_spec.rb +++ b/api/spec/controllers/spree/api/v1/stores_controller_spec.rb @@ -76,7 +76,8 @@ module Spree name: 'Hack0rz', url: 'spree123.example.com', mail_from_address: 'me@example.com', - default_currency: 'USD' + default_currency: 'USD', + supported_currencies: 'USD' } api_post :create, store: store_hash expect(response.status).to eq(201) diff --git a/api/spec/requests/spree/api/v2/storefront/cart_spec.rb b/api/spec/requests/spree/api/v2/storefront/cart_spec.rb index d3f8f190dda..e94fc519493 100644 --- a/api/spec/requests/spree/api/v2/storefront/cart_spec.rb +++ b/api/spec/requests/spree/api/v2/storefront/cart_spec.rb @@ -2,7 +2,7 @@ describe 'API V2 Storefront Cart Spec', type: :request do let(:default_currency) { 'USD' } - let(:store) { create(:store, default_currency: default_currency) } + let!(:store) { create(:store, default_currency: default_currency) } let(:currency) { store.default_currency } let(:user) { create(:user) } let(:order) { create(:order, user: user, store: store, currency: currency) } @@ -359,10 +359,6 @@ end context 'for specified currency' do - before do - Spree::Config[:supported_currencies] = 'USD,EUR' - end - context 'store default' do before do store.update!(default_currency: 'EUR') diff --git a/backend/app/controllers/spree/admin/general_settings_controller.rb b/backend/app/controllers/spree/admin/general_settings_controller.rb index adab53eecfe..f1b6cf2e809 100644 --- a/backend/app/controllers/spree/admin/general_settings_controller.rb +++ b/backend/app/controllers/spree/admin/general_settings_controller.rb @@ -27,7 +27,7 @@ def clear_cache end def render(*args) - @preferences_currency |= [:allow_currency_change, :show_currency_selector, :supported_currencies] + @preferences_currency |= [:allow_currency_change, :show_currency_selector] super end diff --git a/backend/app/views/spree/admin/general_settings/_form.html.erb b/backend/app/views/spree/admin/general_settings/_form.html.erb index d54defac59e..d2b4342706a 100644 --- a/backend/app/views/spree/admin/general_settings/_form.html.erb +++ b/backend/app/views/spree/admin/general_settings/_form.html.erb @@ -4,12 +4,6 @@
-
- - -

<%= Spree.t('supported_currencies.long') %>

-
-