solidus_core 3.1.7 → 3.2.0.alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/helpers/spree/products_helper.rb +1 -1
- data/app/models/concerns/spree/active_storage_adapter/attachment.rb +23 -10
- data/app/models/concerns/spree/active_storage_adapter.rb +1 -1
- data/app/models/concerns/spree/user_address_book.rb +11 -1
- data/app/models/concerns/spree/user_methods.rb +20 -1
- data/app/models/spree/adjustment.rb +1 -0
- data/app/models/spree/carton.rb +1 -1
- data/app/models/spree/option_value.rb +9 -0
- data/app/models/spree/order.rb +68 -29
- data/app/models/spree/order_contents.rb +2 -1
- data/app/models/spree/order_inventory.rb +1 -1
- data/app/models/spree/order_merger.rb +2 -2
- data/app/models/spree/order_taxation.rb +6 -4
- data/app/models/spree/order_updater.rb +4 -3
- data/app/models/spree/payment_method.rb +11 -0
- data/app/models/spree/product/scopes.rb +21 -3
- data/app/models/spree/product.rb +1 -1
- data/app/models/spree/promotion/actions/create_adjustment.rb +4 -0
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +5 -6
- data/app/models/spree/promotion/rules/product.rb +20 -8
- data/app/models/spree/promotion/rules/store.rb +4 -0
- data/app/models/spree/promotion/rules/taxon.rb +4 -0
- data/app/models/spree/promotion/rules/user.rb +4 -0
- data/app/models/spree/promotion.rb +34 -23
- data/app/models/spree/promotion_action.rb +4 -0
- data/app/models/spree/promotion_code.rb +8 -4
- data/app/models/spree/promotion_handler/cart.rb +26 -6
- data/app/models/spree/promotion_rule.rb +5 -0
- data/app/models/spree/reimbursement.rb +2 -2
- data/app/models/spree/return_item.rb +1 -2
- data/app/models/spree/stock/allocator/on_hand_first.rb +2 -2
- data/app/models/spree/stock/quantifier.rb +12 -8
- data/app/models/spree/stock/simple_coordinator.rb +2 -1
- data/app/models/spree/tax/item_tax.rb +3 -2
- data/app/models/spree/tax/order_tax.rb +3 -1
- data/app/models/spree/tax/tax_location.rb +4 -7
- data/app/models/spree/tax_rate.rb +2 -0
- data/app/models/spree/variant.rb +1 -1
- data/app/subscribers/spree/mailer_subscriber.rb +4 -0
- data/app/subscribers/spree/order_mailer_subscriber.rb +35 -0
- data/config/locales/en.yml +9 -2
- data/db/migrate/20201127212108_add_type_before_removal_to_spree_payment_methods.rb +7 -0
- data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +20 -0
- data/lib/generators/solidus/install/install_generator/bundler_context.rb +97 -0
- data/lib/generators/solidus/install/install_generator/install_frontend.rb +50 -0
- data/lib/generators/solidus/install/install_generator/support_solidus_frontend_extraction.rb +48 -0
- data/lib/generators/solidus/install/install_generator.rb +56 -49
- data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +6 -16
- data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/backend/all.js +2 -2
- data/lib/spree/app_configuration.rb +27 -0
- data/lib/spree/bus.rb +20 -0
- data/lib/spree/core/controller_helpers/auth.rb +9 -1
- data/lib/spree/core/controller_helpers/current_host.rb +1 -3
- data/lib/spree/core/controller_helpers/order.rb +10 -10
- data/lib/spree/core/controller_helpers/search.rb +1 -1
- data/lib/spree/core/engine.rb +33 -8
- data/lib/spree/core/state_machines/order.rb +1 -1
- data/lib/spree/core/stock_configuration.rb +18 -0
- data/lib/spree/core/validators/email.rb +3 -1
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +20 -0
- data/lib/spree/event/subscriber_registry.rb +4 -6
- data/lib/spree/event.rb +1 -1
- data/lib/spree/migrations.rb +1 -1
- data/lib/spree/permission_sets/default_customer.rb +8 -1
- data/lib/spree/permitted_attributes.rb +4 -4
- data/lib/spree/preferences/configuration.rb +34 -12
- data/lib/spree/preferences/preferable_class_methods.rb +1 -1
- data/lib/spree/preferences/preference_differentiator.rb +2 -1
- data/lib/spree/preferences/static_model_preferences.rb +0 -2
- data/lib/spree/rails_compatibility.rb +99 -0
- data/lib/spree/testing_support/bus_helpers.rb +101 -0
- data/lib/spree/testing_support/common_rake.rb +47 -19
- data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/backend/all.js +1 -1
- data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/frontend/all.js +1 -1
- data/lib/spree/testing_support/dummy_app.rb +6 -2
- data/lib/spree/testing_support/factories/address_factory.rb +7 -2
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +1 -1
- data/lib/spree/testing_support/factories/order_factory.rb +8 -4
- data/lib/spree/testing_support/factories/product_factory.rb +4 -1
- data/lib/spree/testing_support/factories/store_credit_factory.rb +4 -4
- data/lib/spree/testing_support/factory_bot.rb +1 -1
- data/lib/spree/testing_support/order_walkthrough.rb +5 -4
- data/lib/spree/testing_support/silence_deprecations.rb +9 -0
- data/lib/tasks/payment_method.rake +29 -0
- data/lib/tasks/solidus/delete_prices_with_nil_amount.rake +2 -2
- data/lib/tasks/solidus/split_promotions_with_any_match_policy.rake +33 -0
- data/solidus_core.gemspec +6 -2
- metadata +68 -23
- data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -10
- data/lib/generators/solidus/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +0 -9
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solidus
|
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
|
5
|
+
# Helper for extracting solidus_frontend from solidus meta-gem
|
|
6
|
+
#
|
|
7
|
+
# We're recommending users use newer solidus_starter_frontend. However,
|
|
8
|
+
# we're still shipping solidus_frontend as part of the solidus meta-gem. The
|
|
9
|
+
# reason is that we don't want users updating previous versions to see its
|
|
10
|
+
# storefront gone suddenly.
|
|
11
|
+
#
|
|
12
|
+
# In future solidus releases, solidus_frontend won't be a component anymore.
|
|
13
|
+
# However, until that happens:
|
|
14
|
+
#
|
|
15
|
+
# - For users of the new frontend, we need to prevent pulling
|
|
16
|
+
# solidus_frontend.
|
|
17
|
+
# - For users of the legacy frontend, we need to prevent Bundler from
|
|
18
|
+
# resolving it from the mono-repo while it's still there.
|
|
19
|
+
#
|
|
20
|
+
# This class is a needed companion during the deprecation
|
|
21
|
+
# path. It'll modify the user's Gemfile, breaking the solidus gem down into
|
|
22
|
+
# its components but solidus_frontend.
|
|
23
|
+
class SupportSolidusFrontendExtraction
|
|
24
|
+
attr_reader :bundler_context
|
|
25
|
+
|
|
26
|
+
def initialize(bundler_context:)
|
|
27
|
+
@bundler_context = bundler_context
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def call
|
|
31
|
+
return unless needs_to_break_down_solidus_meta_gem?
|
|
32
|
+
|
|
33
|
+
break_down_solidus_meta_gem
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def break_down_solidus_meta_gem
|
|
39
|
+
@bundler_context.break_down_components(%w[core backend api sample])
|
|
40
|
+
@bundler_context.remove(['solidus'])
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def needs_to_break_down_solidus_meta_gem?
|
|
44
|
+
@bundler_context.solidus_in_gemfile?
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -2,16 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
require 'rails/generators'
|
|
4
4
|
require 'rails/version'
|
|
5
|
+
require_relative 'install_generator/bundler_context'
|
|
6
|
+
require_relative 'install_generator/support_solidus_frontend_extraction'
|
|
7
|
+
require_relative 'install_generator/install_frontend'
|
|
5
8
|
|
|
6
9
|
module Solidus
|
|
7
10
|
# @private
|
|
8
11
|
class InstallGenerator < Rails::Generators::Base
|
|
9
12
|
CORE_MOUNT_ROUTE = "mount Spree::Core::Engine"
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
LEGACY_FRONTEND = 'solidus_frontend'
|
|
15
|
+
DEFAULT_FRONTEND = 'solidus_starter_frontend'
|
|
16
|
+
FRONTENDS = [
|
|
17
|
+
DEFAULT_FRONTEND,
|
|
18
|
+
LEGACY_FRONTEND,
|
|
19
|
+
'none'
|
|
20
|
+
].freeze
|
|
15
21
|
|
|
16
22
|
class_option :migrate, type: :boolean, default: true, banner: 'Run Solidus migrations'
|
|
17
23
|
class_option :seed, type: :boolean, default: true, banner: 'Load seed data (migrations must be run)'
|
|
@@ -24,11 +30,11 @@ module Solidus
|
|
|
24
30
|
class_option :lib_name, type: :string, default: 'spree'
|
|
25
31
|
class_option :with_authentication, type: :boolean, default: true
|
|
26
32
|
class_option :enforce_available_locales, type: :boolean, default: nil
|
|
27
|
-
class_option :
|
|
33
|
+
class_option :frontend,
|
|
28
34
|
type: :string,
|
|
29
|
-
enum:
|
|
30
|
-
default:
|
|
31
|
-
desc: "Indicates which
|
|
35
|
+
enum: FRONTENDS,
|
|
36
|
+
default: nil,
|
|
37
|
+
desc: "Indicates which frontend to install."
|
|
32
38
|
|
|
33
39
|
def self.source_paths
|
|
34
40
|
paths = superclass.source_paths
|
|
@@ -84,16 +90,10 @@ module Solidus
|
|
|
84
90
|
empty_directory 'app/assets/images'
|
|
85
91
|
|
|
86
92
|
%w{javascripts stylesheets images}.each do |path|
|
|
87
|
-
empty_directory "vendor/assets/#{path}/spree/
|
|
88
|
-
empty_directory "vendor/assets/#{path}/spree/backend" if defined? Spree::Backend || Rails.env.test?
|
|
93
|
+
empty_directory "vendor/assets/#{path}/spree/backend" if defined?(Spree::Backend) || Rails.env.test?
|
|
89
94
|
end
|
|
90
95
|
|
|
91
|
-
if defined?
|
|
92
|
-
template "vendor/assets/javascripts/spree/frontend/all.js"
|
|
93
|
-
template "vendor/assets/stylesheets/spree/frontend/all.css"
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
if defined? Spree::Backend || Rails.env.test?
|
|
96
|
+
if defined?(Spree::Backend) || Rails.env.test?
|
|
97
97
|
template "vendor/assets/javascripts/spree/backend/all.js"
|
|
98
98
|
template "vendor/assets/stylesheets/spree/backend/all.css"
|
|
99
99
|
end
|
|
@@ -104,17 +104,6 @@ module Solidus
|
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
def configure_application
|
|
107
|
-
application <<-RUBY
|
|
108
|
-
# Load application's model / class decorators
|
|
109
|
-
initializer 'spree.decorators' do |app|
|
|
110
|
-
config.to_prepare do
|
|
111
|
-
Dir.glob(Rails.root.join('app/**/*_decorator*.rb')) do |path|
|
|
112
|
-
require_dependency(path)
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
RUBY
|
|
117
|
-
|
|
118
107
|
if !options[:enforce_available_locales].nil?
|
|
119
108
|
application <<-RUBY
|
|
120
109
|
# Prevent this deprecation message: https://github.com/svenfuchs/i18n/commit/3b6e56e
|
|
@@ -133,6 +122,9 @@ module Solidus
|
|
|
133
122
|
Solidus has a default authentication extension that uses Devise.
|
|
134
123
|
You can find more info at https://github.com/solidusio/solidus_auth_devise.
|
|
135
124
|
|
|
125
|
+
Regardless of what you answer here, it'll be installed if you choose
|
|
126
|
+
solidus_starter_frontend as your storefront in a later step.
|
|
127
|
+
|
|
136
128
|
Would you like to install it? (Y/n)"))
|
|
137
129
|
|
|
138
130
|
@plugins_to_be_installed << 'solidus_auth_devise'
|
|
@@ -140,25 +132,6 @@ module Solidus
|
|
|
140
132
|
end
|
|
141
133
|
end
|
|
142
134
|
|
|
143
|
-
def install_payment_method
|
|
144
|
-
name = options[:payment_method]
|
|
145
|
-
|
|
146
|
-
unless options[:auto_accept]
|
|
147
|
-
available_names = PAYMENT_METHODS.keys
|
|
148
|
-
|
|
149
|
-
name = ask("
|
|
150
|
-
You can select a payment method to be included in the installation process.
|
|
151
|
-
Please select a payment method name:", limited_to: available_names, default: available_names.first)
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
gem_name = PAYMENT_METHODS.fetch(name)
|
|
155
|
-
|
|
156
|
-
if gem_name
|
|
157
|
-
@plugins_to_be_installed << gem_name
|
|
158
|
-
@plugin_generators_to_run << "#{gem_name}:install"
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
|
|
162
135
|
def include_seed_data
|
|
163
136
|
append_file "db/seeds.rb", <<-RUBY.strip_heredoc
|
|
164
137
|
|
|
@@ -182,7 +155,7 @@ module Solidus
|
|
|
182
155
|
gem plugin_name
|
|
183
156
|
end
|
|
184
157
|
|
|
185
|
-
bundle_cleanly{ run "bundle install" } if @plugins_to_be_installed.any?
|
|
158
|
+
BundlerContext.bundle_cleanly { run "bundle install" } if @plugins_to_be_installed.any?
|
|
186
159
|
run "spring stop" if defined?(Spring)
|
|
187
160
|
|
|
188
161
|
@plugin_generators_to_run.each do |plugin_generator_name|
|
|
@@ -190,6 +163,22 @@ module Solidus
|
|
|
190
163
|
end
|
|
191
164
|
end
|
|
192
165
|
|
|
166
|
+
def install_frontend
|
|
167
|
+
return if options[:frontend] == 'none'
|
|
168
|
+
|
|
169
|
+
bundler_context = BundlerContext.new
|
|
170
|
+
|
|
171
|
+
frontend = detect_frontend_to_install(bundler_context)
|
|
172
|
+
|
|
173
|
+
support_solidus_frontend_extraction(bundler_context) unless frontend == LEGACY_FRONTEND
|
|
174
|
+
|
|
175
|
+
say_status :installing, frontend
|
|
176
|
+
|
|
177
|
+
InstallFrontend.
|
|
178
|
+
new(bundler_context: bundler_context, generator_context: self).
|
|
179
|
+
call(frontend, installer_adds_auth: @plugins_to_be_installed.include?('solidus_auth_devise'))
|
|
180
|
+
end
|
|
181
|
+
|
|
193
182
|
def run_migrations
|
|
194
183
|
if @run_migrations
|
|
195
184
|
say_status :running, "migrations"
|
|
@@ -258,8 +247,26 @@ module Solidus
|
|
|
258
247
|
|
|
259
248
|
private
|
|
260
249
|
|
|
261
|
-
def
|
|
262
|
-
|
|
250
|
+
def detect_frontend_to_install(bundler_context)
|
|
251
|
+
ENV['FRONTEND'] ||
|
|
252
|
+
options[:frontend] ||
|
|
253
|
+
(bundler_context.component_in_gemfile?(:frontend) && LEGACY_FRONTEND) ||
|
|
254
|
+
(options[:auto_accept] && DEFAULT_FRONTEND) ||
|
|
255
|
+
ask(<<~MSG.indent(8), limited_to: FRONTENDS, default: DEFAULT_FRONTEND)
|
|
256
|
+
|
|
257
|
+
Which frontend would you like to use? solidus_starter_frontend is
|
|
258
|
+
recommended. However, some extensions are still only compatible with
|
|
259
|
+
the now deprecated solidus_frontend.
|
|
260
|
+
|
|
261
|
+
MSG
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def support_solidus_frontend_extraction(bundler_context)
|
|
265
|
+
say_status "break down", "solidus"
|
|
266
|
+
|
|
267
|
+
SupportSolidusFrontendExtraction.
|
|
268
|
+
new(bundler_context: bundler_context).
|
|
269
|
+
call
|
|
263
270
|
end
|
|
264
271
|
end
|
|
265
272
|
end
|
|
@@ -31,16 +31,6 @@ Spree.config do |config|
|
|
|
31
31
|
# to a custom users role:
|
|
32
32
|
# config.roles.assign_permissions :role_name, ['Spree::PermissionSets::CustomPermissionSet']
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
# Frontend:
|
|
36
|
-
|
|
37
|
-
# Custom logo for the frontend
|
|
38
|
-
# config.logo = "logo/solidus.svg"
|
|
39
|
-
|
|
40
|
-
# Template to use when rendering layout
|
|
41
|
-
# config.layout = "spree/layouts/spree_application"
|
|
42
|
-
|
|
43
|
-
|
|
44
34
|
# Admin:
|
|
45
35
|
|
|
46
36
|
# Custom logo for the admin
|
|
@@ -62,12 +52,6 @@ Spree.config do |config|
|
|
|
62
52
|
# )
|
|
63
53
|
end
|
|
64
54
|
|
|
65
|
-
<% if defined?(Spree::Frontend::Engine) -%>
|
|
66
|
-
Spree::Frontend::Config.configure do |config|
|
|
67
|
-
config.locale = 'en'
|
|
68
|
-
end
|
|
69
|
-
<% end -%>
|
|
70
|
-
|
|
71
55
|
<% if defined?(Spree::Backend::Engine) -%>
|
|
72
56
|
Spree::Backend::Config.configure do |config|
|
|
73
57
|
config.locale = 'en'
|
|
@@ -80,6 +64,12 @@ Spree::Backend::Config.configure do |config|
|
|
|
80
64
|
# 'icon-name',
|
|
81
65
|
# url: 'https://solidus.io/'
|
|
82
66
|
# )
|
|
67
|
+
|
|
68
|
+
# Custom frontend product path
|
|
69
|
+
#
|
|
70
|
+
# config.frontend_product_path = ->(template_context, product) {
|
|
71
|
+
# template_context.spree.product_path(product)
|
|
72
|
+
# }
|
|
83
73
|
end
|
|
84
74
|
<% end -%>
|
|
85
75
|
|
data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/backend/all.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// This is a manifest file that'll be compiled into including all the files listed below.
|
|
2
|
-
// Add new JavaScript
|
|
2
|
+
// Add new JavaScript code in separate files in this directory and they'll automatically
|
|
3
3
|
// be included in the compiled file accessible from http://example.com/assets/application.js
|
|
4
4
|
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
5
5
|
// the compiled file.
|
|
6
6
|
//
|
|
7
|
-
//= require
|
|
7
|
+
//= require jquery3
|
|
8
8
|
//= require rails-ujs
|
|
9
9
|
//= require spree/backend
|
|
10
10
|
//= require_tree .
|
|
@@ -60,6 +60,11 @@ module Spree
|
|
|
60
60
|
# @return [Boolean] When false, customers must create an account to complete an order (default: +true+)
|
|
61
61
|
preference :allow_guest_checkout, :boolean, default: true
|
|
62
62
|
|
|
63
|
+
# @!attribute [rw] allow_promotions_any_match_policy
|
|
64
|
+
# @return [Boolean] When false, admins cannot create promotions with an "any" match policy (default: +false+)
|
|
65
|
+
# Create individual, separate promotions for each of your rules instead.
|
|
66
|
+
preference :allow_promotions_any_match_policy, :boolean, default: false
|
|
67
|
+
|
|
63
68
|
# @!attribute [rw] guest_token_cookie_options
|
|
64
69
|
# @return [Hash] Add additional guest_token cookie options here (ie. domain or path)
|
|
65
70
|
preference :guest_token_cookie_options, :hash, default: {}
|
|
@@ -145,6 +150,10 @@ module Spree
|
|
|
145
150
|
# @return [String] Two-letter ISO code of a {Spree::Country} to assumed as the country of an unidentified customer (default: "US")
|
|
146
151
|
preference :default_country_iso, :string, default: 'US'
|
|
147
152
|
|
|
153
|
+
# @!attribute [rw] default_email_regexp
|
|
154
|
+
# @return [Regexp] Regex to be used in email validations, for example in Spree::EmailValidator
|
|
155
|
+
preference :default_email_regexp, :regexp, default: URI::MailTo::EMAIL_REGEXP
|
|
156
|
+
|
|
148
157
|
# @!attribute [rw] generate_api_key_for_all_roles
|
|
149
158
|
# @return [Boolean] Allow generating api key automatically for user
|
|
150
159
|
# at role_user creation for all roles. (default: +false+)
|
|
@@ -279,6 +288,13 @@ module Spree
|
|
|
279
288
|
# @return [] Track on_hand values for variants / products. (default: true)
|
|
280
289
|
preference :track_inventory_levels, :boolean, default: true
|
|
281
290
|
|
|
291
|
+
# @!attribute [rw] use_legacy_events
|
|
292
|
+
# Before v3.2, Solidus used a custom pub/sub implementation based on
|
|
293
|
+
# ActiveSupport::Notifications. Now, we internally use and recommend
|
|
294
|
+
# [Omnes](https://github.com/nebulab/omnes). This preference allows falling
|
|
295
|
+
# back to the old system.
|
|
296
|
+
# @return [Boolean]
|
|
297
|
+
versioned_preference :use_legacy_events, :boolean, initial_value: true, boundaries: { "3.2.0.alpha" => false }
|
|
282
298
|
|
|
283
299
|
# Other configurations
|
|
284
300
|
|
|
@@ -541,6 +557,17 @@ module Spree
|
|
|
541
557
|
# Enumerable of taxons adhering to the present_taxon_class interface
|
|
542
558
|
class_name_attribute :taxon_attachment_module, default: 'Spree::Taxon::ActiveStorageAttachment'
|
|
543
559
|
|
|
560
|
+
# Configures the absolute path that contains the Solidus engine
|
|
561
|
+
# migrations. This will be checked at app boot to confirm that all Solidus
|
|
562
|
+
# migrations are installed.
|
|
563
|
+
#
|
|
564
|
+
# @!attribute [rw] migration_path
|
|
565
|
+
# @return [Pathname] the configured path. (default: `Rails.root.join('db', 'migrate')`)
|
|
566
|
+
attr_writer :migration_path
|
|
567
|
+
def migration_path
|
|
568
|
+
@migration_path ||= ::Rails.root.join('db', 'migrate')
|
|
569
|
+
end
|
|
570
|
+
|
|
544
571
|
# Allows providing your own class instance for generating order numbers.
|
|
545
572
|
#
|
|
546
573
|
# @!attribute [rw] order_number_generator
|
data/lib/spree/bus.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'omnes'
|
|
2
|
+
|
|
3
|
+
module Spree
|
|
4
|
+
# Global [Omnes](https://github.com/nebulab/omnes) bus.
|
|
5
|
+
#
|
|
6
|
+
# This is used for internal events, while host applications are also able to
|
|
7
|
+
# use it.
|
|
8
|
+
#
|
|
9
|
+
# It has some modifications to support internal usage of the legacy event
|
|
10
|
+
# system {see Spree::AppConfiguration#use_legacy_events}.
|
|
11
|
+
Bus = Omnes::Bus.new
|
|
12
|
+
Bus.define_singleton_method(:publish) do |*args, **kwargs, &block|
|
|
13
|
+
if Spree::Config.use_legacy_events
|
|
14
|
+
Spree::Event.fire(*args, **kwargs, &block)
|
|
15
|
+
else
|
|
16
|
+
# Override caller_location to point to the actual event publisher
|
|
17
|
+
super(*args, **kwargs, caller_location: caller_locations(1)[0], &block)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -18,6 +18,7 @@ module Spree
|
|
|
18
18
|
included do
|
|
19
19
|
before_action :set_guest_token
|
|
20
20
|
helper_method :try_spree_current_user
|
|
21
|
+
helper_method :spree_current_user
|
|
21
22
|
|
|
22
23
|
class_attribute :unauthorized_redirect
|
|
23
24
|
self.unauthorized_redirect = -> do
|
|
@@ -32,7 +33,7 @@ module Spree
|
|
|
32
33
|
|
|
33
34
|
# Needs to be overriden so that we use Spree's Ability rather than anyone else's.
|
|
34
35
|
def current_ability
|
|
35
|
-
@current_ability ||= Spree::Ability.new(
|
|
36
|
+
@current_ability ||= Spree::Ability.new(spree_current_user)
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
def redirect_back_or_default(default)
|
|
@@ -53,6 +54,11 @@ module Spree
|
|
|
53
54
|
Spree::UserLastUrlStorer.new(self).store_location
|
|
54
55
|
end
|
|
55
56
|
|
|
57
|
+
# Auth extensions are expected to define it, otherwise it's a no-op
|
|
58
|
+
def spree_current_user
|
|
59
|
+
defined?(super) ? super : nil
|
|
60
|
+
end
|
|
61
|
+
|
|
56
62
|
# proxy method to *possible* spree_current_user method
|
|
57
63
|
# Authentication extensions (such as spree_auth_devise) are meant to provide spree_current_user
|
|
58
64
|
def try_spree_current_user
|
|
@@ -65,6 +71,8 @@ module Spree
|
|
|
65
71
|
current_spree_user
|
|
66
72
|
end
|
|
67
73
|
end
|
|
74
|
+
|
|
75
|
+
deprecate try_spree_current_user: :spree_current_user, deprecator: Spree::Deprecation
|
|
68
76
|
end
|
|
69
77
|
end
|
|
70
78
|
end
|
|
@@ -24,9 +24,9 @@ module Spree
|
|
|
24
24
|
|
|
25
25
|
if should_build && (@current_order.nil? || @current_order.completed?)
|
|
26
26
|
@current_order = Spree::Order.new(new_order_params)
|
|
27
|
-
@current_order.user ||=
|
|
27
|
+
@current_order.user ||= spree_current_user
|
|
28
28
|
# See issue https://github.com/spree/spree/issues/3346 for reasons why this line is here
|
|
29
|
-
@current_order.created_by ||=
|
|
29
|
+
@current_order.created_by ||= spree_current_user
|
|
30
30
|
@current_order.save! if should_create
|
|
31
31
|
end
|
|
32
32
|
|
|
@@ -38,15 +38,15 @@ module Spree
|
|
|
38
38
|
|
|
39
39
|
def associate_user
|
|
40
40
|
@order ||= current_order
|
|
41
|
-
if
|
|
42
|
-
@order.associate_user!(
|
|
41
|
+
if spree_current_user && @order
|
|
42
|
+
@order.associate_user!(spree_current_user) if @order.user.blank? || @order.email.blank?
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def set_current_order
|
|
47
|
-
if
|
|
48
|
-
|
|
49
|
-
current_order.merge!(order,
|
|
47
|
+
if spree_current_user && current_order
|
|
48
|
+
spree_current_user.orders.by_store(current_store).incomplete.where('id != ?', current_order.id).each do |order|
|
|
49
|
+
current_order.merge!(order, spree_current_user)
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
end
|
|
@@ -58,11 +58,11 @@ module Spree
|
|
|
58
58
|
private
|
|
59
59
|
|
|
60
60
|
def last_incomplete_order
|
|
61
|
-
@last_incomplete_order ||=
|
|
61
|
+
@last_incomplete_order ||= spree_current_user.last_incomplete_spree_order(store: current_store)
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def current_order_params
|
|
65
|
-
{ currency: current_pricing_options.currency, guest_token: cookies.signed[:guest_token], store_id: current_store.id, user_id:
|
|
65
|
+
{ currency: current_pricing_options.currency, guest_token: cookies.signed[:guest_token], store_id: current_store.id, user_id: spree_current_user.try(:id) }
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
def new_order_params
|
|
@@ -76,7 +76,7 @@ module Spree
|
|
|
76
76
|
order = Spree::Order.incomplete.lock(should_lock).find_by(current_order_params)
|
|
77
77
|
|
|
78
78
|
# Find any incomplete orders for the current user
|
|
79
|
-
if order.nil? &&
|
|
79
|
+
if order.nil? && spree_current_user
|
|
80
80
|
order = last_incomplete_order
|
|
81
81
|
end
|
|
82
82
|
|
|
@@ -6,7 +6,7 @@ module Spree
|
|
|
6
6
|
module Search
|
|
7
7
|
def build_searcher(params)
|
|
8
8
|
Spree::Config.searcher_class.new(params).tap do |searcher|
|
|
9
|
-
searcher.current_user =
|
|
9
|
+
searcher.current_user = spree_current_user
|
|
10
10
|
searcher.pricing_options = current_pricing_options
|
|
11
11
|
end
|
|
12
12
|
end
|
data/lib/spree/core/engine.rb
CHANGED
|
@@ -46,18 +46,33 @@ module Spree
|
|
|
46
46
|
]
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
initializer "spree.core.checking_migrations",
|
|
49
|
+
initializer "spree.core.checking_migrations", after: :load_config_initializers do |_app|
|
|
50
50
|
Migrations.new(config, engine_name).check
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
# Setup
|
|
54
|
-
initializer 'spree.core.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
# Setup pub/sub
|
|
54
|
+
initializer 'spree.core.pub_sub' do |app|
|
|
55
|
+
if Spree::Config.use_legacy_events
|
|
56
|
+
app.reloader.to_prepare do
|
|
57
|
+
Spree::Event.activate_autoloadable_subscribers
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
app.reloader.before_class_unload do
|
|
61
|
+
Spree::Event.deactivate_all_subscribers
|
|
62
|
+
end
|
|
63
|
+
else
|
|
64
|
+
app.reloader.to_prepare do
|
|
65
|
+
Spree::Bus.clear
|
|
58
66
|
|
|
59
|
-
|
|
60
|
-
|
|
67
|
+
%i[
|
|
68
|
+
order_finalized
|
|
69
|
+
order_recalculated
|
|
70
|
+
reimbursement_reimbursed
|
|
71
|
+
reimbursement_errored
|
|
72
|
+
].each { |event_name| Spree::Bus.register(event_name) }
|
|
73
|
+
|
|
74
|
+
Spree::OrderMailerSubscriber.new.subscribe_to(Spree::Bus)
|
|
75
|
+
end
|
|
61
76
|
end
|
|
62
77
|
end
|
|
63
78
|
|
|
@@ -81,6 +96,16 @@ module Spree
|
|
|
81
96
|
Spree::UsersController.protect_from_forgery with: :exception
|
|
82
97
|
end
|
|
83
98
|
end
|
|
99
|
+
|
|
100
|
+
config.after_initialize do
|
|
101
|
+
if Spree::Config.use_legacy_events && !ENV['CI']
|
|
102
|
+
Spree::Deprecation.warn <<~MSG
|
|
103
|
+
Your Solidus store is using the legacy event system. You're
|
|
104
|
+
encouraged to switch to the new event bus. After you're done, you
|
|
105
|
+
can remove the `use_legacy_events` setting from `spree.rb`.
|
|
106
|
+
MSG
|
|
107
|
+
end
|
|
108
|
+
end
|
|
84
109
|
end
|
|
85
110
|
end
|
|
86
111
|
end
|
|
@@ -119,7 +119,7 @@ module Spree
|
|
|
119
119
|
before_transition to: :complete, do: :process_payments_before_complete
|
|
120
120
|
end
|
|
121
121
|
|
|
122
|
-
after_transition to: :complete, do: :finalize
|
|
122
|
+
after_transition to: :complete, do: :finalize
|
|
123
123
|
after_transition to: :resumed, do: :after_resume
|
|
124
124
|
after_transition to: :canceled, do: :after_cancel
|
|
125
125
|
|
|
@@ -8,6 +8,9 @@ module Spree
|
|
|
8
8
|
attr_writer :location_filter_class
|
|
9
9
|
attr_writer :location_sorter_class
|
|
10
10
|
attr_writer :allocator_class
|
|
11
|
+
attr_writer :inventory_unit_builder_class
|
|
12
|
+
attr_writer :availability_validator_class
|
|
13
|
+
attr_writer :inventory_validator_class
|
|
11
14
|
|
|
12
15
|
def coordinator_class
|
|
13
16
|
@coordinator_class ||= '::Spree::Stock::SimpleCoordinator'
|
|
@@ -33,6 +36,21 @@ module Spree
|
|
|
33
36
|
@allocator_class ||= '::Spree::Stock::Allocator::OnHandFirst'
|
|
34
37
|
@allocator_class.constantize
|
|
35
38
|
end
|
|
39
|
+
|
|
40
|
+
def inventory_unit_builder_class
|
|
41
|
+
@inventory_unit_builder_class ||= '::Spree::Stock::InventoryUnitBuilder'
|
|
42
|
+
@inventory_unit_builder_class.constantize
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def availability_validator_class
|
|
46
|
+
@availability_validator_class ||= '::Spree::Stock::AvailabilityValidator'
|
|
47
|
+
@availability_validator_class.constantize
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def inventory_validator_class
|
|
51
|
+
@inventory_validator_class ||= '::Spree::Stock::InventoryValidator'
|
|
52
|
+
@inventory_validator_class.constantize
|
|
53
|
+
end
|
|
36
54
|
end
|
|
37
55
|
end
|
|
38
56
|
end
|
|
@@ -13,9 +13,11 @@ module Spree
|
|
|
13
13
|
#
|
|
14
14
|
class EmailValidator < ActiveModel::EachValidator
|
|
15
15
|
EMAIL_REGEXP = URI::MailTo::EMAIL_REGEXP
|
|
16
|
+
# Use Spree::Config.default_email_regexp instead
|
|
17
|
+
deprecate_constant :EMAIL_REGEXP
|
|
16
18
|
|
|
17
19
|
def validate_each(record, attribute, value)
|
|
18
|
-
unless
|
|
20
|
+
unless Spree::Config.default_email_regexp.match? value
|
|
19
21
|
record.errors.add(attribute, :invalid, **{ value: value }.merge!(options))
|
|
20
22
|
end
|
|
21
23
|
end
|
data/lib/spree/core/version.rb
CHANGED
data/lib/spree/core.rb
CHANGED
|
@@ -21,6 +21,7 @@ require 'ransack'
|
|
|
21
21
|
require 'state_machines-activerecord'
|
|
22
22
|
|
|
23
23
|
require 'spree/deprecation'
|
|
24
|
+
require 'spree/rails_compatibility'
|
|
24
25
|
|
|
25
26
|
# This is required because ActiveModel::Validations#invalid? conflicts with the
|
|
26
27
|
# invalid state of a Payment. In the future this should be removed.
|
|
@@ -84,6 +85,24 @@ module Spree
|
|
|
84
85
|
end
|
|
85
86
|
end
|
|
86
87
|
|
|
88
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.7")
|
|
89
|
+
Spree::Deprecation.warn <<~HEREDOC
|
|
90
|
+
Ruby 2.5 & Ruby 2.6 (both EOL) are deprecated and will not be supported anymore from the next Solidus version.
|
|
91
|
+
Please, upgrade to a more recent Ruby version.
|
|
92
|
+
Read more on the release notes for different Ruby versions here:
|
|
93
|
+
https://www.ruby-lang.org/en/downloads/releases/
|
|
94
|
+
HEREDOC
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
if Gem::Version.new(Rails.version) < Gem::Version.new('6.0')
|
|
98
|
+
Spree::Deprecation.warn <<~HEREDOC
|
|
99
|
+
Rails 5.2 (EOL) is deprecated and will not be supported anymore from the next Solidus version.
|
|
100
|
+
Please, upgrade to a more recent Rails version.
|
|
101
|
+
Read more on upgrading from Rails 5.2 to Rails 6.0 here:
|
|
102
|
+
https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-5-2-to-rails-6-0
|
|
103
|
+
HEREDOC
|
|
104
|
+
end
|
|
105
|
+
|
|
87
106
|
require 'spree/core/version'
|
|
88
107
|
|
|
89
108
|
require 'spree/core/active_merchant_dependencies'
|
|
@@ -95,6 +114,7 @@ require 'spree/core/environment'
|
|
|
95
114
|
require 'spree/migrations'
|
|
96
115
|
require 'spree/migration_helpers'
|
|
97
116
|
require 'spree/event'
|
|
117
|
+
require 'spree/bus'
|
|
98
118
|
require 'spree/core/engine'
|
|
99
119
|
|
|
100
120
|
require 'spree/i18n'
|
|
@@ -64,13 +64,11 @@ module Spree
|
|
|
64
64
|
# Loading the files has the side effect of adding their module to the
|
|
65
65
|
# list in Spree::Event.subscribers.
|
|
66
66
|
def require_subscriber_files
|
|
67
|
-
|
|
67
|
+
require_dependency(
|
|
68
|
+
Spree::Core::Engine.root.join('app', 'subscribers', 'spree', 'mailer_subscriber.rb')
|
|
69
|
+
)
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
# rubocop:disable Rails/DynamicFindBy
|
|
71
|
-
solidus_core_dir = Gem::Specification.find_by_name('solidus_core').gem_dir
|
|
72
|
-
# rubocop:enable Rails/DynamicFindBy
|
|
73
|
-
Dir.glob(File.join(solidus_core_dir, pattern)) { |c| require_dependency(c.to_s) }
|
|
71
|
+
pattern = "app/subscribers/**/*_subscriber.rb"
|
|
74
72
|
|
|
75
73
|
# Load application subscribers, only when the flag is set to true:
|
|
76
74
|
if Spree::Config.events.autoload_subscribers
|
data/lib/spree/event.rb
CHANGED
|
@@ -21,7 +21,7 @@ module Spree
|
|
|
21
21
|
#
|
|
22
22
|
# @example Trigger an event named 'order_finalized'
|
|
23
23
|
# Spree::Event.fire 'order_finalized', order: @order do
|
|
24
|
-
# @order.
|
|
24
|
+
# @order.complete!
|
|
25
25
|
# end
|
|
26
26
|
def fire(event_name, opts = {})
|
|
27
27
|
adapter.fire normalize_name(event_name), opts do
|