solidus_core 3.0.2 → 3.1.3

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.

Potentially problematic release.


This version of solidus_core might be problematic. Click here for more details.

Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/base_helper.rb +1 -1
  3. data/app/helpers/spree/products_helper.rb +1 -1
  4. data/app/models/concerns/spree/default_price.rb +63 -10
  5. data/app/models/spree/adjustment.rb +6 -5
  6. data/app/models/spree/customer_return.rb +3 -2
  7. data/app/models/spree/image/active_storage_attachment.rb +2 -7
  8. data/app/models/spree/image/paperclip_attachment.rb +2 -2
  9. data/app/models/spree/line_item.rb +2 -2
  10. data/app/models/spree/order.rb +11 -6
  11. data/app/models/spree/price.rb +1 -1
  12. data/app/models/spree/product/scopes.rb +5 -5
  13. data/app/models/spree/product.rb +12 -0
  14. data/app/models/spree/promotion/rules/item_total.rb +50 -6
  15. data/app/models/spree/promotion.rb +2 -2
  16. data/app/models/spree/promotion_code.rb +1 -1
  17. data/app/models/spree/shipping_rate_tax.rb +1 -1
  18. data/app/models/spree/stock/availability.rb +11 -3
  19. data/app/models/spree/stock/simple_coordinator.rb +0 -10
  20. data/app/models/spree/stock_location.rb +1 -1
  21. data/app/models/spree/store_credit.rb +6 -1
  22. data/app/models/spree/tax_calculator/shipping_rate.rb +1 -1
  23. data/app/models/spree/taxon/active_storage_attachment.rb +2 -2
  24. data/app/models/spree/taxon/paperclip_attachment.rb +3 -3
  25. data/app/models/spree/variant/price_selector.rb +16 -3
  26. data/app/models/spree/variant.rb +26 -16
  27. data/config/locales/en.yml +2 -0
  28. data/db/migrate/20210312061050_change_column_null_on_prices.rb +7 -0
  29. data/lib/generators/solidus/install/install_generator.rb +1 -1
  30. data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +3 -1
  31. data/lib/generators/solidus/update/templates/config/initializers/new_solidus_defaults.rb.tt +30 -0
  32. data/lib/generators/solidus/update/update_generator.rb +112 -0
  33. data/lib/generators/spree/dummy/templates/rails/application.rb.tt +0 -1
  34. data/lib/generators/spree/dummy/templates/rails/database.yml +78 -35
  35. data/lib/spree/app_configuration.rb +62 -0
  36. data/lib/spree/core/engine.rb +16 -9
  37. data/lib/spree/core/product_filters.rb +1 -1
  38. data/lib/spree/core/search/base.rb +1 -1
  39. data/lib/spree/core/state_machines/order.rb +1 -1
  40. data/lib/spree/core/version.rb +5 -1
  41. data/lib/spree/core/versioned_value.rb +75 -0
  42. data/lib/spree/core.rb +28 -0
  43. data/lib/spree/permitted_attributes.rb +1 -1
  44. data/lib/spree/preferences/configuration.rb +62 -0
  45. data/lib/spree/preferences/preferable.rb +8 -0
  46. data/lib/spree/preferences/preferable_class_methods.rb +37 -4
  47. data/lib/spree/preferences/preference_differentiator.rb +28 -0
  48. data/lib/spree/testing_support/dummy_app/database.yml +42 -22
  49. data/lib/spree/testing_support/dummy_app.rb +33 -18
  50. data/lib/tasks/solidus/delete_prices_with_nil_amount.rake +8 -0
  51. data/solidus_core.gemspec +6 -1
  52. metadata +17 -8
  53. data/app/models/spree/tax/shipping_rate_taxer.rb +0 -24
  54. data/lib/tasks/upgrade.rake +0 -15
@@ -24,7 +24,6 @@ module Spree
24
24
  stock_items.discard_all
25
25
  images.destroy_all
26
26
  prices.discard_all
27
- currently_valid_prices.discard_all
28
27
  end
29
28
 
30
29
  attr_writer :rebuild_vat_prices
@@ -58,13 +57,6 @@ module Spree
58
57
  inverse_of: :variant,
59
58
  autosave: true
60
59
 
61
- has_many :currently_valid_prices,
62
- -> { currently_valid },
63
- class_name: 'Spree::Price',
64
- dependent: :destroy,
65
- inverse_of: :variant,
66
- autosave: true
67
-
68
60
  before_validation :set_cost_currency
69
61
  before_validation :set_price, if: -> { product && product.master }
70
62
  before_validation :build_vat_prices, if: -> { rebuild_vat_prices? || new_record? && product }
@@ -276,16 +268,17 @@ module Spree
276
268
  end
277
269
 
278
270
  # Chooses an appropriate price for the given pricing options
271
+ # This has been deprecated in favor of #price_for_options.
279
272
  #
280
- # @see Spree::Variant::PriceSelector#price_for
273
+ # @see Spree::Variant::PriceSelector#price_for_options
281
274
  delegate :price_for, to: :price_selector
282
275
 
283
276
  # Returns the difference in price from the master variant
284
277
  def price_difference_from_master(pricing_options = Spree::Config.default_pricing_options)
285
- master_price = product.master.price_for(pricing_options)
286
- variant_price = price_for(pricing_options)
278
+ master_price = product.master.price_for_options(pricing_options)
279
+ variant_price = price_for_options(pricing_options)
287
280
  return unless master_price && variant_price
288
- variant_price - master_price
281
+ Spree::Money.new(variant_price.amount - master_price.amount, currency: pricing_options.currency)
289
282
  end
290
283
 
291
284
  def price_same_as_master?(pricing_options = Spree::Config.default_pricing_options)
@@ -293,6 +286,17 @@ module Spree
293
286
  diff && diff.zero?
294
287
  end
295
288
 
289
+ def price_for_options(price_options)
290
+ if price_selector.respond_to?(:price_for_options)
291
+ price_selector.price_for_options(price_options)
292
+ else
293
+ money = price_for(price_options)
294
+ return if money.nil?
295
+
296
+ Spree::Price.new(amount: money.to_d, variant: self, currency: price_options.currency)
297
+ end
298
+ end
299
+
296
300
  # Generates a friendly name and sku string.
297
301
  #
298
302
  # @return [String]
@@ -315,16 +319,22 @@ module Spree
315
319
  end
316
320
 
317
321
  # @param quantity [Fixnum] how many are desired
322
+ # @param stock_location [Spree::StockLocation] Optionally restrict stock
323
+ # quantity check to a specific stock location. If unspecified it will
324
+ # check inventory in all available StockLocations.
318
325
  # @return [Boolean] true if the desired quantity can be supplied
319
- def can_supply?(quantity = 1)
320
- Spree::Stock::Quantifier.new(self).can_supply?(quantity)
326
+ def can_supply?(quantity = 1, stock_location = nil)
327
+ Spree::Stock::Quantifier.new(self, stock_location).can_supply?(quantity)
321
328
  end
322
329
 
323
330
  # Fetches the on-hand quantity of the variant.
324
331
  #
332
+ # @param stock_location [Spree::StockLocation] Optionally restrict stock
333
+ # quantity check to a specific stock location. If unspecified it will
334
+ # check inventory in all available StockLocations.
325
335
  # @return [Fixnum] the number currently on-hand
326
- def total_on_hand
327
- Spree::Stock::Quantifier.new(self).total_on_hand
336
+ def total_on_hand(stock_location = nil)
337
+ Spree::Stock::Quantifier.new(self, stock_location).total_on_hand
328
338
  end
329
339
 
330
340
  # Shortcut method to determine if inventory tracking is enabled for this
@@ -1288,6 +1288,8 @@ en:
1288
1288
  %{amount}.
1289
1289
  item_total_less_than_or_equal: This coupon code can't be applied to orders
1290
1290
  less than or equal to %{amount}.
1291
+ item_total_doesnt_match_with_operator: This coupon code can't be applied to
1292
+ orders %{operator} %{amount}.
1291
1293
  limit_once_per_user: This coupon code can only be used once per user.
1292
1294
  missing_product: This coupon code can't be applied because you don't have
1293
1295
  all of the necessary products in your cart.
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ChangeColumnNullOnPrices < ActiveRecord::Migration[5.2]
4
+ def change
5
+ change_column_null(:spree_prices, :amount, false)
6
+ end
7
+ end
@@ -132,7 +132,7 @@ module Solidus
132
132
  Solidus has a default authentication extension that uses Devise.
133
133
  You can find more info at https://github.com/solidusio/solidus_auth_devise.
134
134
 
135
- Would you like to install it? (y/n)"))
135
+ Would you like to install it? (Y/n)"))
136
136
 
137
137
  @plugins_to_be_installed << 'solidus_auth_devise'
138
138
  @plugin_generators_to_run << 'solidus:auth:install'
@@ -1,9 +1,11 @@
1
1
  # Configure Solidus Preferences
2
2
  # See http://docs.solidus.io/Spree/AppConfiguration.html for details
3
3
 
4
+ # Solidus version defaults for preferences that are not overridden
5
+ Spree.load_defaults '<%= Spree.solidus_version %>'
6
+
4
7
  Spree.config do |config|
5
8
  # Core:
6
-
7
9
  # Default currency for new sites
8
10
  config.currency = "USD"
9
11
 
@@ -0,0 +1,30 @@
1
+ # This initializer lets you preview the defaults that have changed on the new
2
+ # Solidus version.
3
+ #
4
+ # It allows you to enable them one by one while you adapt your application.
5
+ # When you're done with all of them, you can safely remove this file and add
6
+ # the updated `load_defaults` calls to the top of the config blocks in your
7
+ # Solidus main initializer. You can also call `Spree.load_defaults(version)` to
8
+ # target all components at once.
9
+
10
+ Spree.config do |config|
11
+ <%= @core_changes %>
12
+ end
13
+
14
+ <% if defined?(Spree::Frontend::Engine) -%>
15
+ Spree::Frontend::Config.configure do |config|
16
+ <%= @frontend_changes %>
17
+ end
18
+ <% end -%>
19
+
20
+ <% if defined?(Spree::Backend::Engine) -%>
21
+ Spree::Backend::Config.configure do |config|
22
+ <%= @backend_changes %>
23
+ end
24
+ <% end -%>
25
+
26
+ <% if defined?(Spree::Api::Engine) -%>
27
+ Spree::Api::Config.configure do |config|
28
+ <%= @api_changes %>
29
+ end
30
+ <% end -%>
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spree/preferences/preference_differentiator'
4
+ require 'rails/generators'
5
+
6
+ module Solidus
7
+ # @private
8
+ class UpdateGenerator < ::Rails::Generators::Base
9
+ FROM = Spree.previous_solidus_minor_version
10
+
11
+ desc 'Generates a new initializer to preview the new defaults for current Solidus version'
12
+
13
+ source_root File.expand_path('templates', __dir__)
14
+
15
+ class_option :initializer_basename,
16
+ type: :string,
17
+ default: 'new_solidus_defaults',
18
+ banner: 'The name for the new initializer'
19
+
20
+ class_option :previous_version_prompt,
21
+ type: :boolean,
22
+ default: true,
23
+ banner: 'Prompt to warn about only previous version support'
24
+
25
+ class_option :from,
26
+ type: :string,
27
+ default: FROM,
28
+ banner: 'Solidus version from which you are upgrading'
29
+
30
+ class_option :to,
31
+ type: :string,
32
+ default: Spree.solidus_version,
33
+ hide: true
34
+
35
+ class_option :initializer_directory,
36
+ type: :string,
37
+ default: 'config/initializers/',
38
+ hide: true
39
+
40
+ def create_new_defaults_initializer
41
+ previous_version_prompt = options[:previous_version_prompt]
42
+ return if previous_version_prompt && !yes?(<<~MSG, :red)
43
+ The update process is only supported if you are coming from version #{FROM}. If this is not the case, please, skip it and update your application to use Solidus #{FROM} before retrying.
44
+ If you are confident you want to upgrade from a previous version, you must rerun the generator with the "--from={OLD_VERSION}" argument.
45
+ Are you sure you want to continue? (y/N)
46
+ MSG
47
+
48
+ from = options[:from]
49
+ to = options[:to]
50
+ @from = from
51
+ @core_changes = core_changes_template(from, to)
52
+ @frontend_changes = frontend_changes_template(from, to)
53
+ @backend_changes = backend_changes_template(from, to)
54
+ @api_changes = api_changes_template(from, to)
55
+
56
+ template 'config/initializers/new_solidus_defaults.rb.tt',
57
+ File.join(options[:initializer_directory], "#{options[:initializer_basename]}.rb")
58
+ end
59
+
60
+ def print_message
61
+ say <<~MSG
62
+
63
+ ***********************************************************************
64
+
65
+ Other tasks may be needed to update to the new Solidus version. Please,
66
+ check https://github.com/solidusio/solidus/blob/v#{options[:to]}/CHANGELOG.md
67
+ for details.
68
+
69
+ Thanks for using Solidus!
70
+
71
+ ***********************************************************************
72
+
73
+ MSG
74
+ end
75
+
76
+ private
77
+
78
+ def core_changes_template(from, to)
79
+ changes_template_for(Spree::AppConfiguration, from, to)
80
+ end
81
+
82
+ def frontend_changes_template(from, to)
83
+ return '' unless defined?(Spree::Frontend::Engine)
84
+
85
+ changes_template_for(Spree::FrontendConfiguration, from, to)
86
+ end
87
+
88
+ def backend_changes_template(from, to)
89
+ return '' unless defined?(Spree::Backend::Engine)
90
+
91
+ changes_template_for(Spree::BackendConfiguration, from, to)
92
+ end
93
+
94
+ def api_changes_template(from, to)
95
+ return '' unless defined?(Spree::Api::Engine)
96
+
97
+ changes_template_for(Spree::ApiConfiguration, from, to)
98
+ end
99
+
100
+ def changes_template_for(klass, from, to)
101
+ changes = Spree::Preferences::PreferenceDifferentiator.new(klass).call(from: from, to: to)
102
+ return '# No changes' if changes.empty?
103
+
104
+ [
105
+ ["config.load_defaults('#{from}')"] +
106
+ changes.map do |pref_key, change|
107
+ " # config.#{pref_key} = #{change[:to]}"
108
+ end.flatten
109
+ ].join("\n")
110
+ end
111
+ end
112
+ end
@@ -7,4 +7,3 @@ Bundler.require(*Rails.groups(assets: %w(development test)))
7
7
  require '<%= lib_name %>'
8
8
 
9
9
  <%= application_definition %>
10
-
@@ -1,66 +1,111 @@
1
1
  <% if agent_number = ENV['TC_AGENT_NUMBER']
2
2
  database_prefix = agent_number + '_'
3
3
  end %>
4
+ <% db = case ENV['DB']
5
+ when 'mysql'
6
+ 'mysql'
7
+ when 'postgres', 'postgresql'
8
+ 'postgres'
9
+ when 'sqlite', '', nil
10
+ 'sqlite'
11
+ else
12
+ raise "Invalid DB specified: #{ENV['DB']}"
13
+ end %>
14
+ <% db_host = case db
15
+ when 'mysql'
16
+ ENV['DB_MYSQL_HOST'] || ENV['DB_HOST']
17
+ when 'postgres'
18
+ ENV['DB_POSTGRES_HOST'] || ENV['DB_HOST']
19
+ else
20
+ ENV['DB_HOST']
21
+ end %>
22
+ <% db_username = ENV['DB_USERNAME'] %>
23
+ <% db_password = ENV['DB_PASSWORD'] %>
24
+
25
+
26
+
27
+
4
28
  <% case ENV['DB']
5
- when 'sqlite' %>
6
- development:
7
- adapter: sqlite3
8
- database: db/solidus_development.sqlite3
9
- test:
10
- adapter: sqlite3
11
- database: db/solidus_test.sqlite3
12
- timeout: 10000
13
- production:
14
- adapter: sqlite3
15
- database: db/solidus_production.sqlite3
16
- <% when 'mysql' %>
29
+ when 'mysql' %>
17
30
  development:
18
31
  adapter: mysql2
19
32
  database: <%= database_prefix %><%= options[:lib_name] %>_solidus_development
33
+ <% unless db_username.blank? %>
34
+ username: <%= db_username %>
35
+ <% end %>
36
+ <% unless db_password.blank? %>
37
+ password: <%= db_password %>
38
+ <% end %>
39
+ <% unless db_host.blank? %>
40
+ host: <%= db_host %>
41
+ <% end %>
20
42
  encoding: utf8
21
43
  test:
22
44
  adapter: mysql2
23
- <% if ENV['TRAVIS'] %>
24
- username: root
25
- password:
26
- <% end %>
27
45
  database: <%= database_prefix %><%= options[:lib_name] %>_solidus_test
46
+ <% unless db_username.blank? %>
47
+ username: <%= db_username %>
48
+ <% end %>
49
+ <% unless db_password.blank? %>
50
+ password: <%= db_password %>
51
+ <% end %>
52
+ <% unless db_host.blank? %>
53
+ host: <%= db_host %>
54
+ <% end %>
28
55
  encoding: utf8
29
56
  production:
30
57
  adapter: mysql2
31
58
  database: <%= database_prefix %><%= options[:lib_name] %>_solidus_production
59
+ <% unless db_username.blank? %>
60
+ username: <%= db_username %>
61
+ <% end %>
62
+ <% unless db_password.blank? %>
63
+ password: <%= db_password %>
64
+ <% end %>
65
+ <% unless db_host.blank? %>
66
+ host: <%= db_host %>
67
+ <% end %>
32
68
  encoding: utf8
33
69
  <% when 'postgres', 'postgresql' %>
34
- <% db_host = ENV['DB_HOST'] -%>
35
- <% db_username = ENV['DB_USERNAME'] -%>
36
- <% db_password = ENV['DB_PASSWORD'] -%>
37
70
  development:
38
71
  adapter: postgresql
39
72
  database: <%= database_prefix %><%= options[:lib_name] %>_solidus_development
40
- username: postgres
41
- min_messages: warning
42
- <% unless db_host.blank? %>
73
+ <% unless db_username.blank? %>
74
+ username: <%= db_username %>
75
+ <% end %>
76
+ <% unless db_password.blank? %>
77
+ password: <%= db_password %>
78
+ <% end %>
79
+ <% unless db_host.blank? %>
43
80
  host: <%= db_host %>
44
- <% end %>
81
+ <% end %>
82
+ min_messages: warning
45
83
  test:
46
84
  adapter: postgresql
47
85
  database: <%= database_prefix %><%= options[:lib_name] %>_solidus_test
48
- username: <%= db_username || 'postgres' %>
49
- <% unless db_password.blank? %>
86
+ <% unless db_username.blank? %>
87
+ username: <%= db_username %>
88
+ <% end %>
89
+ <% unless db_password.blank? %>
50
90
  password: <%= db_password %>
51
- <% end %>
52
- min_messages: warning
53
- <% unless db_host.blank? %>
91
+ <% end %>
92
+ <% unless db_host.blank? %>
54
93
  host: <%= db_host %>
55
- <% end %>
94
+ <% end %>
95
+ min_messages: warning
56
96
  production:
57
97
  adapter: postgresql
58
98
  database: <%= database_prefix %><%= options[:lib_name] %>_solidus_production
59
- username: postgres
60
- min_messages: warning
61
- <% unless db_host.blank? %>
99
+ <% unless db_username.blank? %>
100
+ username: <%= db_username %>
101
+ <% end %>
102
+ <% unless db_password.blank? %>
103
+ password: <%= db_password %>
104
+ <% end %>
105
+ <% unless db_host.blank? %>
62
106
  host: <%= db_host %>
63
- <% end %>
107
+ <% end %>
108
+ min_messages: warning
64
109
  <% when 'sqlite', '', nil %>
65
110
  development:
66
111
  adapter: sqlite3
@@ -71,6 +116,4 @@ test:
71
116
  production:
72
117
  adapter: sqlite3
73
118
  database: db/solidus_production.sqlite3
74
- <% else %>
75
- <% raise "Invalid DB specified: #{ENV['DB']}" %>
76
119
  <% end %>
@@ -372,6 +372,28 @@ module Spree
372
372
  # Spree::Wallet::DefaultPaymentBuilder.
373
373
  class_name_attribute :default_payment_builder_class, default: 'Spree::Wallet::DefaultPaymentBuilder'
374
374
 
375
+ # Allows providing your own class for managing the contents of an order.
376
+ #
377
+ # @!attribute [rw] order_contents_class
378
+ # @return [Class] a class with the same public interfaces as
379
+ # Spree::OrderContents.
380
+ class_name_attribute :order_contents_class, default: 'Spree::OrderContents'
381
+
382
+ # Allows providing your own class for shipping an order.
383
+ #
384
+ # @!attribute [rw] order_shipping_class
385
+ # @return [Class] a class with the same public interfaces as
386
+ # Spree::OrderShipping.
387
+ class_name_attribute :order_shipping_class, default: 'Spree::OrderShipping'
388
+
389
+ # Allows providing your own class for managing the inventory units of a
390
+ # completed order.
391
+ #
392
+ # @!attribute [rw] order_cancellations_class
393
+ # @return [Class] a class with the same public interfaces as
394
+ # Spree::OrderCancellations.
395
+ class_name_attribute :order_cancellations_class, default: 'Spree::OrderCancellations'
396
+
375
397
  # Allows providing your own class for canceling payments.
376
398
  #
377
399
  # @!attribute [rw] payment_canceller
@@ -453,6 +475,46 @@ module Spree
453
475
  # @return [Array]
454
476
  class_name_attribute :allowed_image_mime_types, default: %w(image/jpeg image/jpg image/png image/gif).freeze
455
477
 
478
+ # @!attribute [rw] product_image_style_default
479
+ #
480
+ # Defines which style to default to when style is not provided
481
+ # :product is the default.
482
+ #
483
+ # @return [Symbol]
484
+ class_name_attribute :product_image_style_default, default: :product
485
+
486
+ # @!attribute [rw] product_image_styles
487
+ #
488
+ # Defines image styles/sizes hash for styles
489
+ # `{ mini: '48x48>',
490
+ # small: '400x400>',
491
+ # product: '680x680>',
492
+ # large: '1200x1200>' } is the default.
493
+ #
494
+ # @return [Hash]
495
+ class_name_attribute :product_image_styles, default: { mini: '48x48>',
496
+ small: '400x400>',
497
+ product: '680x680>',
498
+ large: '1200x1200>' }
499
+ # @!attribute [rw] taxon_image_style_default
500
+ #
501
+ # Defines which style to default to when style is not provided
502
+ # :mini is the default.
503
+ #
504
+ # @return [Symbol]
505
+ class_name_attribute :taxon_image_style_default, default: :mini
506
+
507
+ # @!attribute [rw] taxon_styles
508
+ #
509
+ # Defines taxon styles/sizes hash for styles
510
+ # `{ mini: '48x48>',
511
+ # small: '400x400>',
512
+ # product: '680x680>',
513
+ # large: '1200x1200>' } is the default.
514
+ #
515
+ # @return [Hash]
516
+ class_name_attribute :taxon_image_styles, default: { mini: '32x32>', normal: '128x128>' }
517
+
456
518
  # Allows switching attachment library for Taxon
457
519
  #
458
520
  # `Spree::Taxon::ActiveStorageAttachment`
@@ -55,17 +55,24 @@ module Spree
55
55
  end
56
56
  end
57
57
 
58
+ # Load in mailer previews for apps to use in development.
59
+ initializer "spree.core.action_mailer.set_preview_path", after: "action_mailer.set_configs" do |app|
60
+ original_preview_path = app.config.action_mailer.preview_path
61
+ solidus_preview_path = Spree::Core::Engine.root.join 'lib/spree/mailer_previews'
62
+
63
+ app.config.action_mailer.preview_path = "{#{original_preview_path},#{solidus_preview_path}}"
64
+ ActionMailer::Base.preview_path = app.config.action_mailer.preview_path
65
+ end
66
+
58
67
  config.after_initialize do
59
- # Load in mailer previews for apps to use in development.
60
- # We need to make sure we call `Preview.all` before requiring our
61
- # previews, otherwise any previews the app attempts to add need to be
62
- # manually required.
63
- if Rails.env.development? || Rails.env.test?
64
- ActionMailer::Preview.all
68
+ Spree::Config.check_load_defaults_called('Spree::Config')
69
+ end
65
70
 
66
- Dir[root.join("lib/spree/mailer_previews/**/*_preview.rb")].each do |file|
67
- require_dependency file
68
- end
71
+ config.after_initialize do
72
+ if defined?(Spree::Auth::Engine) &&
73
+ Gem::Version.new(Spree::Auth::VERSION) < Gem::Version.new('2.5.4') &&
74
+ defined?(Spree::UsersController)
75
+ Spree::UsersController.protect_from_forgery with: :exception
69
76
  end
70
77
  end
71
78
  end
@@ -61,7 +61,7 @@ module Spree
61
61
  scope = scope.or(new_scope)
62
62
  end
63
63
 
64
- Spree::Product.joins(master: :default_price).where(scope)
64
+ Spree::Product.joins(master: :prices).where(scope)
65
65
  end
66
66
 
67
67
  def self.format_price(amount)
@@ -51,7 +51,7 @@ module Spree
51
51
  # separate queries most of the time but opt for a join as soon as any
52
52
  # `where` constraints affecting joined tables are added to the search;
53
53
  # which is the case as soon as a taxon is added to the base scope.
54
- scope = scope.preload(master: :currently_valid_prices)
54
+ scope = scope.preload(master: :prices)
55
55
  scope = scope.preload(master: :images) if @properties[:include_images]
56
56
  scope
57
57
  end
@@ -73,7 +73,7 @@ module Spree
73
73
  end
74
74
 
75
75
  event :complete do
76
- transition to: :complete, from: :confirm
76
+ transition to: :complete, from: klass.checkout_steps.keys.last
77
77
  end
78
78
 
79
79
  if states[:payment]
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spree
4
- VERSION = "3.0.2"
4
+ VERSION = "3.1.3"
5
5
 
6
6
  def self.solidus_version
7
7
  VERSION
8
8
  end
9
9
 
10
+ def self.previous_solidus_minor_version
11
+ '3.0'
12
+ end
13
+
10
14
  def self.solidus_gem_version
11
15
  Gem::Version.new(solidus_version)
12
16
  end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module Core
5
+ # Wrapper for a value that can be different depending on the Solidus version
6
+ #
7
+ # Some configuration defaults can be added or changed when a new Solidus
8
+ # version is released. This class encapsulates getting the correct value for a
9
+ # given Solidus version.
10
+ #
11
+ # The way it works is you provide an initial value in time, plus the version
12
+ # boundary where it got changed. Then you can fetch the value providing the
13
+ # desired Solidus version:
14
+ #
15
+ # @example
16
+ # value = VersionedValue.new(true, "3.0.0" => false)
17
+ # value.call("2.7.0") # => true
18
+ # value.call("3.0.0") # => false
19
+ # value.call("3.1.0") # => false
20
+ #
21
+ # Remember that you must provide the exact boundary when a value got changed,
22
+ # which could easily be during a pre-release:
23
+ #
24
+ # @example
25
+ # value = VersionedValue.new(true, "3.0.0" => false)
26
+ # value.call("3.0.0.alpha") # => true
27
+ #
28
+ # value = VersionedValue.new(true, "3.0.0.alpha" => false)
29
+ # value.call("3.0.0.alpha") # => false
30
+ #
31
+ # Multiple boundaries can also be provided:
32
+ #
33
+ # @example
34
+ # value = VersionedValue.new(0, "2.0.0" => 1, "3.0.0" => 2)
35
+ # value.call("1.0.0") # => 0
36
+ # value.call("2.1.0") # => 1
37
+ # value.call("3.0.0") # => 2
38
+ class VersionedValue
39
+ attr_reader :boundaries
40
+
41
+ # @param initial_value [Any]
42
+ # @param boundary [Hash<String, Any>] Map from version number to new value
43
+ def initialize(initial_value, boundaries = {})
44
+ @boundaries = Hash[
45
+ { '0' => initial_value }
46
+ .merge(boundaries)
47
+ .transform_keys { |version| to_gem_version(version) }
48
+ .sort
49
+ ]
50
+ end
51
+
52
+ # @param solidus_version [String]
53
+ def call(solidus_version = Spree.solidus_version)
54
+ solidus_version = to_gem_version(solidus_version)
55
+ boundaries.fetch(
56
+ boundaries
57
+ .keys
58
+ .reduce do |target, following|
59
+ if target <= solidus_version && solidus_version < following
60
+ target
61
+ else
62
+ following
63
+ end
64
+ end
65
+ )
66
+ end
67
+
68
+ private
69
+
70
+ def to_gem_version(string)
71
+ Gem::Version.new(string)
72
+ end
73
+ end
74
+ end
75
+ end