spree_core 4.7.2 → 4.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/app/finders/spree/taxons/find.rb +7 -3
  4. data/app/models/concerns/spree/named_type.rb +1 -1
  5. data/app/models/concerns/spree/product_scopes.rb +19 -19
  6. data/app/models/concerns/spree/user_address.rb +4 -2
  7. data/app/models/spree/address.rb +2 -21
  8. data/app/models/spree/asset.rb +2 -2
  9. data/app/models/spree/calculator/default_tax.rb +1 -1
  10. data/app/models/spree/cms_page.rb +3 -3
  11. data/app/models/spree/cms_section.rb +1 -1
  12. data/app/models/spree/country.rb +0 -26
  13. data/app/models/spree/credit_card.rb +5 -3
  14. data/app/models/spree/customer_return.rb +3 -3
  15. data/app/models/spree/digital.rb +1 -1
  16. data/app/models/spree/digital_link.rb +1 -1
  17. data/app/models/spree/image.rb +2 -2
  18. data/app/models/spree/inventory_unit.rb +1 -1
  19. data/app/models/spree/legacy_user.rb +3 -3
  20. data/app/models/spree/line_item.rb +2 -2
  21. data/app/models/spree/menu.rb +2 -2
  22. data/app/models/spree/menu_item.rb +1 -1
  23. data/app/models/spree/option_type.rb +6 -6
  24. data/app/models/spree/option_value.rb +5 -5
  25. data/app/models/spree/order.rb +9 -7
  26. data/app/models/spree/payment.rb +4 -4
  27. data/app/models/spree/payment_capture_event.rb +1 -1
  28. data/app/models/spree/payment_method.rb +1 -1
  29. data/app/models/spree/payment_source.rb +1 -1
  30. data/app/models/spree/price.rb +4 -2
  31. data/app/models/spree/product.rb +30 -19
  32. data/app/models/spree/product_property.rb +5 -3
  33. data/app/models/spree/promotion.rb +3 -3
  34. data/app/models/spree/property.rb +8 -6
  35. data/app/models/spree/prototype.rb +2 -2
  36. data/app/models/spree/refund.rb +2 -2
  37. data/app/models/spree/reimbursement.rb +2 -2
  38. data/app/models/spree/return_authorization.rb +2 -2
  39. data/app/models/spree/return_item.rb +1 -1
  40. data/app/models/spree/role.rb +1 -1
  41. data/app/models/spree/shipment.rb +4 -4
  42. data/app/models/spree/shipping_category.rb +2 -2
  43. data/app/models/spree/shipping_method.rb +2 -2
  44. data/app/models/spree/stock/estimator.rb +1 -1
  45. data/app/models/spree/stock_item.rb +3 -3
  46. data/app/models/spree/stock_location.rb +7 -2
  47. data/app/models/spree/stock_movement.rb +1 -1
  48. data/app/models/spree/stock_transfer.rb +4 -4
  49. data/app/models/spree/store.rb +3 -5
  50. data/app/models/spree/store_credit.rb +3 -3
  51. data/app/models/spree/store_favicon_image.rb +11 -2
  52. data/app/models/spree/tax_category.rb +1 -1
  53. data/app/models/spree/tax_rate.rb +1 -1
  54. data/app/models/spree/taxon.rb +23 -7
  55. data/app/models/spree/taxon_image.rb +2 -2
  56. data/app/models/spree/taxonomy.rb +5 -5
  57. data/app/models/spree/variant.rb +11 -6
  58. data/app/models/spree/wished_item.rb +1 -1
  59. data/app/models/spree/wishlist.rb +2 -2
  60. data/app/models/spree/zone.rb +2 -2
  61. data/app/services/spree/addresses/update.rb +1 -0
  62. data/app/services/spree/seeds/all.rb +15 -13
  63. data/app/services/spree/seeds/stores.rb +2 -2
  64. data/app/sorters/spree/products/sort.rb +1 -1
  65. data/config/initializers/mobility.rb +1 -0
  66. data/config/routes.rb +7 -8
  67. data/db/migrate/20210929090344_create_stock_item_stock_location_id_variant_id_coalesce_deleted_at_unique_index.rb +1 -28
  68. data/db/migrate/20230103144439_create_option_type_translations.rb +0 -1
  69. data/db/migrate/20230103151034_create_option_value_translations.rb +0 -1
  70. data/db/migrate/20230109084253_create_product_property_translations.rb +0 -1
  71. data/db/migrate/20230109105943_create_property_translations.rb +0 -2
  72. data/db/migrate/20230110142344_backfill_friendly_id_slug_locale.rb +2 -8
  73. data/db/migrate/20240303174340_fix_spree_stock_item_unique_index.rb +35 -0
  74. data/db/migrate/20240514105216_add_weight_and_dimension_units_to_spree_variants.rb +6 -0
  75. data/lib/generators/spree/custom_authentication/custom_authentication_generator.rb +23 -0
  76. data/lib/generators/spree/{custom_user → custom_authentication}/templates/authentication_helpers.rb.tt +1 -14
  77. data/lib/generators/spree/custom_user/custom_user_generator.rb +3 -8
  78. data/lib/generators/spree/custom_user/templates/current_user_helpers.rb.tt +15 -0
  79. data/lib/generators/spree/custom_user/templates/migration.rb.tt +2 -2
  80. data/lib/generators/spree/dummy/dummy_generator.rb +1 -6
  81. data/lib/generators/spree/dummy/templates/rails/database.yml +19 -21
  82. data/lib/generators/spree/dummy/templates/rails/test.rb +1 -1
  83. data/lib/generators/spree/install/templates/config/initializers/spree.rb +25 -0
  84. data/lib/spree/core/configuration.rb +11 -25
  85. data/lib/spree/core/controller_helpers/locale.rb +5 -1
  86. data/lib/spree/core/engine.rb +4 -1
  87. data/lib/spree/core/preferences/runtime_configuration.rb +43 -0
  88. data/lib/spree/core/product_duplicator.rb +2 -0
  89. data/lib/spree/core/product_filters.rb +9 -2
  90. data/lib/spree/core/runtime_configuration.rb +9 -0
  91. data/lib/spree/core/version.rb +1 -1
  92. data/lib/spree/core/webhooks.rb +13 -0
  93. data/lib/spree/core.rb +7 -0
  94. data/lib/spree/money.rb +38 -5
  95. data/lib/spree/testing_support/authorization_helpers.rb +3 -1
  96. data/lib/spree/testing_support/common_rake.rb +7 -18
  97. data/spree_core.gemspec +7 -7
  98. metadata +47 -50
  99. data/db/migrate/20220715120222_change_product_name_null_to_true.rb +0 -5
  100. data/db/migrate/20220718100948_change_taxon_name_null_to_true.rb +0 -5
  101. data/db/migrate/20220804073928_transfer_data_to_translatable_tables.rb +0 -66
  102. data/db/migrate/20230109094907_transfer_options_data_to_translatable_tables.rb +0 -58
  103. data/db/migrate/20230109110840_transfer_property_data_to_translatable_tables.rb +0 -59
  104. data/db/migrate/20230111122511_transfer_product_and_taxon_data_to_translatable_tables.rb +0 -82
  105. data/db/migrate/20230117120430_allow_null_taxonomy_name.rb +0 -5
  106. data/db/migrate/20230117121303_transfer_taxonomy_data_to_translatable_tables.rb +0 -11
  107. data/db/migrate/20230210142849_transfer_store_data_to_translatable_tables.rb +0 -11
  108. data/db/migrate/20230514162157_add_index_on_locale_and_permalink_to_spree_taxons.rb +0 -5
@@ -9,7 +9,6 @@ class CreateOptionValueTranslations < ActiveRecord::Migration[6.1]
9
9
  create_table :spree_option_value_translations do |t|
10
10
 
11
11
  # Translated attribute(s)
12
- t.string :name
13
12
  t.string :presentation
14
13
 
15
14
  t.string :locale, null: false
@@ -9,7 +9,6 @@ class CreateProductPropertyTranslations < ActiveRecord::Migration[6.1]
9
9
  create_table :spree_product_property_translations do |t|
10
10
  # Translated attribute(s)
11
11
  t.string :value
12
- t.string :filter_param
13
12
 
14
13
  t.string :locale, null: false
15
14
  t.references :spree_product_property, null: false, foreign_key: true, index: false
@@ -8,9 +8,7 @@ class CreatePropertyTranslations < ActiveRecord::Migration[6.1]
8
8
  else
9
9
  create_table :spree_property_translations do |t|
10
10
  # Translated attribute(s)
11
- t.string :name
12
11
  t.string :presentation
13
- t.string :filter_param
14
12
 
15
13
  t.string :locale, null: false
16
14
  t.references :spree_property, null: false, foreign_key: true, index: false
@@ -1,15 +1,9 @@
1
1
  class BackfillFriendlyIdSlugLocale < ActiveRecord::Migration[6.1]
2
- DEFAULT_LOCALE = 'en'
3
-
4
2
  def up
5
- ActiveRecord::Base.connection.execute("
6
- UPDATE friendly_id_slugs SET locale = '#{DEFAULT_LOCALE}'
7
- ")
3
+ FriendlyId::Slug.unscoped.update_all(locale: Spree::Store.default.default_locale)
8
4
  end
9
5
 
10
6
  def down
11
- ActiveRecord::Base.connection.execute("
12
- UPDATE friendly_id_slugs SET locale = NULL
13
- ")
7
+ FriendlyId::Slug.unscoped.update_all(locale: nil)
14
8
  end
15
9
  end
@@ -0,0 +1,35 @@
1
+ class FixSpreeStockItemUniqueIndex < ActiveRecord::Migration[6.1]
2
+ def change
3
+ remove_index :spree_stock_items, name: 'stock_item_by_loc_var_id_deleted_at' if index_exists?(:spree_stock_items, [:stock_location_id, :variant_id], name: 'stock_item_by_loc_var_id_deleted_at')
4
+
5
+ unless index_exists?(:spree_stock_items, ['variant_id', 'stock_location_id'], name: 'index_spree_stock_items_unique_without_deleted_at')
6
+ # MySQL doesn't support partial indexes
7
+ if ActiveRecord::Base.connection.adapter_name == 'Mysql2'
8
+ reversible do |dir|
9
+ dir.up do
10
+ execute <<-SQL
11
+ CREATE UNIQUE INDEX index_spree_stock_items_unique_without_deleted_at
12
+ ON spree_stock_items(
13
+ stock_location_id,
14
+ variant_id,
15
+ (COALESCE(deleted_at, CAST('1970-01-01' AS DATETIME)))
16
+ );
17
+ SQL
18
+ end
19
+
20
+ dir.down do
21
+ remove_index :spree_stock_items, name: :index_spree_stock_items_unique_without_deleted_at
22
+ end
23
+ end
24
+ else
25
+ add_index(
26
+ :spree_stock_items,
27
+ ['variant_id', 'stock_location_id'],
28
+ name: 'index_spree_stock_items_unique_without_deleted_at',
29
+ unique: true,
30
+ where: 'deleted_at IS NULL',
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,6 @@
1
+ class AddWeightAndDimensionUnitsToSpreeVariants < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column :spree_variants, :weight_unit, :string, if_not_exists: true
4
+ add_column :spree_variants, :dimensions_unit, :string, if_not_exists: true
5
+ end
6
+ end
@@ -0,0 +1,23 @@
1
+ module Spree
2
+ class CustomAuthenticationGenerator < Rails::Generators::Base
3
+ desc 'Set up a Spree installation with a custom authentication helpers'
4
+
5
+ def self.source_paths
6
+ paths = superclass.source_paths
7
+ paths << File.expand_path('templates', __dir__)
8
+ paths.flatten
9
+ end
10
+
11
+ def generate
12
+ template 'authentication_helpers.rb.tt', 'lib/spree/authentication_helpers.rb'
13
+
14
+ file_action = File.exist?('config/initializers/spree.rb') ? :append_file : :create_file
15
+ send(file_action, 'config/initializers/spree.rb') do
16
+ %Q{
17
+ Rails.application.config.to_prepare do
18
+ require_dependency 'spree/authentication_helpers'
19
+ end\n}
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,14 +1,4 @@
1
1
  module Spree
2
- module CurrentUserHelpers
3
- def self.included(receiver)
4
- receiver.send :helper_method, :spree_current_user
5
- end
6
-
7
- def spree_current_user
8
- current_user
9
- end
10
- end
11
-
12
2
  module AuthenticationHelpers
13
3
  def self.included(receiver)
14
4
  receiver.send :helper_method, :spree_login_path
@@ -30,7 +20,4 @@ module Spree
30
20
  end
31
21
  end
32
22
 
33
- ApplicationController.include Spree::AuthenticationHelpers
34
- ApplicationController.include Spree::CurrentUserHelpers
35
-
36
- Spree::Api::BaseController.include Spree::CurrentUserHelpers
23
+ ApplicationController.include Spree::AuthenticationHelpers if defined?(ApplicationController)
@@ -20,24 +20,19 @@ module Spree
20
20
 
21
21
  def generate
22
22
  migration_template 'migration.rb.tt', 'db/migrate/add_spree_fields_to_custom_user_table.rb'
23
- template 'authentication_helpers.rb.tt', 'lib/spree/authentication_helpers.rb'
23
+ template 'current_user_helpers.rb.tt', 'lib/spree/current_user_helpers.rb'
24
24
 
25
25
  file_action = File.exist?('config/initializers/spree.rb') ? :append_file : :create_file
26
26
  send(file_action, 'config/initializers/spree.rb') do
27
27
  %Q{
28
28
  Rails.application.config.to_prepare do
29
- require_dependency 'spree/authentication_helpers'
29
+ require_dependency 'spree/current_user_helpers'
30
30
  end\n}
31
31
  end
32
32
  end
33
33
 
34
34
  def self.next_migration_number(dirname)
35
- if ApplicationRecord.timestamped_migrations
36
- sleep 1 # make sure to get a different migration every time
37
- Time.new.utc.strftime('%Y%m%d%H%M%S')
38
- else
39
- format('%.3d', (current_migration_number(dirname) + 1))
40
- end
35
+ format('%.3d', (current_migration_number(dirname) + 1))
41
36
  end
42
37
 
43
38
  def klass
@@ -0,0 +1,15 @@
1
+ module Spree
2
+ module CurrentUserHelpers
3
+ def self.included(receiver)
4
+ receiver.send :helper_method, :spree_current_user
5
+ end
6
+
7
+ def spree_current_user
8
+ current_user
9
+ end
10
+ end
11
+ end
12
+
13
+
14
+ ApplicationController.include Spree::CurrentUserHelpers if defined?(ApplicationController)
15
+ Spree::Api::BaseController.include Spree::CurrentUserHelpers if defined?(Spree::Api::BaseController)
@@ -1,7 +1,7 @@
1
1
  class AddSpreeFieldsToCustomUserTable < ActiveRecord::Migration[4.2]
2
2
  def up
3
3
  add_column <%= table_name.inspect %>, :spree_api_key, :string, limit: 48
4
- add_column <%= table_name.inspect %>, :ship_address_id, :integer
5
- add_column <%= table_name.inspect %>, :bill_address_id, :integer
4
+ add_column <%= table_name.inspect %>, :ship_address_id, :bigint
5
+ add_column <%= table_name.inspect %>, :bill_address_id, :bigint
6
6
  end
7
7
  end
@@ -29,10 +29,9 @@ module Spree
29
29
  # calling slice on a Thor::CoreExtensions::HashWithIndifferentAccess
30
30
  # object has been known to return nil
31
31
  opts = {}.merge(options).slice(*PASSTHROUGH_OPTIONS)
32
- opts[:database] = 'postgresql' if opts[:database].blank?
32
+ opts[:database] = 'sqlite3' if opts[:database].blank?
33
33
  opts[:force] = true
34
34
  opts[:skip_bundle] = true
35
- opts[:skip_gemfile] = true
36
35
  opts[:skip_git] = true
37
36
  opts[:skip_listen] = true
38
37
  opts[:skip_rc] = true
@@ -57,10 +56,6 @@ module Spree
57
56
  template 'rails/test.rb', "#{dummy_path}/config/environments/test.rb", force: true
58
57
  template 'rails/script/rails', "#{dummy_path}/spec/dummy/script/rails", force: true
59
58
  template 'initializers/devise.rb', "#{dummy_path}/config/initializers/devise.rb", force: true
60
-
61
- if lib_name == 'spree/backend'
62
- template 'package.json', "#{dummy_path}/package.json", force: true
63
- end
64
59
  end
65
60
 
66
61
  def test_dummy_inject_extension_requirements
@@ -8,7 +8,18 @@ end %>
8
8
  <% db_username = ENV['DB_USERNAME'] %>
9
9
  <% db_host = ENV['DB_HOST'] %>
10
10
  <% case ENV['DB']
11
- when 'mysql' %>
11
+ when 'sqlite' %>
12
+ development:
13
+ adapter: sqlite3
14
+ database: db/spree_development.sqlite3
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/spree_test.sqlite3
18
+ timeout: 10000
19
+ production:
20
+ adapter: sqlite3
21
+ database: db/spree_production.sqlite3
22
+ <% when 'mysql' %>
12
23
  mysql: &mysql
13
24
  adapter: mysql2
14
25
  encoding: utf8
@@ -57,26 +68,13 @@ production:
57
68
  <<: *postgres
58
69
  database: <%= database_prefix %><%= lib_name %>_spree_production
59
70
  <% else %>
60
- postgres: &postgres
61
- adapter: postgresql
62
- <% unless db_username.blank? %>
63
- username: <%= db_username || 'postgres' %>
64
- <% end %>
65
- <% unless db_password.blank? %>
66
- password: <%= db_password %>
67
- <% end %>
68
- <% unless db_host.blank? %>
69
- host: <%= db_host %>
70
- <% end %>
71
- min_messages: warning
72
-
73
71
  development:
74
- <<: *postgres
75
- database: <%= database_prefix %><%= lib_name %>_spree_development
72
+ adapter: sqlite3
73
+ database: db/spree_development.sqlite3
76
74
  test:
77
- <<: *postgres
78
- database: <%= database_prefix %><%= lib_name %>_spree_test
75
+ adapter: sqlite3
76
+ database: db/spree_test.sqlite3
79
77
  production:
80
- <<: *postgres
81
- database: <%= database_prefix %><%= lib_name %>_spree_production
82
- <% end %>
78
+ adapter: sqlite3
79
+ database: db/spree_production.sqlite3
80
+ <% end %>
@@ -36,7 +36,7 @@ Dummy::Application.configure do
36
36
 
37
37
  config.active_job.queue_adapter = :test
38
38
 
39
- config.cache_store = :redis_cache_store
39
+ config.cache_store = :memory_store # we need to use memory store for Spree preferences
40
40
 
41
41
  routes.default_url_options = { host: 'localhost', port: 3000 }
42
42
  end
@@ -9,17 +9,40 @@
9
9
  #
10
10
  # In order to initialize a setting do:
11
11
  # config.setting_name = 'new value'
12
+ #
13
+ # More on configuring Spree preferences can be found at:
14
+ # https://docs.spreecommerce.org/developer/customization
12
15
  Spree.config do |config|
13
16
  # Example:
14
17
  # Uncomment to stop tracking inventory levels in the application
15
18
  # config.track_inventory_levels = false
16
19
  end
17
20
 
21
+ # Use a CDN host for images, eg. Cloudfront
22
+ # This is used in the frontend to generate absolute URLs to images
23
+ # Default is nil and your application host will be used
24
+ # Spree.cdn_host = 'cdn.example.com'
25
+
26
+ # Use a different service for storage (S3, google, etc)
27
+ # unless Rails.env.test?
28
+ # Spree.private_storage_service_name = :amazon_public # public assets, such as product images
29
+ # Spree.public_storage_service_name = :amazon_private # private assets, such as invoices, etc
30
+ # end
31
+
32
+ # Use a different search engine for products
33
+ # You can check the default search class at:
34
+ # https://github.com/spree/spree/blob/main/core/lib/spree/core/search/base.rb
35
+ # and use it as base class for your custom searcher
36
+ # eg. MySearcher < Spree::Core::Search::Base
37
+ # Spree.searcher_class = 'MySearcher'
38
+
18
39
  # Configure Spree Dependencies
19
40
  #
20
41
  # Note: If a dependency is set here it will NOT be stored within the cache & database upon initialization.
21
42
  # Just removing an entry from this initializer will make the dependency value go away.
22
43
  #
44
+ # More on how to use Spree dependencies can be found at:
45
+ # https://docs.spreecommerce.org/customization/dependencies
23
46
  Spree.dependencies do |dependencies|
24
47
  # Example:
25
48
  # Uncomment to change the default Service handling adding Items to Cart
@@ -29,3 +52,5 @@ end
29
52
  # Spree::Api::Dependencies.storefront_cart_serializer = 'MyRailsApp::CartSerializer'
30
53
 
31
54
  Spree.user_class = <%= (options[:user_class].blank? ? 'Spree::LegacyUser' : options[:user_class]).inspect %>
55
+ # Use a different class for admin users
56
+ # Spree.admin_user_class = 'AdminUser'
@@ -1,4 +1,4 @@
1
- # This is the primary location for defining spree preferences
1
+ # This is the primary location for defining Spree Core preferences
2
2
  #
3
3
  # The expectation is that this is created once and stored in
4
4
  # the spree environment
@@ -22,29 +22,20 @@ module Spree
22
22
  module Core
23
23
  class Configuration < Preferences::Configuration
24
24
  # Alphabetized to more easily lookup particular preferences
25
- preference :address_requires_state, :boolean, default: true # should state/state_name be required
25
+ preference :address_requires_state, :boolean, default: true, deprecated: true # should state/state_name be required
26
26
  preference :address_requires_phone, :boolean, default: true # Determines whether we require phone in address
27
- preference :admin_path, :string, deprecated: true
28
- preference :admin_products_per_page, :integer, deprecated: true
29
- preference :admin_orders_per_page, :integer, deprecated: true
30
- preference :admin_properties_per_page, :integer, deprecated: true
31
- preference :admin_promotions_per_page, :integer, deprecated: true
32
- preference :admin_customer_returns_per_page, :integer, deprecated: true
33
- preference :admin_users_per_page, :integer, deprecated: true
34
- preference :admin_show_version, :boolean, deprecated: true
35
27
  preference :allow_checkout_on_gateway_error, :boolean, default: false
36
- preference :allow_guest_checkout, :boolean, default: true
28
+ preference :allow_guest_checkout, :boolean, default: true # this is only used in the rails frontend, and is not implemented in API
37
29
  preference :alternative_shipping_phone, :boolean, default: false # Request extra phone for ship addr
38
30
  preference :always_include_confirm_step, :boolean, default: false # Ensures confirmation step is always in checkout_progress bar, but does not force a confirm step if your payment methods do not support it.
39
31
  preference :always_put_site_name_in_title, :boolean, deprecated: true
40
- preference :title_site_name_separator, :string, deprecated: true
41
32
  preference :auto_capture, :boolean, default: false # automatically capture the credit card (as opposed to just authorize and capture later)
42
33
  preference :auto_capture_on_dispatch, :boolean, default: false # Captures payment for each shipment in Shipment#after_ship callback, and makes Shipment.ready when payment authorized.
43
- preference :binary_inventory_cache, :boolean, default: false # only invalidate product cache when a stock item changes whether it is in_stock
34
+ preference :binary_inventory_cache, :boolean, default: false, deprecated: true # only invalidate product cache when a stock item changes whether it is in_stock
44
35
  preference :checkout_zone, :string, default: nil, deprecated: true # replace with the name of a zone if you would like to limit the countries
45
36
  preference :company, :boolean, default: false # Request company field for billing and shipping addr
46
37
  preference :currency, :string, default: 'USD', deprecated: true
47
- preference :default_country_id, :integer, deprecated: true
38
+ preference :credit_to_new_allocation, :boolean, default: false
48
39
  preference :disable_sku_validation, :boolean, default: false # when turned off disables the built-in SKU uniqueness validation
49
40
  preference :disable_store_presence_validation, :boolean, default: false # when turned off disables Store presence validation for Products and Payment Methods
50
41
  preference :expedited_exchanges, :boolean, default: false # NOTE this requires payment profiles to be supported on your gateway of choice as well as a delayed job handler to be configured with activejob. kicks off an exchange shipment upon return authorization save. charge customer if they do not return items within timely manner.
@@ -53,6 +44,7 @@ module Spree
53
44
  preference :logo, :string, deprecated: true
54
45
  preference :mailer_logo, :string, deprecated: true
55
46
  preference :max_level_in_taxons_menu, :integer, deprecated: true
47
+ preference :non_expiring_credit_types, :array, default: []
56
48
  preference :products_per_page, :integer, default: 12
57
49
  preference :require_master_price, :boolean, default: true
58
50
  preference :restock_inventory, :boolean, default: true # Determines if a return item is restocked automatically once it has been received
@@ -64,15 +56,14 @@ module Spree
64
56
  preference :show_products_without_price, :boolean, default: false
65
57
  preference :show_raw_product_description, :boolean, deprecated: true
66
58
  preference :tax_using_ship_address, :boolean, default: true
59
+ preference :title_site_name_separator, :string, deprecated: true
67
60
  preference :track_inventory_levels, :boolean, default: true # Determines whether to track on_hand values for variants / products.
68
61
  preference :use_user_locale, :boolean, default: true
69
62
 
70
- # Store credits configurations
71
- preference :non_expiring_credit_types, :array, default: []
72
- preference :credit_to_new_allocation, :boolean, default: false
73
-
74
- # Multi store configurations
75
- preference :show_store_selector, :boolean, deprecated: true
63
+ # Sets the path used for products, taxons and pages.
64
+ preference :storefront_products_path, :string, default: 'products'
65
+ preference :storefront_taxons_path, :string, default: 't'
66
+ preference :storefront_pages_path, :string, default: 'pages'
76
67
 
77
68
  # searcher_class allows spree extension writers to provide their own Search class
78
69
  def searcher_class
@@ -80,11 +71,6 @@ module Spree
80
71
  @searcher_class ||= Spree.searcher_class
81
72
  end
82
73
 
83
- # Sets the path used for products, taxons and pages.
84
- preference :storefront_products_path, :string, default: 'products'
85
- preference :storefront_taxons_path, :string, default: 't'
86
- preference :storefront_pages_path, :string, default: 'pages'
87
-
88
74
  attr_writer :searcher_class
89
75
  end
90
76
  end
@@ -28,6 +28,10 @@ module Spree
28
28
  Spree::Locales::SetFallbackLocaleForStore.new.call(store: current_store)
29
29
  end
30
30
 
31
+ def default_locale
32
+ @default_locale ||= current_store&.default_locale || Rails.application.config.i18n.default_locale || I18n.default_locale
33
+ end
34
+
31
35
  def current_locale
32
36
  @current_locale ||= if user_locale?
33
37
  try_spree_current_user.selected_locale
@@ -36,7 +40,7 @@ module Spree
36
40
  elsif config_locale?
37
41
  config_locale
38
42
  else
39
- current_store&.default_locale || Rails.application.config.i18n.default_locale || I18n.default_locale
43
+ default_locale
40
44
  end
41
45
  end
42
46
 
@@ -1,11 +1,13 @@
1
1
  require_relative 'dependencies'
2
2
  require_relative 'configuration'
3
+ require_relative 'runtime_configuration'
3
4
 
4
5
  module Spree
5
6
  module Core
6
7
  class Engine < ::Rails::Engine
7
8
  Environment = Struct.new(:calculators,
8
9
  :preferences,
10
+ :runtime_preferences,
9
11
  :dependencies,
10
12
  :payment_methods,
11
13
  :adjusters,
@@ -23,9 +25,10 @@ module Spree
23
25
  end
24
26
 
25
27
  initializer 'spree.environment', before: :load_config_initializers do |app|
26
- app.config.spree = Environment.new(SpreeCalculators.new, Spree::Core::Configuration.new, Spree::Core::Dependencies.new)
28
+ app.config.spree = Environment.new(SpreeCalculators.new, Spree::Core::Configuration.new, Spree::Core::RuntimeConfiguration.new, Spree::Core::Dependencies.new)
27
29
  app.config.active_record.yaml_column_permitted_classes = [Symbol, BigDecimal]
28
30
  Spree::Config = app.config.spree.preferences
31
+ Spree::RuntimeConfig = app.config.spree.runtime_preferences
29
32
  Spree::Dependencies = app.config.spree.dependencies
30
33
  Spree::Deprecation = ActiveSupport::Deprecation.new
31
34
  end
@@ -0,0 +1,43 @@
1
+ module Spree
2
+ module Preferences
3
+ class RuntimeConfiguration
4
+ def initialize
5
+ self.class.defaults.each do |key, value|
6
+ self[key] = value
7
+ end
8
+ end
9
+
10
+ def configure
11
+ yield(self) if block_given?
12
+ end
13
+
14
+ def get(preference)
15
+ send(preference)
16
+ end
17
+
18
+ alias [] get
19
+
20
+ def set(preference, value)
21
+ send("#{preference}=", value)
22
+ end
23
+
24
+ alias []= set
25
+
26
+ class << self
27
+ def preference(name, _type, default: nil, deprecated: false)
28
+ defaults[name] = default
29
+ deprecations[name] = deprecated
30
+ attr_accessor name
31
+ end
32
+
33
+ def defaults
34
+ @defaults ||= {}
35
+ end
36
+
37
+ def deprecations
38
+ @deprecations ||= {}
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -30,6 +30,8 @@ module Spree
30
30
  t.name = "COPY OF #{t.name}"
31
31
  t.slug = nil
32
32
  end
33
+
34
+ new_product.name = "COPY OF #{product.name}"
33
35
  new_product.taxons = product.taxons
34
36
  new_product.stores = product.stores
35
37
  new_product.created_at = nil
@@ -98,7 +98,12 @@ module Spree
98
98
  conds.each do |new_scope|
99
99
  scope = scope.or(new_scope)
100
100
  end
101
- Product.with_property('brand').join_translation_table(ProductProperty).where(scope)
101
+
102
+ if Spree.use_translations?
103
+ Product.with_property('brand').join_translation_table(ProductProperty).where(scope)
104
+ else
105
+ Product.with_property('brand').where(scope)
106
+ end
102
107
  end
103
108
 
104
109
  def self.brand_filter
@@ -106,7 +111,9 @@ module Spree
106
111
  brands = brand_property ? Spree::ProductProperty.where(property_id: brand_property.id).pluck(:value).uniq.map(&:to_s) : []
107
112
 
108
113
  conditions = brands.map do |brand|
109
- [brand, { ProductProperty.translation_table_alias => { value: brand } }]
114
+ table_name = Spree.use_translations? ? ProductProperty.translation_table_alias : ProductProperty.table_name
115
+
116
+ [brand, { table_name.to_s => { value: brand } }]
110
117
  end.to_h
111
118
 
112
119
  {
@@ -0,0 +1,9 @@
1
+ require 'spree/core/preferences/runtime_configuration'
2
+
3
+ module Spree
4
+ module Core
5
+ class RuntimeConfiguration < Preferences::RuntimeConfiguration
6
+ preference :always_use_translations, :boolean, default: false
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  module Spree
2
- VERSION = '4.7.2'.freeze
2
+ VERSION = '4.8.0'.freeze
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ module Webhooks
3
+ def self.disable_webhooks
4
+ webhooks_disabled_previously = ENV['DISABLE_SPREE_WEBHOOKS']
5
+ begin
6
+ ENV['DISABLE_SPREE_WEBHOOKS'] = 'true'
7
+ yield
8
+ ensure
9
+ ENV['DISABLE_SPREE_WEBHOOKS'] = webhooks_disabled_previously
10
+ end
11
+ end
12
+ end
13
+ end
data/lib/spree/core.rb CHANGED
@@ -76,6 +76,10 @@ module Spree
76
76
  end
77
77
  end
78
78
 
79
+ def self.use_translations?
80
+ Spree::RuntimeConfig.always_use_translations || I18n.default_locale != I18n.locale
81
+ end
82
+
79
83
  # Used to configure Spree.
80
84
  #
81
85
  # Example:
@@ -141,3 +145,6 @@ require 'spree/core/controller_helpers/currency'
141
145
 
142
146
  require 'spree/core/preferences/store'
143
147
  require 'spree/core/preferences/scoped_store'
148
+ require 'spree/core/preferences/runtime_configuration'
149
+
150
+ require "spree/core/webhooks"