spree_core 4.2.0.rc3 → 4.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/spree.js +19 -0
  3. data/app/controllers/spree/base_controller.rb +2 -1
  4. data/app/controllers/spree/errors_controller.rb +11 -0
  5. data/app/finders/spree/orders/find_current.rb +1 -1
  6. data/app/finders/spree/products/find.rb +14 -3
  7. data/app/helpers/spree/base_helper.rb +2 -1
  8. data/app/helpers/spree/currency_helper.rb +34 -0
  9. data/app/helpers/spree/locale_helper.rb +31 -0
  10. data/app/helpers/spree/products_helper.rb +37 -12
  11. data/app/models/concerns/spree/product_scopes.rb +1 -1
  12. data/app/models/concerns/spree/user_payment_source.rb +1 -1
  13. data/app/models/spree/ability.rb +45 -30
  14. data/app/models/spree/app_configuration.rb +2 -2
  15. data/app/models/spree/app_dependencies.rb +3 -1
  16. data/app/models/spree/credit_card.rb +4 -0
  17. data/app/models/spree/image.rb +14 -14
  18. data/app/models/spree/line_item.rb +6 -9
  19. data/app/models/spree/price.rb +1 -1
  20. data/app/models/spree/product.rb +29 -15
  21. data/app/models/spree/promotion/rules/option_value.rb +1 -1
  22. data/app/models/spree/store.rb +38 -9
  23. data/app/models/spree/variant.rb +8 -8
  24. data/app/paginators/spree/shared/paginate.rb +8 -1
  25. data/app/presenters/spree/variant_presenter.rb +2 -5
  26. data/app/services/spree/build_localized_redirect_url.rb +101 -0
  27. data/app/services/spree/cart/estimate_shipping_rates.rb +1 -1
  28. data/app/views/spree/errors/forbidden.html.erb +0 -0
  29. data/app/views/spree/errors/unauthorized.html.erb +0 -0
  30. data/app/views/spree/shared/_base_mailer_stylesheets.html.erb +13 -2
  31. data/app/views/spree/shared/_purchased_items_table.html.erb +15 -6
  32. data/app/views/spree/shared/purchased_items_table/_adjustment.html.erb +2 -2
  33. data/app/views/spree/shared/purchased_items_table/_line_item.html.erb +2 -2
  34. data/config/locales/en.yml +8 -54
  35. data/config/routes.rb +2 -1
  36. data/db/default/spree/stores.rb +1 -0
  37. data/db/default/spree/zones.rb +4 -1
  38. data/db/migrate/20191017121054_add_supported_currencies_to_store.rb +1 -0
  39. data/db/migrate/20201012091259_add_filterable_column_to_spree_option_types.rb +6 -2
  40. data/db/migrate/20210120142527_ensure_default_locale_in_spree_stores.rb +5 -0
  41. data/db/migrate/20210205211040_add_supported_locales_to_spree_stores.rb +11 -0
  42. data/db/migrate/20210215202602_migrate_spree_i18n_globalize_config.rb +22 -0
  43. data/lib/generators/spree/install/install_generator.rb +9 -6
  44. data/lib/spree/core.rb +2 -1
  45. data/lib/spree/core/controller_helpers/auth.rb +3 -1
  46. data/lib/spree/core/controller_helpers/common.rb +6 -8
  47. data/lib/spree/core/controller_helpers/currency.rb +54 -0
  48. data/lib/spree/core/controller_helpers/locale.rb +58 -0
  49. data/lib/spree/core/controller_helpers/search.rb +1 -1
  50. data/lib/spree/core/controller_helpers/store.rb +4 -16
  51. data/lib/spree/core/version.rb +3 -1
  52. data/lib/spree/i18n.rb +12 -0
  53. data/lib/spree/permitted_attributes.rb +1 -1
  54. data/lib/spree/service_module.rb +2 -2
  55. data/lib/spree/testing_support/common_rake.rb +1 -1
  56. data/lib/spree/testing_support/controller_requests.rb +10 -10
  57. data/lib/spree/testing_support/factories/stock_location_factory.rb +2 -2
  58. data/lib/spree/testing_support/factories/store_factory.rb +1 -0
  59. data/lib/spree/testing_support/flatpickr_capybara.rb +101 -0
  60. data/lib/spree/testing_support/locale_helpers.rb +78 -0
  61. data/lib/spree/testing_support/next_instance_of.rb +38 -0
  62. data/spree_core.gemspec +1 -1
  63. metadata +20 -9
  64. data/lib/generators/spree/install/templates/config/initializers/spree_storefront.rb +0 -1
  65. data/lib/generators/spree/install/templates/config/spree_storefront.yml +0 -67
  66. data/lib/spree/core/controller_helpers/currency_helpers.rb +0 -15
@@ -8,10 +8,13 @@
8
8
  <td></td>
9
9
  <td>
10
10
  <p class="f-fallback purchase_total purchase_total--label">
11
- <%= Spree.t(:promotion) %> <%= label %>:
11
+ <%= Spree.t(:promotion) %>:
12
+ </p>
13
+ <p class="f-fallback purchase_total--name purchase_total--label">
14
+ <%= label %>
12
15
  </p>
13
16
  </td>
14
- <td>
17
+ <td class="purchase_total-col">
15
18
  <p class="f-fallback purchase_total">
16
19
  <%= Spree::Money.new(adjustments.sum(&:amount), currency: order.currency) %>
17
20
  </p>
@@ -25,10 +28,13 @@
25
28
  <td></td>
26
29
  <td>
27
30
  <p class="f-fallback purchase_total purchase_total--label">
28
- <%= Spree.t(:shipping) %> <%= name %>:
31
+ <%= Spree.t(:shipping) %>:
32
+ </p>
33
+ <p class="f-fallback purchase_total--name purchase_total--label">
34
+ <%= name %>
29
35
  </p>
30
36
  </td>
31
- <td>
37
+ <td class="purchase_total-col">
32
38
  <p class="f-fallback purchase_total">
33
39
  <%= Spree::Money.new(shipments.sum(&:discounted_cost), currency: order.currency) %>
34
40
  </p>
@@ -41,10 +47,13 @@
41
47
  <td></td>
42
48
  <td>
43
49
  <p class="f-fallback purchase_total purchase_total--label">
44
- <%= Spree.t(:tax) %> <%= label %>:
50
+ <%= Spree.t(:tax) %>:
51
+ </p>
52
+ <p class="f-fallback purchase_total--name purchase_total--label">
53
+ <%= label %>
45
54
  </p>
46
55
  </td>
47
- <td>
56
+ <td class="purchase_total-col">
48
57
  <p class="f-fallback purchase_total">
49
58
  <%= Spree::Money.new(adjustments.sum(&:amount), currency: order.currency) %>
50
59
  </p>
@@ -5,9 +5,9 @@
5
5
  <%= raw(adjustment.label) %>:
6
6
  </p>
7
7
  </td>
8
- <td>
8
+ <td class="purchase_total-col">
9
9
  <p class="f-fallback purchase_total">
10
10
  <%= Spree::Money.new(adjustment.amount, currency: order.currency) %>
11
11
  </p>
12
12
  </td>
13
- </tr>
13
+ </tr>
@@ -18,9 +18,9 @@
18
18
  </strong>
19
19
  <p class="purchase_item--additional"><%= raw(line_item.variant.options_text) -%></p>
20
20
  </td>
21
- <td class="align-right">
21
+ <td class="align-right" width="30%">
22
22
  <span class="f-fallback purchase_item_price">
23
- <%= line_item.quantity %> x <%= line_item.single_money %>
23
+ <%= line_item.quantity %> x <%= line_item.single_money %><br>
24
24
  <%= line_item.display_amount %>
25
25
  </span>
26
26
  </td>
@@ -663,7 +663,6 @@ en:
663
663
  jackets_and_coats: JACKET & COASTS
664
664
  new_collection: NEW COLLECTION
665
665
  special_offers: SPECIAL OFFERS
666
- summer_2019: SUMMER 2019
667
666
  channel: Channel
668
667
  charged: Charged
669
668
  checkout: Checkout
@@ -756,42 +755,14 @@ en:
756
755
  new_order_notifications_email: New Order Notifications Email
757
756
  cut: Cut
758
757
  cvv: CVV
758
+ no_cc_type: N/A
759
759
  cvv_response: CVV Response
760
760
  date: Date
761
761
  date_completed: Date Completed
762
762
  date_picker:
763
- am: 'AM'
764
- first_day: 0
765
- format: ! '%Y/%m/%d'
766
- hourAriaLabel: 'Hour'
767
- js_format: Y/m/d
768
- js_date_time: Y/m/d - H:i
769
- minuteAriaLabel: 'Minute'
770
- pm: 'PM'
771
- rangeSeparator: ' to '
772
- scrollTitle: 'Scroll to increment'
773
- toggleTitle: 'Click to toggle'
774
- weekAbbreviation: 'Wk'
775
- yearAriaLabel: 'Year'
776
- sun: 'Sun'
777
- mon: 'Mon'
778
- tue: 'Tue'
779
- wed: 'Wed'
780
- thu: 'Thu'
781
- fri: 'Fri'
782
- sat: 'Sat'
783
- lh_jan: 'January'
784
- lh_feb: 'February'
785
- lh_mar: 'March'
786
- lh_apr: 'April'
787
- lh_may: 'May'
788
- lh_jun: 'June'
789
- lh_jul: 'July'
790
- lh_aug: 'August'
791
- lh_sep: 'September'
792
- lh_oct: 'October'
793
- lh_nov: 'November'
794
- lh_dec: 'December'
763
+ # FlatPickr human friendly formatting
764
+ fpr_human_friendly_date_format: M j, Y
765
+ fpr_human_friendly_date_time_format: M j, Y at H:i
795
766
  date_range: Date Range
796
767
  default: Default
797
768
  default_country_cannot_be_deleted: Default country cannot be deleted
@@ -926,24 +897,6 @@ en:
926
897
  hide_from_subcategories_nav: Hide from subcategories navigation
927
898
  home: Home
928
899
  home_page: homepage
929
- homepage:
930
- bestsellers: BESTSELLERS
931
- fashion_trends: FASHION TRENDS
932
- fashion_trends_note: Want to rock this season’s hottest trend in style? These are the top fashion from Summer 2020 Fashion Weeks that are coming our way this season.
933
- men: MEN
934
- new: NEW
935
- new_collection: NEW COLLECTION
936
- read_more: READ MORE
937
- shoes: SHOES
938
- shop_now: SHOP NOW
939
- sportswear: SPORTSWEAR
940
- streetstyle: STREETSTYLE
941
- summer_2020: Summer 2020
942
- summer_collection: Summer Collection
943
- summer_sale: SUMMER SALE
944
- trending: TRENDING
945
- up_to_60: UP TO 60%
946
- women: WOMEN
947
900
  help_center: Help Center
948
901
  i18n:
949
902
  available_locales: Available Locales
@@ -1582,7 +1535,7 @@ en:
1582
1535
  show_only_considered_risky: Only show risky orders
1583
1536
  show_property: Show Property
1584
1537
  show_rate_in_label: Show rate in label
1585
- show_store_currency_selector:
1538
+ show_store_selector:
1586
1539
  short: Show Store selector
1587
1540
  long: Display the Store selector in the main nav bar of Storefront and allow users to change Store and Currency
1588
1541
  sign_up: Sign Up
@@ -1660,9 +1613,9 @@ en:
1660
1613
  unable_to_delete: Unable to delete store.
1661
1614
  store_form:
1662
1615
  code_help: "Store unique identifier, which is an abbreviated version of the store’s name (used as the layout directory name, and also helpful for separating templates by store)"
1663
- checkout_zone_help: "Selecting a Zone will limit customers on Checkout to Addresses in Countries or States in that Zone.
1616
+ checkout_zone_help: "Selecting zone will limit to which Countries or States products are shipped.
1664
1617
  For more information <a href='https://guides.spreecommerce.org/user/configuration/configuring_geography.html#zones' target='_blank' class='alert-link'>please see documentation</a>"
1665
- languages_help: "Install <a href='https://github.com/spree-contrib/spree_i18n target='_blank' class='alert-link'>Spree I18n extension</a> to add more languages"
1618
+ locales_help: "Install <a href='https://github.com/spree-contrib/spree_i18n' target='_blank' class='alert-link'>Spree I18n extension</a> to add more locales"
1666
1619
  social_help: "If you want to link to your social accounts in the footer part of your website please fill below fields"
1667
1620
  default_country_help: "This is the Country that will be pre-selected on the Checkout Address form"
1668
1621
  footer_help: "This content is visible in the footer section of your Store"
@@ -1719,6 +1672,7 @@ en:
1719
1672
  summary: Summary
1720
1673
  supported_currencies: Supported Currencies
1721
1674
  supported_currencies_long: A comma separated list of supported currencies
1675
+ supported_locales: Supported Locales
1722
1676
  tax: Tax
1723
1677
  tax_included: "Tax (incl.)"
1724
1678
  tax_categories: Tax Categories
data/config/routes.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  Spree::Core::Engine.add_routes do
2
- get '/forbidden', to: 'home#forbidden', as: :forbidden
2
+ get '/forbidden', to: 'errors#forbidden', as: :forbidden
3
+ get '/unauthorized', to: 'errors#unauthorized', as: :unauthorized
3
4
  end
4
5
 
5
6
  Spree::Core::Engine.draw_routes
@@ -11,6 +11,7 @@ else
11
11
  s.customer_support_email = 'support@example.com'
12
12
  s.default_currency = 'USD'
13
13
  s.default_country_id = Spree::Config[:default_country_id]
14
+ s.default_locale = I18n.locale
14
15
  s.seo_title = 'Spree Commerce Demo Shop'
15
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/'
16
17
  s.facebook = 'spreecommerce'
@@ -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 GB LT CY LU MT DK NL EE HR CZ GR).each do |name|
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
@@ -2,6 +2,7 @@ class AddSupportedCurrenciesToStore < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  unless column_exists?(:spree_stores, :supported_currencies)
4
4
  add_column :spree_stores, :supported_currencies, :string
5
+ Spree::Store.reset_column_information
5
6
  Spree::Store.all.each do |store|
6
7
  store.update_attribute(:supported_currencies, store.default_currency)
7
8
  end
@@ -1,6 +1,10 @@
1
1
  class AddFilterableColumnToSpreeOptionTypes < ActiveRecord::Migration[6.0]
2
2
  def change
3
- add_column :spree_option_types, :filterable, :boolean, default: true, null: false
4
- add_index :spree_option_types, :filterable
3
+ unless column_exists?(:spree_option_types, :filterable)
4
+ add_column :spree_option_types, :filterable, :boolean, default: true, null: false
5
+ end
6
+ unless index_exists?(:spree_option_types, :filterable)
7
+ add_index :spree_option_types, :filterable
8
+ end
5
9
  end
6
10
  end
@@ -0,0 +1,5 @@
1
+ class EnsureDefaultLocaleInSpreeStores < ActiveRecord::Migration[6.0]
2
+ def change
3
+ Spree::Store.where(default_locale: nil).update_all(default_locale: I18n.locale)
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ class AddSupportedLocalesToSpreeStores < ActiveRecord::Migration[6.0]
2
+ def change
3
+ unless column_exists?(:spree_stores, :supported_locales)
4
+ add_column :spree_stores, :supported_locales, :string
5
+ Spree::Store.reset_column_information
6
+ Spree::Store.all.each do |store|
7
+ store.update_attribute(:supported_locales, store.default_locale)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ class MigrateSpreeI18nGlobalizeConfig < ActiveRecord::Migration[6.0]
2
+ def up
3
+ locales = []
4
+
5
+ if defined?(SpreeI18n) && defined?(SpreeI18n::Config)
6
+ locales = (locales << SpreeI18n::Config[:available_locales]).flatten.uniq.compact
7
+ end
8
+
9
+ if defined?(SpreeGlobalize) && defined?(SpreeGlobalize::Config)
10
+ locales = (locales << SpreeGlobalize::Config[:supported_locales]).flatten.uniq.compact
11
+ end
12
+
13
+ default_store = Spree::Store.default
14
+ if default_store.supported_locales.blank? || default_store.supported_locales == default_store.default_locale
15
+ locales = (locales << default_store.default_locale).uniq.compact.join(',')
16
+ default_store.update(supported_locales: locales)
17
+ end
18
+ end
19
+
20
+ def down
21
+ end
22
+ end
@@ -10,7 +10,8 @@ module Spree
10
10
  class_option :migrate, type: :boolean, default: true, banner: 'Run Spree migrations'
11
11
  class_option :seed, type: :boolean, default: true, banner: 'load seed data (migrations must be run)'
12
12
  class_option :sample, type: :boolean, default: true, banner: 'load sample data (migrations must be run)'
13
- class_option :copy_storefront, type: :boolean, default: true, banner: 'copy storefront from spree frontend to your application for easy customization'
13
+ class_option :install_storefront, type: :boolean, default: true, banner: 'installs storefront configuration files'
14
+ class_option :copy_storefront, type: :boolean, default: false, banner: 'copy all storefront views and stylesheets'
14
15
  class_option :auto_accept, type: :boolean
15
16
  class_option :user_class, type: :string
16
17
  class_option :admin_email, type: :string
@@ -30,6 +31,7 @@ module Spree
30
31
  @run_migrations = options[:migrate]
31
32
  @load_seed_data = options[:seed]
32
33
  @load_sample_data = options[:sample]
34
+ @install_storefront = options[:install_storefront]
33
35
  @copy_storefront = options[:copy_storefront]
34
36
 
35
37
  unless @run_migrations
@@ -40,11 +42,6 @@ module Spree
40
42
 
41
43
  def add_files
42
44
  template 'config/initializers/spree.rb', 'config/initializers/spree.rb'
43
-
44
- if Spree::Core::Engine.frontend_available? || Rails.env.test?
45
- template 'config/initializers/spree_storefront.rb', 'config/initializers/spree_storefront.rb'
46
- template 'config/spree_storefront.yml', 'config/spree_storefront.yml'
47
- end
48
45
  end
49
46
 
50
47
  def additional_tweaks
@@ -91,6 +88,12 @@ module Spree
91
88
  empty_directory 'app/overrides'
92
89
  end
93
90
 
91
+ def install_storefront
92
+ if @install_storefront && Spree::Core::Engine.frontend_available?
93
+ generate 'spree:frontend:install'
94
+ end
95
+ end
96
+
94
97
  def copy_storefront
95
98
  if @copy_storefront && Spree::Core::Engine.frontend_available?
96
99
  generate 'spree:frontend:copy_storefront'
data/lib/spree/core.rb CHANGED
@@ -105,4 +105,5 @@ require 'spree/core/controller_helpers/order'
105
105
  require 'spree/core/controller_helpers/search'
106
106
  require 'spree/core/controller_helpers/store'
107
107
  require 'spree/core/controller_helpers/strong_parameters'
108
- require 'spree/core/controller_helpers/currency_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 respond_to?(:spree_login_path)
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
- locale = session[:locale]
47
- locale = store_locale if respond_to?(:store_locale, true) && locale.blank?
48
- locale = config_locale if respond_to?(:config_locale, true) && locale.blank?
49
- locale = Rails.application.config.i18n.default_locale if locale.blank?
50
- locale = I18n.default_locale unless I18n.available_locales.map(&:to_s).include?(locale.to_s)
51
- I18n.locale = locale
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,54 @@
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
+ helper_method :currency_param
13
+ end
14
+
15
+ def current_currency
16
+ @current_currency ||= if defined?(session) && session.key?(:currency) && supported_currency?(session[:currency])
17
+ session[:currency]
18
+ elsif params[:currency].present? && supported_currency?(params[:currency])
19
+ params[:currency]
20
+ elsif current_store.present?
21
+ current_store.default_currency
22
+ else
23
+ Spree::Config[:currency]
24
+ end&.upcase
25
+ end
26
+
27
+ def supported_currencies
28
+ @supported_currencies ||= current_store&.supported_currencies_list
29
+ end
30
+
31
+ def supported_currencies_for_all_stores
32
+ @supported_currencies_for_all_stores ||= begin
33
+ (
34
+ Spree::Store.pluck(:supported_currencies).map { |c| c&.split(',') }.flatten + Spree::Store.pluck(:default_currency)
35
+ ).
36
+ compact.uniq.map { |code| ::Money::Currency.find(code.strip) }
37
+ end
38
+ end
39
+
40
+ def supported_currency?(currency_iso_code)
41
+ return false if supported_currencies.nil?
42
+
43
+ supported_currencies.map(&:iso_code).include?(currency_iso_code.upcase)
44
+ end
45
+
46
+ def currency_param
47
+ return if current_currency == current_store.default_currency
48
+
49
+ current_currency
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,58 @@
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
+ helper_method :locale_param
16
+ end
17
+
18
+ def set_locale
19
+ I18n.locale = current_locale
20
+ end
21
+
22
+ def current_locale
23
+ @current_locale ||= if params[:locale].present? && supported_locale?(params[:locale])
24
+ params[:locale]
25
+ elsif respond_to?(:config_locale, true) && config_locale.present?
26
+ config_locale
27
+ else
28
+ current_store&.default_locale || Rails.application.config.i18n.default_locale || I18n.default_locale
29
+ end
30
+ end
31
+
32
+ def supported_locales
33
+ @supported_locales ||= current_store&.supported_locales_list
34
+ end
35
+
36
+ def supported_locale?(locale_code)
37
+ return false if supported_locales.nil?
38
+
39
+ supported_locales.include?(locale_code&.to_s)
40
+ end
41
+
42
+ def supported_locales_for_all_stores
43
+ @supported_locales_for_all_stores ||= Spree.available_locales
44
+ end
45
+
46
+ def available_locales
47
+ Spree::Store.available_locales
48
+ end
49
+
50
+ def locale_param
51
+ return if I18n.locale.to_s == current_store.default_locale || current_store.default_locale.nil?
52
+
53
+ I18n.locale.to_s
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end