spree_core 4.7.3 → 4.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) 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/product_scopes.rb +19 -19
  5. data/app/models/concerns/spree/user_address.rb +4 -2
  6. data/app/models/spree/address.rb +1 -20
  7. data/app/models/spree/asset.rb +1 -1
  8. data/app/models/spree/cms_page.rb +1 -1
  9. data/app/models/spree/country.rb +0 -26
  10. data/app/models/spree/credit_card.rb +4 -2
  11. data/app/models/spree/customer_return.rb +1 -1
  12. data/app/models/spree/digital.rb +1 -1
  13. data/app/models/spree/digital_link.rb +1 -1
  14. data/app/models/spree/inventory_unit.rb +1 -1
  15. data/app/models/spree/line_item.rb +1 -1
  16. data/app/models/spree/menu.rb +1 -1
  17. data/app/models/spree/menu_item.rb +1 -1
  18. data/app/models/spree/option_type.rb +3 -3
  19. data/app/models/spree/option_value.rb +3 -3
  20. data/app/models/spree/order.rb +5 -3
  21. data/app/models/spree/payment.rb +1 -1
  22. data/app/models/spree/payment_capture_event.rb +1 -1
  23. data/app/models/spree/price.rb +3 -1
  24. data/app/models/spree/product.rb +24 -13
  25. data/app/models/spree/product_property.rb +4 -2
  26. data/app/models/spree/promotion.rb +1 -1
  27. data/app/models/spree/property.rb +6 -4
  28. data/app/models/spree/prototype.rb +1 -1
  29. data/app/models/spree/refund.rb +1 -1
  30. data/app/models/spree/reimbursement.rb +1 -1
  31. data/app/models/spree/return_authorization.rb +1 -1
  32. data/app/models/spree/return_item.rb +1 -1
  33. data/app/models/spree/shipment.rb +1 -1
  34. data/app/models/spree/shipping_category.rb +1 -1
  35. data/app/models/spree/shipping_method.rb +1 -1
  36. data/app/models/spree/stock_item.rb +2 -2
  37. data/app/models/spree/stock_location.rb +6 -1
  38. data/app/models/spree/stock_movement.rb +1 -1
  39. data/app/models/spree/stock_transfer.rb +1 -1
  40. data/app/models/spree/store.rb +2 -4
  41. data/app/models/spree/store_credit.rb +1 -1
  42. data/app/models/spree/store_favicon_image.rb +11 -2
  43. data/app/models/spree/tax_category.rb +1 -1
  44. data/app/models/spree/tax_rate.rb +1 -1
  45. data/app/models/spree/taxon.rb +20 -4
  46. data/app/models/spree/taxonomy.rb +3 -3
  47. data/app/models/spree/variant.rb +9 -4
  48. data/app/models/spree/wished_item.rb +1 -1
  49. data/app/models/spree/wishlist.rb +1 -1
  50. data/app/models/spree/zone.rb +1 -1
  51. data/app/services/spree/addresses/update.rb +1 -0
  52. data/app/services/spree/seeds/all.rb +15 -13
  53. data/app/services/spree/seeds/stores.rb +2 -2
  54. data/app/sorters/spree/products/sort.rb +1 -1
  55. data/config/initializers/mobility.rb +1 -0
  56. data/config/locales/en.yml +2 -36
  57. data/config/routes.rb +7 -8
  58. data/db/migrate/20210929090344_create_stock_item_stock_location_id_variant_id_coalesce_deleted_at_unique_index.rb +1 -28
  59. data/db/migrate/20230103144439_create_option_type_translations.rb +0 -1
  60. data/db/migrate/20230103151034_create_option_value_translations.rb +0 -1
  61. data/db/migrate/20230109084253_create_product_property_translations.rb +0 -1
  62. data/db/migrate/20230109105943_create_property_translations.rb +0 -2
  63. data/db/migrate/20230110142344_backfill_friendly_id_slug_locale.rb +2 -8
  64. data/db/migrate/20240303174340_fix_spree_stock_item_unique_index.rb +35 -0
  65. data/db/migrate/20240514105216_add_weight_and_dimension_units_to_spree_variants.rb +6 -0
  66. data/lib/generators/spree/custom_authentication/custom_authentication_generator.rb +23 -0
  67. data/lib/generators/spree/{custom_user → custom_authentication}/templates/authentication_helpers.rb.tt +1 -14
  68. data/lib/generators/spree/custom_user/custom_user_generator.rb +3 -8
  69. data/lib/generators/spree/custom_user/templates/current_user_helpers.rb.tt +15 -0
  70. data/lib/generators/spree/custom_user/templates/migration.rb.tt +2 -2
  71. data/lib/generators/spree/dummy/dummy_generator.rb +1 -6
  72. data/lib/generators/spree/dummy/templates/rails/database.yml +19 -21
  73. data/lib/generators/spree/dummy/templates/rails/test.rb +1 -1
  74. data/lib/generators/spree/install/templates/config/initializers/spree.rb +25 -0
  75. data/lib/spree/core/configuration.rb +11 -25
  76. data/lib/spree/core/controller_helpers/locale.rb +5 -1
  77. data/lib/spree/core/engine.rb +4 -1
  78. data/lib/spree/core/preferences/runtime_configuration.rb +43 -0
  79. data/lib/spree/core/product_duplicator.rb +2 -0
  80. data/lib/spree/core/product_filters.rb +9 -2
  81. data/lib/spree/core/runtime_configuration.rb +9 -0
  82. data/lib/spree/core/version.rb +1 -1
  83. data/lib/spree/core/webhooks.rb +13 -0
  84. data/lib/spree/core.rb +10 -1
  85. data/lib/spree/money.rb +38 -5
  86. data/lib/spree/testing_support/authorization_helpers.rb +3 -1
  87. data/lib/spree/testing_support/common_rake.rb +7 -18
  88. data/spree_core.gemspec +7 -7
  89. metadata +47 -50
  90. data/db/migrate/20220715120222_change_product_name_null_to_true.rb +0 -5
  91. data/db/migrate/20220718100948_change_taxon_name_null_to_true.rb +0 -5
  92. data/db/migrate/20220804073928_transfer_data_to_translatable_tables.rb +0 -66
  93. data/db/migrate/20230109094907_transfer_options_data_to_translatable_tables.rb +0 -58
  94. data/db/migrate/20230109110840_transfer_property_data_to_translatable_tables.rb +0 -59
  95. data/db/migrate/20230111122511_transfer_product_and_taxon_data_to_translatable_tables.rb +0 -82
  96. data/db/migrate/20230117120430_allow_null_taxonomy_name.rb +0 -5
  97. data/db/migrate/20230117121303_transfer_taxonomy_data_to_translatable_tables.rb +0 -11
  98. data/db/migrate/20230210142849_transfer_store_data_to_translatable_tables.rb +0 -11
  99. data/db/migrate/20230514162157_add_index_on_locale_and_permalink_to_spree_taxons.rb +0 -5
@@ -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.3'.freeze
2
+ VERSION = '4.8.1'.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:
@@ -87,7 +91,9 @@ module Spree
87
91
  # This method is defined within the core gem on purpose.
88
92
  # Some people may only wish to use the Core part of Spree.
89
93
  def self.config
90
- yield(Spree::Config)
94
+ Rails.application.config.after_initialize do
95
+ yield(Spree::Config)
96
+ end
91
97
  end
92
98
 
93
99
  # Used to set dependencies for Spree.
@@ -141,3 +147,6 @@ require 'spree/core/controller_helpers/currency'
141
147
 
142
148
  require 'spree/core/preferences/store'
143
149
  require 'spree/core/preferences/scoped_store'
150
+ require 'spree/core/preferences/runtime_configuration'
151
+
152
+ require "spree/core/webhooks"
data/lib/spree/money.rb CHANGED
@@ -5,8 +5,15 @@ Money.rounding_mode = BigDecimal::ROUND_HALF_UP
5
5
 
6
6
  module Spree
7
7
  class Money
8
+ include Comparable
9
+
8
10
  class << self
9
11
  attr_accessor :default_formatting_rules
12
+
13
+ def from_cents(amount_in_cents, options = {})
14
+ money = ::Money.from_cents(amount_in_cents, options[:currency])
15
+ new(money.to_d, options)
16
+ end
10
17
  end
11
18
 
12
19
  self.default_formatting_rules = {
@@ -17,10 +24,10 @@ module Spree
17
24
 
18
25
  attr_reader :money
19
26
 
20
- delegate :cents, :currency, to: :money
27
+ delegate :cents, :currency, :to_d, :positive?, :zero?, to: :money
21
28
 
22
29
  def initialize(amount, options = {})
23
- use_default_currency
30
+ ::Money.default_currency ||= Spree::Store.default.default_currency || 'USD'
24
31
  @money = Monetize.parse([amount, (options[:currency] || Spree::Store.default.default_currency)].join)
25
32
  @options = Spree::Money.default_formatting_rules.merge(options)
26
33
  end
@@ -29,10 +36,18 @@ module Spree
29
36
  (cents / currency.subunit_to_unit.to_f * 100).round
30
37
  end
31
38
 
39
+ def abs
40
+ self.class.new(money.abs, options)
41
+ end
42
+
32
43
  def to_s
33
44
  money&.format(options)
34
45
  end
35
46
 
47
+ def inspect
48
+ "#{self.class}(cents: #{cents}, currency: #{currency})"
49
+ end
50
+
36
51
  # 1) prevent blank, breaking spaces
37
52
  # 2) prevent escaping of HTML character entities
38
53
  def to_html(opts = { html: true })
@@ -65,9 +80,27 @@ module Spree
65
80
  money == obj.money
66
81
  end
67
82
 
68
- def use_default_currency
69
- currency = Spree::Store.default.default_currency
70
- ::Money.default_currency = currency
83
+ def +(other)
84
+ result_money = money + other.money
85
+ self.class.new(result_money.to_s, options)
86
+ end
87
+
88
+ def -(other)
89
+ result_money = money - other.money
90
+ self.class.new(result_money.to_s, options)
91
+ end
92
+
93
+ def *(value)
94
+ result_money = money * value
95
+ self.class.new(result_money.to_s, options)
96
+ end
97
+
98
+ def <=>(other)
99
+ money <=> other.money
100
+ end
101
+
102
+ def -@
103
+ self.class.new((-money).to_s, options)
71
104
  end
72
105
 
73
106
  private
@@ -37,12 +37,14 @@ module Spree
37
37
  ability_class.register_ability(ability)
38
38
  end
39
39
 
40
+ let(:user) { Spree.user_class.new }
40
41
  let(:admin_app) { Spree::OauthApplication.create!(name: 'Admin Panel', scopes: 'admin') }
41
42
  let(:admin_token) { Spree::OauthAccessToken.create!(application: admin_app, scopes: 'admin').token }
42
43
 
43
44
  before do
44
- allow(Spree.user_class).to receive(:find_by).and_return(Spree.user_class.new)
45
+ allow(Spree.user_class).to receive(:find_by).and_return(user)
45
46
  if defined?(Spree::Admin)
47
+ allow_any_instance_of(Spree::Admin::BaseController).to receive(:try_spree_current_user).and_return(user)
46
48
  allow_any_instance_of(Spree::Admin::BaseController).to receive(:admin_oauth_application).and_return(admin_app)
47
49
  allow_any_instance_of(Spree::Admin::BaseController).to receive(:admin_oauth_token).and_return(admin_token)
48
50
  end
@@ -14,21 +14,21 @@ namespace :common do
14
14
  ENV['RAILS_ENV'] = 'test'
15
15
  Rails.env = 'test'
16
16
 
17
- if ENV['LIB_NAME'] == 'spree/backend'
18
- puts 'Preparing NPM package...'
19
- system('yarn install')
20
- system('yarn build')
21
- system('yarn link')
17
+ Spree::DummyGenerator.start ["--lib_name=#{ENV['LIB_NAME']}"]
18
+
19
+ # install frontend libraries
20
+ unless ['spree/api', 'spree/core', 'spree/sample'].include?(ENV['LIB_NAME'])
21
+ system('bin/rails importmap:install')
22
+ system('bin/rails turbo:install')
23
+ system('bin/rails stimulus:install')
22
24
  end
23
25
 
24
- Spree::DummyGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", '--quiet']
25
26
  Spree::InstallGenerator.start [
26
27
  "--lib_name=#{ENV['LIB_NAME']}",
27
28
  '--auto-accept',
28
29
  '--migrate=false',
29
30
  '--seed=false',
30
31
  '--sample=false',
31
- '--quiet',
32
32
  '--copy_storefront=false',
33
33
  "--install_storefront=#{args[:install_storefront]}",
34
34
  "--install_admin=#{args[:install_admin]}",
@@ -41,12 +41,6 @@ namespace :common do
41
41
  Spree::DummyModelGenerator.start
42
42
  system('bundle exec rake db:migrate')
43
43
 
44
- unless ['spree/api', 'spree/core', 'spree/sample', 'spree/emails'].include?(ENV['LIB_NAME'])
45
- puts 'Setting up node environment'
46
- system('bin/rails javascript:install:esbuild')
47
- system('bin/rails turbo:install')
48
- end
49
-
50
44
  begin
51
45
  require "generators/#{ENV['LIB_NAME']}/install/install_generator"
52
46
  puts 'Running extension installation generator...'
@@ -56,11 +50,6 @@ namespace :common do
56
50
  end
57
51
 
58
52
  unless ['spree/api', 'spree/core', 'spree/sample'].include?(ENV['LIB_NAME'])
59
- if ENV['LIB_NAME'] == 'spree/backend'
60
- puts 'Installing node dependencies...'
61
- system('yarn link @spree/dashboard')
62
- system('yarn install')
63
- end
64
53
  puts 'Precompiling assets...'
65
54
  system('bundle exec rake assets:precompile')
66
55
  end
data/spree_core.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.metadata = {
17
17
  "bug_tracker_uri" => "https://github.com/spree/spree/issues",
18
18
  "changelog_uri" => "https://github.com/spree/spree/releases/tag/v#{s.version}",
19
- "documentation_uri" => "https://dev-docs.spreecommerce.org/",
19
+ "documentation_uri" => "https://docs.spreecommerce.org/",
20
20
  "source_code_uri" => "https://github.com/spree/spree/tree/v#{s.version}",
21
21
  }
22
22
 
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
30
30
  actionpack actionview activejob activemodel activerecord
31
31
  activestorage activesupport railties
32
32
  ].each do |rails_gem|
33
- s.add_dependency rails_gem, '>= 6.1', '< 7.2'
33
+ s.add_dependency rails_gem, '>= 6.1', '< 8.0'
34
34
  end
35
35
 
36
36
  s.add_dependency 'activemerchant', '~> 1.67'
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
40
40
  s.add_dependency 'carmen', '>= 1.0'
41
41
  s.add_dependency 'cancancan', '~> 3.2'
42
42
  s.add_dependency 'friendly_id', '~> 5.2', '>= 5.2.1'
43
- s.add_dependency 'highline', '~> 2.0' # Necessary for the install generator
43
+ s.add_dependency 'highline', '>= 2', '< 4' # Necessary for the install generator
44
44
  s.add_dependency 'kaminari', '~> 1.2'
45
45
  s.add_dependency 'money', '~> 6.13'
46
46
  s.add_dependency 'monetize', '~> 1.9'
@@ -52,9 +52,9 @@ Gem::Specification.new do |s|
52
52
  s.add_dependency 'stringex'
53
53
  s.add_dependency 'validates_zipcode'
54
54
  s.add_dependency 'image_processing', '~> 1.2'
55
- s.add_dependency 'active_storage_validations', '~> 0.9', '<= 0.9.5'
55
+ s.add_dependency 'active_storage_validations', '~> 1.1'
56
56
  s.add_dependency 'activerecord-typedstore'
57
- s.add_dependency 'mobility', '~> 1.2.9'
58
- s.add_dependency 'mobility-ransack', '~> 1.2.1'
59
- s.add_dependency 'friendly_id-mobility', '~> 1.0.4'
57
+ s.add_dependency 'mobility', '~> 1.2'
58
+ s.add_dependency 'mobility-ransack', '~> 1.2'
59
+ s.add_dependency 'friendly_id-mobility', '~> 1.0'
60
60
  end