spree_core 4.2.0.beta → 4.2.0.rc5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/spree/base_controller.rb +2 -3
- data/app/controllers/spree/errors_controller.rb +11 -0
- data/app/finders/spree/addresses/find.rb +6 -0
- data/app/finders/spree/base_finder.rb +14 -0
- data/app/finders/spree/countries/find.rb +11 -3
- data/app/finders/spree/credit_cards/find.rb +2 -2
- data/app/finders/spree/orders/find_current.rb +2 -2
- data/app/finders/spree/products/find.rb +12 -1
- data/app/helpers/spree/base_helper.rb +38 -18
- data/app/helpers/spree/locale_helper.rb +19 -0
- data/app/helpers/spree/mail_helper.rb +12 -7
- data/app/helpers/spree/products_helper.rb +39 -13
- data/app/mailers/spree/base_mailer.rb +5 -5
- data/app/mailers/spree/order_mailer.rb +3 -3
- data/app/mailers/spree/reimbursement_mailer.rb +1 -1
- data/app/mailers/spree/shipment_mailer.rb +1 -1
- data/app/models/concerns/spree/default_price.rb +1 -5
- data/app/models/concerns/spree/user_methods.rb +2 -2
- data/app/models/concerns/spree/user_payment_source.rb +1 -1
- data/app/models/spree/ability.rb +45 -34
- data/app/models/spree/address.rb +17 -1
- data/app/models/spree/adjustment.rb +1 -0
- data/app/models/spree/app_configuration.rb +2 -3
- data/app/models/spree/app_dependencies.rb +10 -2
- data/app/models/spree/base.rb +5 -0
- data/app/models/spree/credit_card.rb +5 -0
- data/app/models/spree/fulfilment_changer.rb +58 -16
- data/app/models/spree/image.rb +14 -14
- data/app/models/spree/inventory_unit.rb +2 -7
- data/app/models/spree/line_item.rb +9 -16
- data/app/models/spree/log_entry.rb +1 -1
- data/app/models/spree/option_type.rb +2 -0
- data/app/models/spree/order.rb +12 -6
- data/app/models/spree/order/address_book.rb +7 -20
- data/app/models/spree/order/payments.rb +10 -2
- data/app/models/spree/payment.rb +18 -4
- data/app/models/spree/payment/processing.rb +2 -2
- data/app/models/spree/payment_method.rb +3 -3
- data/app/models/spree/preferences/store.rb +1 -1
- data/app/models/spree/price.rb +1 -6
- data/app/models/spree/product.rb +24 -17
- data/app/models/spree/promotion.rb +10 -15
- data/app/models/spree/promotion/rules/option_value.rb +1 -1
- data/app/models/spree/promotion/rules/product.rb +2 -1
- data/app/models/spree/promotion/rules/user.rb +2 -1
- data/app/models/spree/promotion_handler/coupon.rb +1 -2
- data/app/models/spree/promotion_handler/promotion_duplicator.rb +9 -3
- data/app/models/spree/refund.rb +2 -2
- data/app/models/spree/return_item/eligibility_validator/default.rb +0 -2
- data/app/models/spree/return_item/eligibility_validator/{r_m_a_required.rb → rma_required.rb} +0 -0
- data/app/models/spree/shipment.rb +1 -1
- data/app/models/spree/shipping_method.rb +1 -5
- data/app/models/spree/shipping_rate.rb +2 -11
- data/app/models/spree/stock/availability_validator.rb +3 -4
- data/app/models/spree/stock_item.rb +1 -5
- data/app/models/spree/store.rb +45 -1
- data/app/models/spree/store_credit.rb +1 -1
- data/app/models/spree/variant.rb +8 -15
- data/app/models/spree/zone.rb +17 -4
- data/app/presenters/spree/variant_presenter.rb +4 -6
- data/app/services/spree/account/addresses/create.rb +23 -0
- data/app/services/spree/account/addresses/helper.rb +37 -0
- data/app/services/spree/account/addresses/update.rb +23 -0
- data/app/services/spree/cart/estimate_shipping_rates.rb +1 -1
- data/app/services/spree/checkout/update.rb +13 -2
- data/app/services/spree/compare_line_items.rb +4 -2
- data/app/sorters/spree/base_sorter.rb +35 -0
- data/app/sorters/spree/orders/sort.rb +1 -37
- data/app/sorters/spree/products/sort.rb +9 -32
- data/app/validators/email_validator.rb +1 -1
- data/app/views/spree/errors/forbidden.html.erb +0 -0
- data/app/views/spree/errors/unauthorized.html.erb +0 -0
- data/app/views/spree/shared/_base_mailer_stylesheets.html.erb +0 -2
- data/app/views/spree/shared/purchased_items_table/_line_item.html.erb +1 -1
- data/config/initializers/inflections.rb +3 -0
- data/config/initializers/rails61_fixes.rb +3 -0
- data/config/locales/en.yml +42 -63
- data/config/routes.rb +2 -1
- data/db/default/spree/countries.rb +10 -4
- data/db/default/spree/states.rb +42 -5
- data/db/default/spree/stores.rb +18 -13
- data/db/default/spree/zones.rb +5 -2
- data/db/migrate/20130326175857_add_stock_location_to_rma.rb +1 -1
- data/db/migrate/20200610113542_add_label_to_spree_addresses.rb +5 -0
- data/db/migrate/20201006110150_add_checkout_zone_field_to_store.rb +12 -0
- data/db/migrate/20201012091259_add_filterable_column_to_spree_option_types.rb +6 -0
- data/db/migrate/20201013084504_add_seo_robots_to_spree_stores.rb +5 -0
- data/db/migrate/20201127084048_add_default_country_kind_to_spree_zones.rb +5 -0
- data/db/migrate/20210112193440_remove_contact_email_from_spree_stores.rb +5 -0
- data/db/migrate/20210114182625_create_spree_payment_methods_stores.rb +10 -0
- data/db/migrate/20210114220232_migrate_data_payment_methods_stores.rb +15 -0
- data/db/migrate/20210117112551_remove_store_id_from_spree_payment_methods.rb +5 -0
- data/db/migrate/20210120142527_ensure_default_locale_in_spree_stores.rb +5 -0
- data/lib/generators/spree/install/templates/config/spree_storefront.yml +9 -9
- data/lib/spree/core.rb +3 -1
- data/lib/spree/core/controller_helpers/auth.rb +3 -1
- data/lib/spree/core/controller_helpers/common.rb +6 -8
- data/lib/spree/core/controller_helpers/currency.rb +45 -0
- data/lib/spree/core/controller_helpers/locale.rb +57 -0
- data/lib/spree/core/controller_helpers/order.rb +9 -4
- data/lib/spree/core/controller_helpers/store.rb +4 -16
- data/lib/spree/core/importer/order.rb +9 -9
- data/lib/spree/core/product_filters.rb +3 -3
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/i18n.rb +7 -21
- data/lib/spree/permitted_attributes.rb +3 -3
- data/lib/spree/service_module.rb +6 -2
- data/lib/spree/testing_support/capybara_config.rb +1 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +29 -17
- data/lib/spree/testing_support/factories/shipment_factory.rb +7 -9
- data/lib/spree/testing_support/factories/stock_location_factory.rb +2 -2
- data/lib/spree/testing_support/factories/zone_factory.rb +16 -13
- data/lib/spree/testing_support/i18n.rb +1 -1
- data/lib/spree/testing_support/order_walkthrough.rb +8 -3
- data/lib/spree/testing_support/rspec_retry_config.rb +10 -0
- data/spree_core.gemspec +7 -5
- metadata +90 -28
- data/lib/spree/core/controller_helpers/currency_helpers.rb +0 -15
- data/lib/spree/i18n/base.rb +0 -17
- data/lib/spree/i18n/initializer.rb +0 -1
data/config/routes.rb
CHANGED
@@ -1,18 +1,24 @@
|
|
1
1
|
require 'carmen'
|
2
2
|
|
3
|
+
EXCLUDED_COUNTRIES = ['AQ', 'AX', 'GS', 'UM', 'HM', 'IO', 'EH', 'BV', 'TF'].freeze
|
4
|
+
|
3
5
|
Carmen::Country.all.each do |country|
|
6
|
+
# Skip the creation of some territories, uninhabited islands and the Antarctic.
|
7
|
+
next if EXCLUDED_COUNTRIES.include?(country.alpha_2_code)
|
8
|
+
|
4
9
|
Spree::Country.where(
|
5
10
|
name: country.name,
|
6
11
|
iso3: country.alpha_3_code,
|
7
12
|
iso: country.alpha_2_code,
|
8
13
|
iso_name: country.name.upcase,
|
9
|
-
numcode: country.numeric_code
|
10
|
-
states_required: country.subregions?
|
14
|
+
numcode: country.numeric_code
|
11
15
|
).first_or_create
|
12
16
|
end
|
13
17
|
|
14
18
|
Spree::Config[:default_country_id] = Spree::Country.find_by(iso: 'US').id
|
15
19
|
|
16
|
-
#
|
17
|
-
|
20
|
+
# Find countries that do not use postal codes (by iso) and set 'zipcode_required' to false for them.
|
18
21
|
Spree::Country.where(iso: Spree::Address::NO_ZIPCODE_ISO_CODES).update_all(zipcode_required: false)
|
22
|
+
|
23
|
+
# Find all countries that require a state (province) at checkout and set 'states_required' to true.
|
24
|
+
Spree::Country.where(iso: Spree::Address::STATES_REQUIRED).update_all(states_required: true)
|
data/db/default/spree/states.rb
CHANGED
@@ -1,12 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
EXCLUDED_US_STATES = ['UM', 'AS', 'MP', 'VI', 'PR', 'GU'].freeze
|
4
|
+
EXCLUDED_CN_STATES = ['HK', 'MO', 'TW'].freeze
|
5
|
+
|
6
|
+
def state_level(country, subregion)
|
7
|
+
country.states.where(
|
8
|
+
name: subregion.name,
|
9
|
+
abbr: subregion.code
|
10
|
+
).first_or_create
|
11
|
+
end
|
12
|
+
|
13
|
+
def province_level(country, subregion)
|
14
|
+
subregion.subregions.each do |province|
|
15
|
+
country.states.where(
|
16
|
+
name: province.name,
|
17
|
+
abbr: province.code
|
18
|
+
).first_or_create
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
1
22
|
Spree::Country.where(states_required: true).each do |country|
|
2
23
|
carmen_country = Carmen::Country.named(country.name)
|
3
24
|
next unless carmen_country
|
4
25
|
|
5
26
|
carmen_country.subregions.each do |subregion|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
27
|
+
if carmen_country.alpha_2_code == 'US'
|
28
|
+
# Produces 50 states, one postal district (Washington DC)
|
29
|
+
# and 3 APO's as you would expect to see on any good U.S. states list.
|
30
|
+
next if EXCLUDED_US_STATES.include?(subregion.code)
|
31
|
+
|
32
|
+
state_level(country, subregion)
|
33
|
+
elsif carmen_country.alpha_2_code == 'CA' || carmen_country.alpha_2_code == 'MX'
|
34
|
+
# Force Canada and Mexico to use state-level data import from Carmen Gem
|
35
|
+
# else we pull in a subset of provinces that are not common at checkout.
|
36
|
+
state_level(country, subregion)
|
37
|
+
elsif carmen_country.alpha_2_code == 'CN'
|
38
|
+
# Removes 3 "States" from that list that are also listed as Countries,
|
39
|
+
# Hong Kong, Taiwan and Macao
|
40
|
+
next if EXCLUDED_CN_STATES.include?(subregion.code)
|
41
|
+
|
42
|
+
state_level(country, subregion)
|
43
|
+
elsif subregion.subregions?
|
44
|
+
province_level(country, subregion)
|
45
|
+
else
|
46
|
+
state_level(country, subregion)
|
47
|
+
end
|
11
48
|
end
|
12
49
|
end
|
data/db/default/spree/stores.rb
CHANGED
@@ -1,16 +1,21 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
default_store = Spree::Store.default
|
2
|
+
|
3
|
+
if default_store.persisted?
|
4
|
+
default_store.update!(default_country_id: Spree::Config[:default_country_id])
|
5
|
+
else
|
3
6
|
Spree::Store.new do |s|
|
4
|
-
s.name
|
5
|
-
s.code
|
6
|
-
s.url
|
7
|
-
s.mail_from_address
|
8
|
-
s.customer_support_email
|
9
|
-
s.default_currency
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
s.
|
7
|
+
s.name = 'Spree Demo Site'
|
8
|
+
s.code = 'spree'
|
9
|
+
s.url = Rails.application.routes.default_url_options[:host] || 'demo.spreecommerce.org'
|
10
|
+
s.mail_from_address = 'no-reply@example.com'
|
11
|
+
s.customer_support_email = 'support@example.com'
|
12
|
+
s.default_currency = 'USD'
|
13
|
+
s.default_country_id = Spree::Config[:default_country_id]
|
14
|
+
s.default_locale = I18n.locale
|
15
|
+
s.seo_title = 'Spree Commerce Demo Shop'
|
16
|
+
s.meta_description = 'This is the new Spree UX DEMO | OVERVIEW: http://bit.ly/new-spree-ux | DOCS: http://bit.ly/spree-ux-customization-docs | CONTACT: https://spreecommerce.org/contact/'
|
17
|
+
s.facebook = 'spreecommerce'
|
18
|
+
s.twitter = 'spreecommerce'
|
19
|
+
s.instagram = 'spreecommerce'
|
15
20
|
end.save!
|
16
21
|
end
|
data/db/default/spree/zones.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
eu_vat = Spree::Zone.where(name: 'EU_VAT', description: 'Countries that make up the EU VAT zone.', kind: 'country').first_or_create!
|
2
|
+
uk_vat = Spree::Zone.where(name: 'UK_VAT', kind: 'country').first_or_create!
|
2
3
|
north_america = Spree::Zone.where(name: 'North America', description: 'USA + Canada', kind: 'country').first_or_create!
|
3
4
|
south_america = Spree::Zone.where(name: 'South America', description: 'South America', kind: 'country').first_or_create!
|
4
5
|
middle_east = Spree::Zone.where(name: 'Middle East', description: 'Middle East', kind: 'country').first_or_create!
|
5
6
|
asia = Spree::Zone.where(name: 'Asia', description: 'Asia', kind: 'country').first_or_create!
|
6
7
|
|
7
|
-
%w(PL FI PT RO DE FR SK HU SI IE AT ES IT BE SE LV BG
|
8
|
+
%w(PL FI PT RO DE FR SK HU SI IE AT ES IT BE SE LV BG LT CY LU MT DK NL EE HR CZ GR).each do |name|
|
8
9
|
eu_vat.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
|
9
10
|
end
|
10
11
|
|
12
|
+
uk_vat.zone_members.where(zoneable: Spree::Country.find_by(iso: 'GB')).first_or_create!
|
13
|
+
|
11
14
|
%w(US CA).each do |name|
|
12
15
|
north_america.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
|
13
16
|
end
|
@@ -16,7 +19,7 @@ end
|
|
16
19
|
middle_east.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
|
17
20
|
end
|
18
21
|
|
19
|
-
%w(AF AM AZ BH BD BT BN KH CN CX CC
|
22
|
+
%w(AF AM AZ BH BD BT BN KH CN CX CC GE HK IN ID IR IQ IL JP JO KZ KW KG LA LB MO MY MV MN MM NP
|
20
23
|
KP OM PK PS PH QA SA SG KR LK SY TW TJ TH TR TM AE UZ VN YE).each do |name|
|
21
24
|
asia.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
|
22
25
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class AddCheckoutZoneFieldToStore < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
unless column_exists?(:spree_stores, :checkout_zone_id)
|
4
|
+
add_column :spree_stores, :checkout_zone_id, :integer
|
5
|
+
|
6
|
+
Spree::Store.reset_column_information
|
7
|
+
|
8
|
+
default_zone = Spree::Zone.default_checkout_zone
|
9
|
+
Spree::Store.update_all(checkout_zone_id: default_zone.id) if default_zone.present?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class CreateSpreePaymentMethodsStores < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :spree_payment_methods_stores, id: false do |t|
|
4
|
+
t.belongs_to :payment_method
|
5
|
+
t.belongs_to :store
|
6
|
+
end
|
7
|
+
|
8
|
+
add_index :spree_payment_methods_stores, [:payment_method_id, :store_id], unique: true, name: 'payment_mentod_id_store_id_unique_index'
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class MigrateDataPaymentMethodsStores < ActiveRecord::Migration[6.0]
|
2
|
+
def up
|
3
|
+
Spree::PaymentMethod.all.each do |payment_method|
|
4
|
+
next if payment_method.store_ids.any?
|
5
|
+
|
6
|
+
if payment_method[:store_id].present?
|
7
|
+
payment_method.store_ids = payment_method[:store_id]
|
8
|
+
else
|
9
|
+
payment_method.store_ids = Spree::Store.ids
|
10
|
+
end
|
11
|
+
|
12
|
+
payment_method.save
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -18,12 +18,12 @@ default:
|
|
18
18
|
:url: /t/women/jackets-and-coats
|
19
19
|
promo_banners:
|
20
20
|
- subtitle: New collection
|
21
|
-
title: Summer
|
22
|
-
url: /t/new-collection/summer-
|
21
|
+
title: Summer 2021
|
22
|
+
url: /t/new-collection/summer-2021
|
23
23
|
image: 'meganav/promo_banner_left-first-category.jpg'
|
24
24
|
- subtitle: Special Offers
|
25
25
|
title: Get up to 30% off
|
26
|
-
url: /t/special-offers/30-off
|
26
|
+
url: /t/special-offers/30-percent-off
|
27
27
|
image: 'meganav/promo_banner_right-first-category.jpg'
|
28
28
|
- title: Men
|
29
29
|
subtitle: Categories
|
@@ -39,12 +39,12 @@ default:
|
|
39
39
|
:url: /t/men/jackets-and-coats
|
40
40
|
promo_banners:
|
41
41
|
- subtitle: New collection
|
42
|
-
title: Summer
|
43
|
-
url: /t/new-collection/summer-
|
42
|
+
title: Summer 2021
|
43
|
+
url: /t/new-collection/summer-2021
|
44
44
|
image: 'meganav/promo_banner_left-second-category.jpg'
|
45
45
|
- subtitle: Special Offers
|
46
46
|
title: Get up to 30% off
|
47
|
-
url: /t/special-offers/30-off
|
47
|
+
url: /t/special-offers/30-percent-off
|
48
48
|
image: 'meganav/promo_banner_right-second-category.jpg'
|
49
49
|
- title: Sportswear
|
50
50
|
subtitle: Categories
|
@@ -58,10 +58,10 @@ default:
|
|
58
58
|
:url: /t/sportswear/pants
|
59
59
|
promo_banners:
|
60
60
|
- subtitle: New collection
|
61
|
-
title: Summer
|
62
|
-
url: /t/new-collection/summer-
|
61
|
+
title: Summer 2021
|
62
|
+
url: /t/new-collection/summer-2021
|
63
63
|
image: 'meganav/promo_banner_left-third-category.jpg'
|
64
64
|
- subtitle: Special Offers
|
65
65
|
title: Get up to 30% off
|
66
|
-
url: /t/special-offers/30-off
|
66
|
+
url: /t/special-offers/30-percent-off
|
67
67
|
image: 'meganav/promo_banner_right-third-category.jpg'
|
data/lib/spree/core.rb
CHANGED
@@ -13,6 +13,7 @@ require 'premailer/rails'
|
|
13
13
|
require 'ransack'
|
14
14
|
require 'responders'
|
15
15
|
require 'state_machines-activerecord'
|
16
|
+
require 'active_storage_validations'
|
16
17
|
|
17
18
|
# This is required because ActiveModel::Validations#invalid? conflicts with the
|
18
19
|
# invalid state of a Payment. In the future this should be removed.
|
@@ -104,4 +105,5 @@ require 'spree/core/controller_helpers/order'
|
|
104
105
|
require 'spree/core/controller_helpers/search'
|
105
106
|
require 'spree/core/controller_helpers/store'
|
106
107
|
require 'spree/core/controller_helpers/strong_parameters'
|
107
|
-
require 'spree/core/controller_helpers/
|
108
|
+
require 'spree/core/controller_helpers/locale'
|
109
|
+
require 'spree/core/controller_helpers/currency'
|
@@ -76,7 +76,9 @@ module Spree
|
|
76
76
|
redirect_to spree.forbidden_path
|
77
77
|
else
|
78
78
|
store_location
|
79
|
-
if
|
79
|
+
if request.fullpath.match(Spree.admin_path) && defined?(spree.admin_login_path)
|
80
|
+
redirect_to spree.admin_login_path
|
81
|
+
elsif respond_to?(:spree_login_path)
|
80
82
|
redirect_to spree_login_path
|
81
83
|
elsif spree.respond_to?(:root_path)
|
82
84
|
redirect_to spree.root_path
|
@@ -10,8 +10,6 @@ module Spree
|
|
10
10
|
|
11
11
|
layout :get_layout
|
12
12
|
|
13
|
-
before_action :set_user_language
|
14
|
-
|
15
13
|
protected
|
16
14
|
|
17
15
|
# can be used in views as well as controllers.
|
@@ -43,12 +41,12 @@ module Spree
|
|
43
41
|
private
|
44
42
|
|
45
43
|
def set_user_language
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
44
|
+
ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
|
45
|
+
ControllerHelpers::Common#set_user_language is deprecated and will be removed in Spree 5.0.
|
46
|
+
Please use `before_action :set_locale` instead
|
47
|
+
DEPRECATION
|
48
|
+
|
49
|
+
set_locale
|
52
50
|
end
|
53
51
|
|
54
52
|
# Returns which layout to render.
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Spree
|
2
|
+
module Core
|
3
|
+
module ControllerHelpers
|
4
|
+
module Currency
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
helper_method :supported_currencies
|
9
|
+
helper_method :supported_currencies_for_all_stores
|
10
|
+
helper_method :current_currency
|
11
|
+
helper_method :supported_currency?
|
12
|
+
end
|
13
|
+
|
14
|
+
def current_currency
|
15
|
+
# session support was previously in SpreeMultiCurrency so we would like
|
16
|
+
# to keep it for now
|
17
|
+
@current_currency ||= if defined?(session) && session.key?(:currency) && supported_currency?(session[:currency])
|
18
|
+
session[:currency]
|
19
|
+
elsif params[:currency].present? && supported_currency?(params[:currency])
|
20
|
+
params[:currency]
|
21
|
+
else
|
22
|
+
current_store.default_currency
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def supported_currencies
|
27
|
+
@supported_currencies ||= current_store.supported_currencies_list
|
28
|
+
end
|
29
|
+
|
30
|
+
def supported_currencies_for_all_stores
|
31
|
+
@supported_currencies_for_all_stores ||= begin
|
32
|
+
(
|
33
|
+
Spree::Store.pluck(:supported_currencies).map { |c| c&.split(',') }.flatten + Spree::Store.pluck(:default_currency)
|
34
|
+
).
|
35
|
+
compact.uniq.map { |code| ::Money::Currency.find(code.strip) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def supported_currency?(currency_iso_code)
|
40
|
+
supported_currencies.map(&:iso_code).include?(currency_iso_code)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Spree
|
2
|
+
module Core
|
3
|
+
module ControllerHelpers
|
4
|
+
module Locale
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
before_action :set_locale
|
9
|
+
|
10
|
+
helper_method :supported_locales
|
11
|
+
helper_method :supported_locales_for_all_stores
|
12
|
+
helper_method :current_locale
|
13
|
+
helper_method :supported_locale?
|
14
|
+
helper_method :available_locales
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_locale
|
18
|
+
I18n.locale = current_locale
|
19
|
+
end
|
20
|
+
|
21
|
+
def current_locale
|
22
|
+
# session support was previously in SpreeI18n so we would like to keep it for now
|
23
|
+
# for easer upgrade
|
24
|
+
@current_locale ||= if defined?(session) && session.key?(:locale) && supported_locale?(session[:locale])
|
25
|
+
session[:locale]
|
26
|
+
elsif params[:locale].present? && supported_locale?(params[:locale])
|
27
|
+
params[:locale]
|
28
|
+
elsif respond_to?(:config_locale, true) && config_locale.present?
|
29
|
+
config_locale
|
30
|
+
else
|
31
|
+
current_store.default_locale || Rails.application.config.i18n.default_locale || I18n.default_locale
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def supported_locales
|
36
|
+
@supported_locales ||= current_store.supported_locales_list
|
37
|
+
end
|
38
|
+
|
39
|
+
def supported_locale?(locale_code)
|
40
|
+
supported_locales.include?(locale_code&.to_s)
|
41
|
+
end
|
42
|
+
|
43
|
+
def supported_locales_for_all_stores
|
44
|
+
@supported_locales_for_all_stores ||= (if defined?(SpreeI18n)
|
45
|
+
(SpreeI18n::Locale.all << :en).map(&:to_s)
|
46
|
+
else
|
47
|
+
[Rails.application.config.i18n.default_locale, I18n.locale, :en]
|
48
|
+
end).uniq.compact
|
49
|
+
end
|
50
|
+
|
51
|
+
def available_locales
|
52
|
+
Spree::Store.available_locales
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|