solidus_core 3.2.4 → 3.3.0

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.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +6 -2
  3. data/app/controllers/spree/base_controller.rb +1 -1
  4. data/app/models/concerns/spree/active_storage_adapter/attachment.rb +4 -0
  5. data/app/models/concerns/spree/ransackable_attributes.rb +24 -4
  6. data/app/models/concerns/spree/user_methods.rb +2 -2
  7. data/app/models/spree/address.rb +1 -1
  8. data/app/models/spree/calculator/flat_fee.rb +21 -0
  9. data/app/models/spree/country.rb +1 -1
  10. data/app/models/spree/credit_card.rb +1 -1
  11. data/app/models/spree/customer_return.rb +1 -1
  12. data/app/models/spree/line_item.rb +2 -2
  13. data/app/models/spree/option_type.rb +1 -1
  14. data/app/models/spree/option_value.rb +1 -1
  15. data/app/models/spree/order/number_generator.rb +7 -1
  16. data/app/models/spree/order.rb +4 -3
  17. data/app/models/spree/order_promotion.rb +1 -1
  18. data/app/models/spree/order_updater.rb +11 -2
  19. data/app/models/spree/payment/processing.rb +58 -55
  20. data/app/models/spree/payment_method/bogus_credit_card.rb +6 -7
  21. data/app/models/spree/payment_method/simple_bogus_credit_card.rb +8 -0
  22. data/app/models/spree/payment_method.rb +16 -10
  23. data/app/models/spree/price.rb +1 -1
  24. data/app/models/spree/product.rb +3 -3
  25. data/app/models/spree/product_property.rb +1 -1
  26. data/app/models/spree/promotion/actions/free_shipping.rb +1 -0
  27. data/app/models/spree/promotion/order_adjustments_recalculator.rb +92 -0
  28. data/app/models/spree/promotion.rb +2 -2
  29. data/app/models/spree/promotion_code.rb +1 -1
  30. data/app/models/spree/property.rb +1 -1
  31. data/app/models/spree/return_authorization.rb +1 -1
  32. data/app/models/spree/shipment.rb +2 -2
  33. data/app/models/spree/state.rb +1 -1
  34. data/app/models/spree/stock_item.rb +1 -1
  35. data/app/models/spree/stock_location.rb +1 -1
  36. data/app/models/spree/stock_movement.rb +2 -2
  37. data/app/models/spree/store_credit_prioritizer.rb +17 -0
  38. data/app/models/spree/tax/tax_helpers.rb +2 -2
  39. data/app/models/spree/tax_calculator/default.rb +31 -0
  40. data/app/models/spree/tax_rate.rb +8 -1
  41. data/app/models/spree/taxon.rb +1 -1
  42. data/app/models/spree/taxonomy.rb +1 -1
  43. data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +1 -1
  44. data/app/models/spree/variant.rb +25 -5
  45. data/app/models/spree/zone.rb +1 -1
  46. data/config/locales/en.yml +17 -2
  47. data/db/migrate/20220805202442_add_level_to_spree_tax_rates.rb +5 -0
  48. data/db/migrate/20221123152807_add_shipping_category_to_spree_variants.rb +5 -0
  49. data/db/seeds.rb +4 -1
  50. data/lib/generators/solidus/install/app_templates/authentication/custom.rb +21 -0
  51. data/lib/generators/solidus/install/app_templates/authentication/devise.rb +16 -0
  52. data/lib/generators/solidus/install/app_templates/authentication/existing.rb +10 -0
  53. data/lib/generators/solidus/install/app_templates/authentication/none.rb +1 -0
  54. data/lib/generators/solidus/install/app_templates/frontend/break_down_solidus_gem.rb +54 -0
  55. data/lib/generators/solidus/install/app_templates/frontend/classic.rb +16 -0
  56. data/lib/generators/solidus/install/app_templates/frontend/none.rb +2 -0
  57. data/lib/generators/solidus/install/app_templates/frontend/starter.rb +3 -0
  58. data/lib/generators/solidus/install/app_templates/payment_method/bolt.rb +13 -0
  59. data/lib/generators/solidus/install/app_templates/payment_method/none.rb +1 -0
  60. data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +10 -0
  61. data/lib/generators/solidus/install/install_generator.rb +233 -187
  62. data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +3 -4
  63. data/lib/generators/spree/custom_user/custom_user_generator.rb +6 -4
  64. data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +2 -6
  65. data/lib/generators/spree/custom_user/templates/migration.rb.tt +7 -3
  66. data/lib/generators/spree/dummy/dummy_generator.rb +10 -8
  67. data/lib/generators/spree/dummy/templates/rails/database.yml +6 -12
  68. data/lib/spree/app_configuration.rb +23 -0
  69. data/lib/spree/core/controller_helpers/current_host.rb +5 -1
  70. data/lib/spree/core/engine.rb +1 -0
  71. data/lib/spree/core/search/base.rb +17 -8
  72. data/lib/spree/core/version.rb +2 -2
  73. data/lib/spree/core.rb +1 -21
  74. data/lib/spree/migrations.rb +12 -10
  75. data/lib/spree/permitted_attributes.rb +4 -1
  76. data/lib/spree/preferences/preferable.rb +5 -0
  77. data/lib/spree/preferences/preferable_class_methods.rb +2 -2
  78. data/lib/spree/preferences/static_model_preferences.rb +25 -8
  79. data/lib/spree/rails_compatibility.rb +0 -17
  80. data/lib/spree/testing_support/common_rake.rb +27 -7
  81. data/lib/spree/testing_support/dummy_app.rb +2 -2
  82. data/lib/spree/testing_support/factories/address_factory.rb +9 -11
  83. data/lib/spree/testing_support/factories/calculator_factory.rb +3 -0
  84. data/lib/spree/testing_support/factories/country_factory.rb +1 -2
  85. data/lib/spree/testing_support/factories/promotion_factory.rb +28 -14
  86. data/lib/spree/testing_support/factories/state_factory.rb +8 -2
  87. data/lib/spree/testing_support/factory_bot.rb +1 -1
  88. data/lib/spree/testing_support/order_walkthrough.rb +1 -1
  89. data/lib/tasks/colorado_delivery_fee.rake +28 -0
  90. data/solidus_core.gemspec +2 -2
  91. metadata +37 -23
  92. data/lib/generators/solidus/install/install_generator/bundler_context.rb +0 -97
  93. data/lib/generators/solidus/install/install_generator/install_frontend.rb +0 -59
  94. data/lib/generators/solidus/install/install_generator/support_solidus_frontend_extraction.rb +0 -48
@@ -0,0 +1,3 @@
1
+ apply "#{__dir__}/break_down_solidus_gem.rb"
2
+ run_bundle
3
+ apply 'https://github.com/solidusio/solidus_starter_frontend/raw/main/template.rb'
@@ -0,0 +1,13 @@
1
+ unless Bundler.locked_gems.dependencies['solidus_frontend']
2
+ say_status :warning, "Support for frontends other than `solidus_frontend` by `solidus_bolt` is still in progress.", :yellow
3
+ end
4
+
5
+ unless Bundler.locked_gems.dependencies['solidus_auth_devise']
6
+ say_status :warning, "Running solidus_bolt without solidus_auth_devise is not supported.", :yellow
7
+ end
8
+
9
+ unless Bundler.locked_gems.dependencies['solidus_bolt']
10
+ bundle_command 'add solidus_bolt'
11
+ end
12
+
13
+ generate 'solidus_bolt:install'
@@ -0,0 +1,10 @@
1
+ unless Bundler.locked_gems.dependencies['solidus_frontend']
2
+ say_status :warning, "Support for frontends other than `solidus_frontend` by `solidus_paypal_commerce_platform` is still in progress.", :yellow
3
+ end
4
+
5
+ unless Bundler.locked_gems.dependencies['solidus_paypal_commerce_platform']
6
+ version = @selected_frontend == 'classic' ? '< 1' : '~> 1.0'
7
+ bundle_command "add solidus_paypal_commerce_platform --version='#{version}'"
8
+ end
9
+
10
+ generate 'solidus_paypal_commerce_platform:install'
@@ -1,68 +1,90 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails/generators'
4
3
  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'
4
+ require 'rails/generators'
5
+ require 'rails/generators/app_base'
8
6
 
9
7
  module Solidus
10
8
  # @private
11
- class InstallGenerator < Rails::Generators::Base
12
- CORE_MOUNT_ROUTE = "mount Spree::Core::Engine"
9
+ class InstallGenerator < Rails::Generators::AppBase
10
+ argument :app_path, type: :string, default: Rails.root
13
11
 
14
- LEGACY_FRONTEND = 'solidus_frontend'
15
- DEFAULT_FRONTEND = 'solidus_starter_frontend'
16
- FRONTENDS = [
17
- DEFAULT_FRONTEND,
18
- LEGACY_FRONTEND,
19
- 'none'
20
- ].freeze
12
+ CORE_MOUNT_ROUTE = "mount Spree::Core::Engine"
21
13
 
22
- PAYMENT_METHODS = {
23
- 'paypal' => 'solidus_paypal_commerce_platform',
24
- 'bolt' => 'solidus_bolt',
25
- 'none' => nil,
26
- }
14
+ FRONTENDS = %w[
15
+ none
16
+ classic
17
+ starter
18
+ ]
19
+
20
+ LEGACY_FRONTENDS = %w[
21
+ solidus_starter_frontend
22
+ solidus_frontend
23
+ ]
24
+
25
+ AUTHENTICATIONS = %w[
26
+ devise
27
+ existing
28
+ custom
29
+ none
30
+ ]
31
+
32
+ PAYMENT_METHODS = %w[
33
+ paypal
34
+ bolt
35
+ none
36
+ ]
27
37
 
28
38
  class_option :migrate, type: :boolean, default: true, banner: 'Run Solidus migrations'
29
39
  class_option :seed, type: :boolean, default: true, banner: 'Load seed data (migrations must be run)'
30
- class_option :sample, type: :boolean, default: true, banner: 'Load sample data (migrations must be run)'
31
- class_option :active_storage, type: :boolean, default: Rails.gem_version >= Gem::Version.new("6.1.0"), banner: 'Install ActiveStorage as image attachments handler for products and taxons'
40
+ class_option :sample, type: :boolean, default: true, banner: 'Load sample data (migrations and seeds must be run)'
41
+ class_option :active_storage, type: :boolean, default: (
42
+ Rails.gem_version >= Gem::Version.new("6.1.0")
43
+ ), banner: 'Install ActiveStorage as image attachments handler for products and taxons'
32
44
  class_option :auto_accept, type: :boolean
33
45
  class_option :user_class, type: :string
34
46
  class_option :admin_email, type: :string
35
47
  class_option :admin_password, type: :string
36
- class_option :lib_name, type: :string, default: 'spree'
37
- class_option :with_authentication, type: :boolean, default: nil
38
- class_option :enforce_available_locales, type: :boolean, default: nil
39
- class_option :frontend,
40
- type: :string,
41
- enum: FRONTENDS,
42
- default: nil,
43
- desc: "Indicates which frontend to install."
44
- class_option :payment_method,
45
- type: :string,
46
- enum: PAYMENT_METHODS.keys,
47
- default: nil,
48
- desc: "Indicates which payment method to install."
49
-
50
- def self.source_paths
51
- paths = superclass.source_paths
52
- paths << File.expand_path('../templates', "../../#{__FILE__}")
53
- paths << File.expand_path('../templates', "../#{__FILE__}")
54
- paths << File.expand_path('templates', __dir__)
55
- paths.flatten
48
+
49
+ class_option :frontend, type: :string, enum: FRONTENDS + LEGACY_FRONTENDS, default: nil, desc: "Indicates which frontend to install."
50
+ class_option :authentication, type: :string, enum: AUTHENTICATIONS, default: nil, desc: "Indicates which authentication system to install."
51
+ class_option :payment_method, type: :string, enum: PAYMENT_METHODS, default: nil, desc: "Indicates which payment method to install."
52
+
53
+ # DEPRECATED
54
+ class_option :with_authentication, type: :boolean, hide: true, default: nil
55
+ class_option :enforce_available_locales, type: :boolean, hide: true, default: nil
56
+ class_option :lib_name, type: :string, hide: true, default: nil
57
+
58
+ source_root "#{__dir__}/templates"
59
+
60
+ def self.exit_on_failure?
61
+ true
56
62
  end
57
63
 
58
64
  def prepare_options
59
65
  @run_migrations = options[:migrate]
60
- @load_seed_data = options[:seed]
61
- @load_sample_data = options[:sample]
66
+ @load_seed_data = options[:seed] && @run_migrations
67
+ @load_sample_data = options[:sample] && @run_migrations && @load_seed_data
68
+ @selected_frontend = detect_frontend_to_install
69
+ @selected_authentication = detect_authentication_to_install
70
+ @selected_payment_method = detect_payment_method_to_install
71
+
72
+ # Silence verbose output (e.g. Rails migrations will rely on this environment variable)
73
+ ENV['VERBOSE'] = 'false'
74
+
75
+ # No reason to check for their presence if we're about to install them
76
+ ENV['SOLIDUS_SKIP_MIGRATIONS_CHECK'] = 'true'
77
+
78
+ if options[:enforce_available_locales] != nil
79
+ warn \
80
+ "DEPRECATION WARNING: using `solidus:install --enforce-available-locales` is now deprecated and has no effect. " \
81
+ "Since Rails 4.1 the default is `true` so we no longer need to explicitly set a value."
82
+ end
62
83
 
63
- unless @run_migrations
64
- @load_seed_data = false
65
- @load_sample_data = false
84
+ if options[:lib_name] != nil
85
+ warn \
86
+ "DEPRECATION WARNING: using `solidus:install --lib-name` is now deprecated and has no effect. " \
87
+ "The option is legacy and should be removed from scripts still using it."
66
88
  end
67
89
  end
68
90
 
@@ -72,32 +94,15 @@ module Solidus
72
94
 
73
95
  def install_file_attachment
74
96
  if options[:active_storage]
75
- say "Installing Active Storage", :green
97
+ say_status :assets, "Active Storage", :green
76
98
  rake 'active_storage:install'
77
99
  else
78
- say "Installing Paperclip", :green
100
+ say_status :assets, "Paperclip", :green
79
101
  gsub_file 'config/initializers/spree.rb', "ActiveStorageAttachment", "PaperclipAttachment"
80
102
  end
81
103
  end
82
104
 
83
- def additional_tweaks
84
- return unless File.exist? 'public/robots.txt'
85
-
86
- append_file "public/robots.txt", <<-ROBOTS.strip_heredoc
87
- User-agent: *
88
- Disallow: /checkout
89
- Disallow: /cart
90
- Disallow: /orders
91
- Disallow: /user
92
- Disallow: /account
93
- Disallow: /api
94
- Disallow: /password
95
- ROBOTS
96
- end
97
-
98
105
  def setup_assets
99
- @lib_name = 'spree'
100
-
101
106
  empty_directory 'app/assets/images'
102
107
 
103
108
  %w{javascripts stylesheets images}.each do |path|
@@ -114,68 +119,15 @@ module Solidus
114
119
  empty_directory "app/overrides"
115
120
  end
116
121
 
117
- def configure_application
118
- if !options[:enforce_available_locales].nil?
119
- application <<-RUBY
120
- # Prevent this deprecation message: https://github.com/svenfuchs/i18n/commit/3b6e56e
121
- I18n.enforce_available_locales = #{options[:enforce_available_locales]}
122
- RUBY
123
- end
124
- end
125
-
126
- def plugin_install_preparation
127
- @plugins_to_be_installed = []
128
- @plugin_generators_to_run = []
129
- end
130
-
131
- def install_auth_plugin
132
- with_authentication = options[:with_authentication]
133
- with_authentication.nil? and with_authentication = (options[:auto_accept] || !no?("
134
- Solidus has a default authentication extension that uses Devise.
135
- You can find more info at https://github.com/solidusio/solidus_auth_devise.
136
-
137
- Regardless of what you answer here, it'll be installed if you choose
138
- solidus_starter_frontend as your storefront in a later step.
139
-
140
- Would you like to install it? (Y/n)"))
141
-
142
- if with_authentication
143
- @plugins_to_be_installed << 'solidus_auth_devise'
144
- @plugin_generators_to_run << 'solidus:auth:install'
145
- end
146
- end
147
-
148
- def install_payment_method
149
- say_status :warning, set_color(
150
- "Selecting a payment along with `solidus_starter_frontend` might require manual integration.",
151
- :yellow
152
- ), :yellow
153
-
154
- name = options[:payment_method]
155
- name ||= PAYMENT_METHODS.keys.first if options[:auto_accept]
156
- name ||= ask("
157
- You can select a payment method to be included in the installation process.
158
- Please select a payment method name:", limited_to: PAYMENT_METHODS.keys, default: PAYMENT_METHODS.keys.first)
159
-
160
- gem_name = PAYMENT_METHODS.fetch(name)
161
-
162
- if gem_name
163
- @plugins_to_be_installed << gem_name
164
- @plugin_generators_to_run << "#{gem_name}:install"
165
- end
166
- end
167
-
168
122
  def include_seed_data
169
- append_file "db/seeds.rb", <<-RUBY.strip_heredoc
170
-
171
- Spree::Core::Engine.load_seed if defined?(Spree::Core)
172
- Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
123
+ append_file "db/seeds.rb", <<~RUBY
124
+ Spree::Core::Engine.load_seed
173
125
  RUBY
174
126
  end
175
127
 
176
128
  def install_migrations
177
129
  say_status :copying, "migrations"
178
- `rake railties:install:migrations`
130
+ rake 'railties:install:migrations'
179
131
  end
180
132
 
181
133
  def create_database
@@ -183,32 +135,18 @@ module Solidus
183
135
  rake 'db:create'
184
136
  end
185
137
 
186
- def install_frontend
187
- return if options[:frontend] == 'none'
188
-
189
- bundler_context = BundlerContext.new
190
-
191
- frontend = detect_frontend_to_install(bundler_context)
192
-
193
- support_solidus_frontend_extraction(bundler_context) unless frontend == LEGACY_FRONTEND
194
-
195
- say_status :installing, frontend
196
-
197
- InstallFrontend
198
- .new(bundler_context: bundler_context, generator_context: self)
199
- .call(frontend)
200
- end
201
-
202
- def run_bundle_install_if_needed_by_plugins
203
- @plugins_to_be_installed.each do |plugin_name|
204
- gem plugin_name
205
- end
206
-
207
- BundlerContext.bundle_cleanly { run "bundle install" } if @plugins_to_be_installed.any?
208
- run "spring stop" if defined?(Spring)
209
-
210
- @plugin_generators_to_run.each do |plugin_generator_name|
211
- generate "#{plugin_generator_name} --skip_migrations=true"
138
+ def install_routes
139
+ if Pathname(app_path).join('config', 'routes.rb').read.include? CORE_MOUNT_ROUTE
140
+ say_status :route_exist, CORE_MOUNT_ROUTE, :blue
141
+ else
142
+ route <<~RUBY
143
+ # This line mounts Solidus's routes at the root of your application.
144
+ # This means, any requests to URLs such as /products, will go to Spree::ProductsController.
145
+ # If you would like to change where this engine is mounted, simply change the :at option to something different.
146
+ #
147
+ # We ask that you don't use the :as option here, as Solidus relies on it being the default of "spree"
148
+ #{CORE_MOUNT_ROUTE}, at: '/'
149
+ RUBY
212
150
  end
213
151
  end
214
152
 
@@ -216,15 +154,27 @@ module Solidus
216
154
  if @run_migrations
217
155
  say_status :running, "migrations"
218
156
 
219
- rake 'db:migrate VERBOSE=false'
157
+ rake 'db:migrate'
220
158
  else
221
159
  say_status :skipping, "migrations (don't forget to run rake db:migrate)"
222
160
  end
223
161
  end
224
162
 
163
+ def install_authentication
164
+ apply_template_for :authentication, @selected_authentication
165
+ end
166
+
167
+ def install_frontend
168
+ apply_template_for :frontend, @selected_frontend
169
+ end
170
+
171
+ def install_payment_method
172
+ apply_template_for :payment_method, @selected_payment_method
173
+ end
174
+
225
175
  def populate_seed_data
226
176
  if @load_seed_data
227
- say_status :loading, "seed data"
177
+ say_status :loading, "seed data"
228
178
  rake_options = []
229
179
  rake_options << "AUTO_ACCEPT=1" if options[:auto_accept]
230
180
  rake_options << "ADMIN_EMAIL=#{options[:admin_email]}" if options[:admin_email]
@@ -245,61 +195,157 @@ module Solidus
245
195
  end
246
196
  end
247
197
 
248
- def install_routes
249
- routes_file_path = File.join('config', 'routes.rb')
250
- unless File.read(routes_file_path).include? CORE_MOUNT_ROUTE
251
- insert_into_file routes_file_path, after: "Rails.application.routes.draw do\n" do
252
- <<-RUBY
253
- # This line mounts Solidus's routes at the root of your application.
254
- # This means, any requests to URLs such as /products, will go to Spree::ProductsController.
255
- # If you would like to change where this engine is mounted, simply change the :at option to something different.
256
- #
257
- # We ask that you don't use the :as option here, as Solidus relies on it being the default of "spree"
258
- #{CORE_MOUNT_ROUTE}, at: '/'
259
-
260
- RUBY
198
+ def complete
199
+ say_status :complete, "Solidus has been installed successfully. Enjoy!"
200
+ end
201
+
202
+ private
203
+
204
+ def generate(what, *args, abort_on_failure: true)
205
+ args << '--auto-accept' if options[:auto_accept]
206
+ args << '--auto-run-migrations' if options[:migrate]
207
+ super(what, *args, abort_on_failure: abort_on_failure)
208
+ end
209
+
210
+ def bundle_command(command, env = {})
211
+ # Make `bundle install` less verbose by skipping the "Using ..." messages
212
+ super(command, env.reverse_merge('BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES' => 'true'))
213
+ ensure
214
+ Bundler.reset_paths!
215
+ end
216
+
217
+ def ask_with_description(desc:, limited_to:, default:)
218
+ loop do
219
+ say_status :question, desc, :yellow
220
+ answer = ask(set_color("answer:".rjust(13), :blue, :bold)).to_s.downcase.presence
221
+
222
+ case answer
223
+ when nil
224
+ say_status :using, "#{default} (default)"
225
+ break default
226
+ when *limited_to.map(&:to_s)
227
+ say_status :using, answer
228
+ break answer
229
+ else say_status :error, "Please select a valid answer:", :red
261
230
  end
262
231
  end
232
+ end
233
+
234
+ def apply_template_for(topic, selected)
235
+ template_path = Dir["#{__dir__}/app_templates/#{topic}/*.rb"].find do |path|
236
+ File.basename(path, '.rb') == selected
237
+ end
263
238
 
264
- unless options[:quiet]
265
- puts "*" * 50
266
- puts "We added the following line to your application's config/routes.rb file:"
267
- puts " "
268
- puts " #{CORE_MOUNT_ROUTE}, at: '/'"
239
+ unless template_path
240
+ say_status :warning, "Unknown #{topic}: #{selected.inspect}, attempting to run it with `rails app:template`"
241
+ template_path = selected
269
242
  end
243
+
244
+ say_status :installing, "[#{topic}] #{selected}", :blue
245
+ apply template_path
270
246
  end
271
247
 
272
- def complete
273
- unless options[:quiet]
274
- puts "*" * 50
275
- puts "Solidus has been installed successfully. You're all ready to go!"
276
- puts " "
277
- puts "Enjoy!"
248
+ def with_env(vars)
249
+ original = ENV.to_hash
250
+ vars.each { |k, v| ENV[k] = v }
251
+
252
+ begin
253
+ yield
254
+ ensure
255
+ ENV.replace(original)
278
256
  end
279
257
  end
280
258
 
281
- private
259
+ def detect_frontend_to_install
260
+ # We need to support names that were available in v3.2
261
+ selected_frontend = 'starter' if options[:frontend] == 'solidus_starter_frontend'
262
+ selected_frontend = 'classic' if options[:frontend] == 'solidus_frontend'
263
+ selected_frontend ||= options[:frontend]
282
264
 
283
- def detect_frontend_to_install(bundler_context)
284
265
  ENV['FRONTEND'] ||
285
- options[:frontend] ||
286
- (bundler_context.component_in_gemfile?(:frontend) && LEGACY_FRONTEND) ||
287
- (options[:auto_accept] && DEFAULT_FRONTEND) ||
288
- ask(<<~MSG.indent(8), limited_to: FRONTENDS, default: DEFAULT_FRONTEND)
266
+ selected_frontend ||
267
+ (Bundler.locked_gems.dependencies['solidus_frontend'] && 'classic') ||
268
+ (options[:auto_accept] && 'starter') ||
269
+ ask_with_description(
270
+ default: 'starter',
271
+ limited_to: FRONTENDS,
272
+ desc: <<~TEXT
273
+ Which frontend would you like to use?
274
+
275
+ - [#{set_color 'starter', :bold}] Generate all necessary controllers and views directly in your Rails app (#{set_color :default, :bold}).
276
+ - [#{set_color 'classic', :bold}] Install `solidus_frontend`, was the default in previous solidus versions (#{set_color :deprecated, :bold}).
277
+ - [#{set_color 'none', :bold}] Skip installing a frontend.
278
+
279
+ Selecting `starter` is recommended, however, some extensions are still only compatible with `classic`.
280
+ TEXT
281
+ )
282
+ end
289
283
 
290
- Which frontend would you like to use? solidus_starter_frontend is
291
- recommended. However, some extensions are still only compatible with
292
- the now deprecated solidus_frontend.
284
+ def detect_authentication_to_install
285
+ return 'devise' if @selected_frontend == 'starter'
286
+
287
+ if options[:with_authentication] != nil
288
+ say_status :warning, \
289
+ "Using `solidus:install --with-authentication` is now deprecated. " \
290
+ "Please use `--authentication` instead (see --help for the full list of options).",
291
+ :red
292
+
293
+ if options[:with_authentication] == 'false'
294
+ # Don't use the default authentication if the user explicitly
295
+ # requested no authentication system.
296
+ return 'none'
297
+ else
298
+ return 'devise'
299
+ end
300
+ end
293
301
 
294
- MSG
302
+ ENV['AUTHENTICATION'] ||
303
+ options[:authentication] ||
304
+ (Bundler.locked_gems.dependencies['solidus_auth_devise'] && 'devise') ||
305
+ (options[:auto_accept] && 'devise') ||
306
+ ask_with_description(
307
+ default: 'devise',
308
+ limited_to: AUTHENTICATIONS,
309
+ desc: <<~TEXT
310
+ Which authentication would you like to use?
311
+
312
+ - [#{set_color 'devise', :bold}] Install and configure the standard `devise` integration. (#{set_color :default, :bold}).
313
+ - [#{set_color 'existing', :bold}] Integrate and configure an existing `devise` setup.
314
+ - [#{set_color 'custom', :bold}] A starter configuration for rolling your own authentication system.
315
+ - [#{set_color 'none', :bold}] Don't add any configuration for authentication.
316
+
317
+ Selecting `devise` is recommended.
318
+ TEXT
319
+ )
295
320
  end
296
321
 
297
- def support_solidus_frontend_extraction(bundler_context)
298
- say_status "break down", "solidus"
322
+ def detect_payment_method_to_install
323
+ return 'paypal' if Bundler.locked_gems.dependencies['solidus_paypal_commerce_platform']
324
+ return 'bolt' if Bundler.locked_gems.dependencies['solidus_bolt']
325
+
326
+ descriptions = {
327
+ paypal: "- [#{set_color 'paypal', :bold}] Install `solidus_paypal_commerce_platform` (#{set_color :default, :bold}).",
328
+ bolt: "- [#{set_color 'bolt', :bold}] Install `solidus_bolt`.",
329
+ none: "- [#{set_color 'none', :bold}] Skip installing a payment method.",
330
+ }
331
+
332
+ payment_methods = PAYMENT_METHODS
333
+
334
+ if @selected_frontend != 'classic'
335
+ payment_methods -= ['bolt']
336
+ descriptions.delete(:bolt)
337
+ end
338
+
339
+ selected = options[:payment_method] || (options[:auto_accept] && 'paypal') ||
340
+ ask_with_description(
341
+ default: 'paypal',
342
+ limited_to: payment_methods,
343
+ desc: <<~TEXT
344
+ Which payment method would you like to use?
299
345
 
300
- SupportSolidusFrontendExtraction.
301
- new(bundler_context: bundler_context).
302
- call
346
+ #{descriptions.values.join("\n")}
347
+ TEXT
348
+ )
303
349
  end
304
350
  end
305
351
  end
@@ -9,9 +9,6 @@ Spree.config do |config|
9
9
  # Default currency for new sites
10
10
  config.currency = "USD"
11
11
 
12
- # from address for transactional emails
13
- config.mails_from = "store@example.com"
14
-
15
12
  # Uncomment to stop tracking inventory levels in the application
16
13
  # config.track_inventory_levels = false
17
14
 
@@ -79,7 +76,9 @@ Spree::Api::Config.configure do |config|
79
76
  end
80
77
  <% end -%>
81
78
 
82
- Spree.user_class = <%= (options[:user_class].blank? ? "Spree::LegacyUser" : options[:user_class]).inspect %>
79
+ <% if options[:user_class].present? -%>
80
+ Spree.user_class = <%= options[:user_class].inspect %>
81
+ <% end -%>
83
82
 
84
83
  # Rules for avoiding to store the current path into session for redirects
85
84
  # When at least one rule is matched, the request path will not be stored
@@ -22,10 +22,12 @@ module Spree
22
22
  migration_template 'migration.rb.tt', "db/migrate/add_spree_fields_to_custom_user_table.rb"
23
23
  template 'authentication_helpers.rb.tt', "lib/spree/authentication_helpers.rb"
24
24
 
25
- file_action = File.exist?('config/initializers/spree.rb') ? :append_file : :create_file
26
- send(file_action, 'config/initializers/spree.rb') do
27
- "Rails.application.config.to_prepare do\n require_dependency 'spree/authentication_helpers'\nend\n"
28
- end
25
+ initializer 'solidus_authentication', <<~RUBY
26
+ Rails.application.config.to_prepare do
27
+ ApplicationController.include Spree::AuthenticationHelpers, Spree::CurrentUserHelpers
28
+ Spree::Api::BaseController.include Spree::CurrentUserHelpers if defined? Spree::Api
29
+ end
30
+ RUBY
29
31
 
30
32
  gsub_file 'config/initializers/spree.rb', /Spree\.user_class.?=.?.+$/, %{Spree.user_class = "#{class_name}"}
31
33
  end
@@ -9,7 +9,8 @@ module Spree
9
9
  end
10
10
 
11
11
  def spree_current_user
12
- current_user
12
+ # TODO: Replace this with your implementation for retrieving the current user
13
+ Spree.user_class.new
13
14
  end
14
15
  end
15
16
 
@@ -33,8 +34,3 @@ module Spree
33
34
  end
34
35
  end
35
36
  end
36
-
37
- ApplicationController.send :include, Spree::AuthenticationHelpers
38
- ApplicationController.send :include, Spree::CurrentUserHelpers
39
-
40
- Spree::Api::BaseController.send :include, Spree::CurrentUserHelpers
@@ -1,7 +1,11 @@
1
1
  class AddSpreeFieldsToCustomUserTable < ActiveRecord::Migration[4.2]
2
2
  def up
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
3
+ if table_exists?(<%= table_name.inspect %>)
4
+ add_column <%= table_name.inspect %>, :spree_api_key, :string, :limit => 48 unless column_exists?(<%= table_name.inspect %>, :spree_api_key)
5
+ add_column <%= table_name.inspect %>, :ship_address_id, :integer unless column_exists?(<%= table_name.inspect %>, :ship_address_id)
6
+ add_column <%= table_name.inspect %>, :bill_address_id, :integer unless column_exists?(<%= table_name.inspect %>, :bill_address_id)
7
+ add_column <%= table_name.inspect %>, :deleted_at, :datetime unless column_exists?(<%= table_name.inspect %>, :deleted_at)
8
+ add_index <%= table_name.inspect %>, :deleted_at unless column_exists?(<%= table_name.inspect %>, :deleted_at)
9
+ end
6
10
  end
7
11
  end
@@ -96,13 +96,15 @@ module Spree
96
96
  protected
97
97
 
98
98
  def inject_require_for(requirement)
99
- inject_into_file 'config/application.rb', %[
100
- begin
101
- require '#{requirement}'
102
- rescue LoadError
103
- # #{requirement} is not available.
104
- end
105
- ], before: /require '#{@lib_name}'/, verbose: true
99
+ inject_into_file 'config/application.rb', (
100
+ <<~RUBY
101
+ begin
102
+ require '#{requirement}'
103
+ rescue LoadError
104
+ # #{requirement} is not available.
105
+ end
106
+ RUBY
107
+ ), before: /require '#{@lib_name}'/, verbose: true
106
108
  end
107
109
 
108
110
  def dummy_path
@@ -118,7 +120,7 @@ end
118
120
  dummy_application_path = File.expand_path("#{dummy_path}/config/application.rb", destination_root)
119
121
  unless options[:pretend] || !File.exist?(dummy_application_path)
120
122
  contents = File.read(dummy_application_path)
121
- contents[(contents.index("module #{module_name}"))..-1]
123
+ contents[(contents.index("module #{module_name}"))..]
122
124
  end
123
125
  end
124
126
  end