solidus_core 2.11.10 → 3.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (252) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +6 -2
  3. data/app/assets/javascripts/spree.js.erb +0 -51
  4. data/app/controllers/spree/base_controller.rb +1 -1
  5. data/app/helpers/spree/base_helper.rb +1 -1
  6. data/app/helpers/spree/products_helper.rb +2 -2
  7. data/app/helpers/spree/store_helper.rb +0 -11
  8. data/app/mailers/spree/carton_mailer.rb +1 -5
  9. data/app/models/concerns/spree/active_storage_adapter/attachment.rb +30 -11
  10. data/app/models/concerns/spree/active_storage_adapter.rb +1 -1
  11. data/app/models/concerns/spree/adjustment_source.rb +0 -15
  12. data/app/models/concerns/spree/calculated_adjustments.rb +0 -18
  13. data/app/models/concerns/spree/default_price.rb +39 -10
  14. data/app/models/concerns/spree/ransackable_attributes.rb +24 -4
  15. data/app/models/concerns/spree/soft_deletable.rb +2 -4
  16. data/app/models/concerns/spree/user_address_book.rb +10 -37
  17. data/app/models/concerns/spree/user_methods.rb +38 -13
  18. data/app/models/spree/ability.rb +0 -37
  19. data/app/models/spree/address/name.rb +2 -20
  20. data/app/models/spree/address.rb +8 -186
  21. data/app/models/spree/adjustment.rb +7 -33
  22. data/app/models/spree/base.rb +0 -53
  23. data/app/models/spree/calculator/flat_fee.rb +21 -0
  24. data/app/models/spree/calculator/flexi_rate.rb +0 -5
  25. data/app/models/spree/calculator.rb +0 -7
  26. data/app/models/spree/carton.rb +1 -1
  27. data/app/models/spree/country.rb +2 -7
  28. data/app/models/spree/credit_card.rb +1 -28
  29. data/app/models/spree/customer_return.rb +5 -7
  30. data/app/models/spree/image/active_storage_attachment.rb +2 -7
  31. data/app/models/spree/image/paperclip_attachment.rb +2 -2
  32. data/app/models/spree/image.rb +0 -7
  33. data/app/models/spree/inventory_unit.rb +0 -21
  34. data/app/models/spree/line_item.rb +6 -49
  35. data/app/models/spree/log_entry.rb +74 -1
  36. data/app/models/spree/option_type.rb +1 -1
  37. data/app/models/spree/option_value.rb +10 -1
  38. data/app/models/spree/order/number_generator.rb +7 -1
  39. data/app/models/spree/order.rb +82 -170
  40. data/app/models/spree/order_cancellations.rb +4 -24
  41. data/app/models/spree/order_contents.rb +2 -1
  42. data/app/models/spree/order_inventory.rb +1 -1
  43. data/app/models/spree/order_merger.rb +2 -2
  44. data/app/models/spree/order_promotion.rb +1 -1
  45. data/app/models/spree/order_shipping.rb +6 -9
  46. data/app/models/spree/order_taxation.rb +6 -4
  47. data/app/models/spree/order_updater.rb +17 -16
  48. data/app/models/spree/payment/cancellation.rb +1 -1
  49. data/app/models/spree/payment/processing.rb +58 -55
  50. data/app/models/spree/payment.rb +0 -3
  51. data/app/models/spree/payment_create.rb +1 -13
  52. data/app/models/spree/payment_method/bogus_credit_card.rb +6 -7
  53. data/app/models/spree/payment_method/credit_card.rb +1 -3
  54. data/app/models/spree/payment_method/simple_bogus_credit_card.rb +8 -0
  55. data/app/models/spree/payment_method.rb +26 -110
  56. data/app/models/spree/price.rb +3 -3
  57. data/app/models/spree/product/scopes.rb +24 -33
  58. data/app/models/spree/product.rb +15 -42
  59. data/app/models/spree/product_property.rb +1 -1
  60. data/app/models/spree/promotion/actions/create_adjustment.rb +4 -3
  61. data/app/models/spree/promotion/actions/create_item_adjustments.rb +5 -9
  62. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -3
  63. data/app/models/spree/promotion/actions/free_shipping.rb +1 -0
  64. data/app/models/spree/promotion/order_adjustments_recalculator.rb +92 -0
  65. data/app/models/spree/promotion/rules/item_total.rb +50 -6
  66. data/app/models/spree/promotion/rules/product.rb +20 -8
  67. data/app/models/spree/promotion/rules/store.rb +4 -0
  68. data/app/models/spree/promotion/rules/taxon.rb +6 -15
  69. data/app/models/spree/promotion/rules/user.rb +4 -0
  70. data/app/models/spree/promotion.rb +39 -32
  71. data/app/models/spree/promotion_action.rb +6 -9
  72. data/app/models/spree/promotion_code/batch_builder.rb +0 -14
  73. data/app/models/spree/promotion_code.rb +11 -7
  74. data/app/models/spree/promotion_handler/cart.rb +26 -6
  75. data/app/models/spree/promotion_rule.rb +5 -0
  76. data/app/models/spree/property.rb +1 -1
  77. data/app/models/spree/refund.rb +8 -52
  78. data/app/models/spree/reimbursement.rb +5 -43
  79. data/app/models/spree/reimbursement_performer.rb +2 -8
  80. data/app/models/spree/reimbursement_type/credit.rb +1 -4
  81. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +1 -2
  82. data/app/models/spree/reimbursement_type/store_credit.rb +1 -4
  83. data/app/models/spree/return_authorization.rb +2 -5
  84. data/app/models/spree/return_item.rb +4 -24
  85. data/app/models/spree/shipment.rb +3 -56
  86. data/app/models/spree/shipping_method.rb +0 -25
  87. data/app/models/spree/shipping_rate.rb +0 -2
  88. data/app/models/spree/shipping_rate_tax.rb +1 -1
  89. data/app/models/spree/state.rb +1 -5
  90. data/app/models/spree/stock/allocator/on_hand_first.rb +2 -2
  91. data/app/models/spree/stock/availability.rb +11 -3
  92. data/app/models/spree/stock/quantifier.rb +12 -8
  93. data/app/models/spree/stock/simple_coordinator.rb +8 -26
  94. data/app/models/spree/stock/splitter/base.rb +2 -7
  95. data/app/models/spree/stock_item.rb +2 -8
  96. data/app/models/spree/stock_location.rb +2 -2
  97. data/app/models/spree/stock_movement.rb +2 -2
  98. data/app/models/spree/store.rb +0 -12
  99. data/app/models/spree/store_credit.rb +14 -1
  100. data/app/models/spree/store_credit_category.rb +0 -32
  101. data/app/models/spree/store_credit_prioritizer.rb +17 -0
  102. data/app/models/spree/tax/item_tax.rb +3 -2
  103. data/app/models/spree/tax/order_tax.rb +3 -1
  104. data/app/models/spree/tax/tax_helpers.rb +2 -2
  105. data/app/models/spree/tax/tax_location.rb +4 -7
  106. data/app/models/spree/tax_calculator/default.rb +31 -0
  107. data/app/models/spree/tax_calculator/shipping_rate.rb +2 -13
  108. data/app/models/spree/tax_rate.rb +9 -27
  109. data/app/models/spree/taxon/active_storage_attachment.rb +2 -7
  110. data/app/models/spree/taxon/paperclip_attachment.rb +3 -8
  111. data/app/models/spree/taxon.rb +1 -12
  112. data/app/models/spree/taxonomy.rb +1 -1
  113. data/app/models/spree/user_address.rb +0 -5
  114. data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +1 -1
  115. data/app/models/spree/variant/price_selector.rb +34 -4
  116. data/app/models/spree/variant.rb +52 -66
  117. data/app/models/spree/zone.rb +1 -1
  118. data/app/subscribers/spree/mailer_subscriber.rb +4 -0
  119. data/app/subscribers/spree/order_mailer_subscriber.rb +35 -0
  120. data/config/i18n-tasks.yml +134 -0
  121. data/config/locales/en.yml +406 -263
  122. data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +1 -1
  123. data/db/migrate/20201127212108_add_type_before_removal_to_spree_payment_methods.rb +7 -0
  124. data/db/migrate/20210312061050_change_column_null_on_prices.rb +7 -0
  125. data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +20 -0
  126. data/db/migrate/20220805202442_add_level_to_spree_tax_rates.rb +5 -0
  127. data/db/migrate/20221123152807_add_shipping_category_to_spree_variants.rb +5 -0
  128. data/db/seeds.rb +4 -1
  129. data/lib/generators/solidus/install/app_templates/authentication/custom.rb +21 -0
  130. data/lib/generators/solidus/install/app_templates/authentication/devise.rb +16 -0
  131. data/lib/generators/solidus/install/app_templates/authentication/existing.rb +10 -0
  132. data/lib/generators/solidus/install/app_templates/authentication/none.rb +1 -0
  133. data/lib/generators/solidus/install/app_templates/frontend/break_down_solidus_gem.rb +54 -0
  134. data/lib/generators/solidus/install/app_templates/frontend/classic.rb +16 -0
  135. data/lib/generators/solidus/install/app_templates/frontend/none.rb +2 -0
  136. data/lib/generators/solidus/install/app_templates/frontend/starter.rb +3 -0
  137. data/lib/generators/solidus/install/app_templates/payment_method/bolt.rb +13 -0
  138. data/lib/generators/solidus/install/app_templates/payment_method/none.rb +1 -0
  139. data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +10 -0
  140. data/lib/generators/solidus/install/install_generator.rb +247 -149
  141. data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +15 -60
  142. data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/backend/all.js +2 -2
  143. data/lib/generators/solidus/update/templates/config/initializers/new_solidus_defaults.rb.tt +30 -0
  144. data/lib/generators/solidus/update/update_generator.rb +112 -0
  145. data/lib/generators/spree/custom_user/custom_user_generator.rb +6 -4
  146. data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +2 -6
  147. data/lib/generators/spree/custom_user/templates/migration.rb.tt +7 -3
  148. data/lib/generators/spree/dummy/dummy_generator.rb +12 -9
  149. data/lib/generators/spree/dummy/templates/rails/application.rb.tt +0 -1
  150. data/lib/generators/spree/dummy/templates/rails/database.yml +81 -39
  151. data/lib/generators/spree/dummy/templates/rails/storage.yml +3 -0
  152. data/lib/generators/spree/dummy/templates/rails/test.rb +2 -0
  153. data/lib/spree/app_configuration.rb +134 -64
  154. data/lib/spree/bus.rb +20 -0
  155. data/lib/spree/core/class_constantizer.rb +2 -0
  156. data/lib/spree/core/controller_helpers/auth.rb +10 -15
  157. data/lib/spree/core/controller_helpers/current_host.rb +5 -3
  158. data/lib/spree/core/controller_helpers/order.rb +12 -32
  159. data/lib/spree/core/controller_helpers/payment_parameters.rb +0 -54
  160. data/lib/spree/core/controller_helpers/pricing.rb +0 -8
  161. data/lib/spree/core/controller_helpers/search.rb +1 -1
  162. data/lib/spree/core/controller_helpers/strong_parameters.rb +0 -4
  163. data/lib/spree/core/engine.rb +54 -50
  164. data/lib/spree/core/environment_extension.rb +0 -9
  165. data/lib/spree/core/product_filters.rb +1 -41
  166. data/lib/spree/core/role_configuration.rb +0 -14
  167. data/lib/spree/core/search/base.rb +18 -35
  168. data/lib/spree/core/state_machines/order.rb +2 -2
  169. data/lib/spree/core/state_machines.rb +2 -11
  170. data/lib/spree/core/stock_configuration.rb +18 -0
  171. data/lib/spree/core/validators/email.rb +5 -3
  172. data/lib/spree/core/version.rb +5 -1
  173. data/lib/spree/core/versioned_value.rb +75 -0
  174. data/lib/spree/core.rb +40 -11
  175. data/lib/spree/deprecation.rb +1 -1
  176. data/lib/spree/event/configuration.rb +0 -5
  177. data/lib/spree/event/subscriber.rb +0 -18
  178. data/lib/spree/event/subscriber_registry.rb +7 -7
  179. data/lib/spree/event.rb +1 -32
  180. data/lib/spree/i18n.rb +0 -22
  181. data/lib/spree/migrations.rb +13 -11
  182. data/lib/spree/money.rb +3 -18
  183. data/lib/spree/permission_sets/default_customer.rb +8 -1
  184. data/lib/spree/permitted_attributes.rb +17 -59
  185. data/lib/spree/preferences/configuration.rb +84 -0
  186. data/lib/spree/preferences/preferable.rb +13 -0
  187. data/lib/spree/preferences/preferable_class_methods.rb +37 -4
  188. data/lib/spree/preferences/preference_differentiator.rb +29 -0
  189. data/lib/spree/preferences/static_model_preferences.rb +25 -10
  190. data/lib/spree/rails_compatibility.rb +106 -0
  191. data/lib/spree/testing_support/blacklist_urls.rb +1 -1
  192. data/lib/spree/testing_support/bus_helpers.rb +101 -0
  193. data/lib/spree/testing_support/capybara_ext.rb +0 -30
  194. data/lib/spree/testing_support/common_rake.rb +71 -23
  195. data/lib/spree/testing_support/controller_requests.rb +0 -82
  196. data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/backend/all.js +1 -1
  197. data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/frontend/all.js +1 -1
  198. data/lib/spree/testing_support/dummy_app/database.yml +42 -22
  199. data/lib/spree/testing_support/dummy_app/migrations.rb +0 -3
  200. data/lib/spree/testing_support/dummy_app.rb +47 -34
  201. data/lib/spree/testing_support/factories/address_factory.rb +9 -6
  202. data/lib/spree/testing_support/factories/calculator_factory.rb +3 -0
  203. data/lib/spree/testing_support/factories/country_factory.rb +1 -2
  204. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +1 -1
  205. data/lib/spree/testing_support/factories/order_factory.rb +8 -5
  206. data/lib/spree/testing_support/factories/product_factory.rb +4 -1
  207. data/lib/spree/testing_support/factories/promotion_factory.rb +28 -14
  208. data/lib/spree/testing_support/factories/refund_factory.rb +0 -1
  209. data/lib/spree/testing_support/factories/state_factory.rb +8 -2
  210. data/lib/spree/testing_support/factories/store_credit_factory.rb +4 -4
  211. data/lib/spree/testing_support/factories/user_factory.rb +6 -0
  212. data/lib/spree/testing_support/factory_bot.rb +2 -2
  213. data/lib/spree/testing_support/order_walkthrough.rb +6 -8
  214. data/lib/spree/testing_support/preferences.rb +0 -25
  215. data/lib/spree/testing_support/silence_deprecations.rb +9 -0
  216. data/lib/tasks/colorado_delivery_fee.rake +28 -0
  217. data/lib/tasks/payment_method.rake +29 -0
  218. data/lib/tasks/solidus/check_orders_with_invalid_email.rake +18 -0
  219. data/lib/tasks/solidus/delete_prices_with_nil_amount.rake +8 -0
  220. data/lib/tasks/solidus/split_promotions_with_any_match_policy.rake +33 -0
  221. data/solidus_core.gemspec +14 -7
  222. metadata +127 -78
  223. data/app/mailers/spree/test_mailer.rb +0 -13
  224. data/app/models/concerns/spree/user_payment_source.rb +0 -26
  225. data/app/models/spree/calculator/free_shipping.rb +0 -22
  226. data/app/models/spree/calculator/percent_per_item.rb +0 -51
  227. data/app/models/spree/calculator/price_sack.rb +0 -28
  228. data/app/models/spree/gateway/bogus.rb +0 -13
  229. data/app/models/spree/gateway/bogus_simple.rb +0 -13
  230. data/app/models/spree/gateway.rb +0 -14
  231. data/app/models/spree/order/checkout.rb +0 -244
  232. data/app/models/spree/order_capturing.rb +0 -50
  233. data/app/models/spree/promotion_handler/free_shipping.rb +0 -9
  234. data/app/models/spree/tax/shipping_rate_taxer.rb +0 -24
  235. data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -10
  236. data/lib/generators/solidus/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +0 -9
  237. data/lib/generators/spree/install/install_generator.rb +0 -15
  238. data/lib/solidus/migrations/rename_gateways.rb +0 -41
  239. data/lib/spree/core/current_store.rb +0 -24
  240. data/lib/spree/paranoia_deprecations.rb +0 -41
  241. data/lib/spree/promo/environment.rb +0 -12
  242. data/lib/spree/testing_support/bar_ability.rb +0 -19
  243. data/lib/tasks/core.rake +0 -104
  244. data/lib/tasks/email.rake +0 -12
  245. data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +0 -119
  246. data/lib/tasks/migrations/migrate_address_names.rake +0 -158
  247. data/lib/tasks/migrations/migrate_default_billing_addresses_to_address_book.rake +0 -26
  248. data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +0 -22
  249. data/lib/tasks/migrations/migrate_user_addresses.rake +0 -34
  250. data/lib/tasks/migrations/rename_gateways.rake +0 -23
  251. data/lib/tasks/order_capturing.rake +0 -27
  252. data/lib/tasks/upgrade.rake +0 -13
@@ -15,6 +15,12 @@ module Spree
15
15
  generator.test_framework :rspec
16
16
  end
17
17
 
18
+ if ActiveRecord.respond_to?(:yaml_column_permitted_classes) || ActiveRecord::Base.respond_to?(:yaml_column_permitted_classes)
19
+ config.active_record.yaml_column_permitted_classes ||= []
20
+ config.active_record.yaml_column_permitted_classes |=
21
+ [Symbol, BigDecimal, ActiveSupport::HashWithIndifferentAccess]
22
+ end
23
+
18
24
  initializer "spree.environment", before: :load_config_initializers do |app|
19
25
  app.config.spree = Spree::Config.environment
20
26
  end
@@ -40,67 +46,65 @@ module Spree
40
46
  ]
41
47
  end
42
48
 
43
- initializer "spree.core.checking_migrations", before: :load_config_initializers do |_app|
49
+ initializer "spree.core.checking_migrations", after: :load_config_initializers do |_app|
44
50
  Migrations.new(config, engine_name).check
45
51
  end
46
52
 
47
- # Setup Event Subscribers
48
- initializer 'spree.core.initialize_subscribers' do |app|
49
- app.reloader.to_prepare do
50
- Spree::Event.activate_autoloadable_subscribers
51
- end
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
66
+
67
+ %i[
68
+ order_finalized
69
+ order_recalculated
70
+ reimbursement_reimbursed
71
+ reimbursement_errored
72
+ ].each { |event_name| Spree::Bus.register(event_name) }
52
73
 
53
- app.reloader.before_class_unload do
54
- Spree::Event.deactivate_all_subscribers
74
+ Spree::OrderMailerSubscriber.new.subscribe_to(Spree::Bus)
75
+ end
55
76
  end
56
77
  end
57
78
 
79
+ # Load in mailer previews for apps to use in development.
80
+ initializer "spree.core.action_mailer.set_preview_path", after: "action_mailer.set_configs" do |app|
81
+ original_preview_path = app.config.action_mailer.preview_path
82
+ solidus_preview_path = Spree::Core::Engine.root.join 'lib/spree/mailer_previews'
83
+
84
+ app.config.action_mailer.preview_path = "{#{original_preview_path},#{solidus_preview_path}}"
85
+ ActionMailer::Base.preview_path = app.config.action_mailer.preview_path
86
+ end
87
+
58
88
  config.after_initialize do
59
- if Spree::Config.raise_with_invalid_currency == true
60
- Spree::Deprecation.warn(
61
- 'Spree::Config.raise_with_invalid_currency set to true is ' \
62
- 'deprecated. Please note that by switching this value, ' \
63
- 'Spree::LineItem::CurrencyMismatch will not be raised anymore.',
64
- caller
65
- )
66
- end
67
- if Spree::Config.consider_actionless_promotion_active == true
68
- Spree::Deprecation.warn(
69
- 'Spree::Config.consider_actionless_promotion_active set to true is ' \
70
- 'deprecated. Please note that by switching this value, ' \
71
- 'promotions with no actions will be considered active.',
72
- caller
73
- )
74
- end
75
- if Spree::Config.run_order_validations_on_order_updater != true
76
- Spree::Deprecation.warn(
77
- 'Spree::Config.run_order_validations_on_order_updater set to false is ' \
78
- 'deprecated and will not be possibile in Solidus 3.0. Please switch this ' \
79
- 'value to true and check that everything works as expected.',
80
- caller
81
- )
82
- end
89
+ Spree::Config.check_load_defaults_called('Spree::Config')
90
+ Spree::Config.static_model_preferences.validate!
91
+ end
83
92
 
84
- if Spree::Config.use_legacy_address_state_validator != false
85
- Spree::Deprecation.warn(<<~DEPRECATION.squish, caller)
86
- Spree::Config.use_legacy_address_state_validator set to true has been
87
- deprecated and will be removed in Solidus 3.0. The Spree::Address state
88
- validation has been extracted into a configurable external class.
89
- Switch Spree::Config.use_legacy_address_state_validator to false to start
90
- using the external validation class.
91
- DEPRECATION
93
+ config.after_initialize do
94
+ if defined?(Spree::Auth::Engine) &&
95
+ Gem::Version.new(Spree::Auth::VERSION) < Gem::Version.new('2.5.4') &&
96
+ defined?(Spree::UsersController)
97
+ Spree::UsersController.protect_from_forgery with: :exception
92
98
  end
99
+ end
93
100
 
94
- # Load in mailer previews for apps to use in development.
95
- # We need to make sure we call `Preview.all` before requiring our
96
- # previews, otherwise any previews the app attempts to add need to be
97
- # manually required.
98
- if Rails.env.development? || Rails.env.test?
99
- ActionMailer::Preview.all
100
-
101
- Dir[root.join("lib/spree/mailer_previews/**/*_preview.rb")].each do |file|
102
- require_dependency file
103
- end
101
+ config.after_initialize do
102
+ if Spree::Config.use_legacy_events && !ENV['CI']
103
+ Spree::Deprecation.warn <<~MSG
104
+ Your Solidus store is using the legacy event system. You're
105
+ encouraged to switch to the new event bus. After you're done, you
106
+ can remove the `use_legacy_events` setting from `spree.rb`.
107
+ MSG
104
108
  end
105
109
  end
106
110
  end
@@ -22,15 +22,6 @@ module Spree
22
22
  end
23
23
  end
24
24
  end
25
-
26
- def add_class(name)
27
- Spree::Deprecation.warn(
28
- 'This method is deprecated. ' \
29
- "Please use `#{self.class}.add_class_set(#{name.inspect})` instead.",
30
- caller,
31
- )
32
- singleton_class.send(:add_class_set, name)
33
- end
34
25
  end
35
26
  end
36
27
  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)
@@ -153,46 +153,6 @@ module Spree
153
153
  labels: brands.sort.map { |key| [key, key] }
154
154
  }
155
155
  end
156
-
157
- # Provide filtering on the immediate children of a taxon
158
- #
159
- # This doesn't fit the pattern of the examples above, so there's a few changes.
160
- # Firstly, it uses an existing scope which was not built for filtering - and so
161
- # has no need of a conditions mapping, and secondly, it has a mapping of name
162
- # to the argument type expected by the other scope.
163
- #
164
- # This technique is useful for filtering on objects (by passing ids) or with a
165
- # scope that can be used directly (eg. testing only ever on a single property).
166
- #
167
- # This scope selects products in any of the active taxons or their children.
168
- #
169
- def self.taxons_below(taxon)
170
- Spree::Deprecation.warn "taxons_below is deprecated in solidus_core. Please add it to your own application to continue using it."
171
- return Spree::Core::ProductFilters.all_taxons if taxon.nil?
172
- {
173
- name: 'Taxons under ' + taxon.name,
174
- scope: :taxons_id_in_tree_any,
175
- labels: taxon.children.sort_by(&:position).map { |element| [element.name, element.id] },
176
- conds: nil
177
- }
178
- end
179
-
180
- # Filtering by the list of all taxons
181
- #
182
- # Similar idea as above, but we don't want the descendants' products, hence
183
- # it uses one of the auto-generated scopes from Ransack.
184
- #
185
- # idea: expand the format to allow nesting of labels?
186
- def self.all_taxons
187
- Spree::Deprecation.warn "all_taxons is deprecated in solidus_core. Please add it to your own application to continue using it."
188
- taxons = Spree::Taxonomy.all.flat_map { |element| [element.root] + element.root.descendants }
189
- {
190
- name: 'All taxons',
191
- scope: :taxons_id_equals_any,
192
- labels: taxons.sort_by(&:name).map { |element| [element.name, element.id] },
193
- conds: nil # not needed
194
- }
195
- end
196
156
  end
197
157
  end
198
158
  end
@@ -31,20 +31,6 @@ module Spree
31
31
 
32
32
  attr_accessor :roles
33
33
 
34
- class << self
35
- def instance
36
- Spree::Deprecation.warn "Spree::RoleConfiguration.instance is DEPRECATED use Spree::Config.roles instead"
37
- Spree::Config.roles
38
- end
39
-
40
- # Yields the instance of the singleton, used for configuration
41
- # @yieldparam instance [Spree::RoleConfiguration]
42
- def configure
43
- Spree::Deprecation.warn "Spree::RoleConfiguration.configure is deprecated. Call Spree::Config.roles.assign_permissions instead"
44
- yield(Spree::Config.roles)
45
- end
46
- end
47
-
48
34
  # Given a CanCan::Ability, and a user, determine what permissions sets can
49
35
  # be activated on the ability, then activate them.
50
36
  #
@@ -1,11 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spree/deprecation'
4
-
5
3
  module Spree
6
4
  module Core
7
5
  module Search
8
6
  class Base
7
+ class InvalidOptions < ArgumentError
8
+ def initialize(option)
9
+ super("Invalid option passed to the searcher: '#{option}'")
10
+ end
11
+ end
12
+
9
13
  attr_accessor :properties
10
14
  attr_accessor :current_user
11
15
  attr_accessor :pricing_options
@@ -16,17 +20,6 @@ module Spree
16
20
  prepare(params)
17
21
  end
18
22
 
19
- def current_currency=(currency)
20
- self.pricing_options = Spree::Config.pricing_options_class.new(
21
- pricing_options.desired_attributes.merge(currency: currency)
22
- )
23
- end
24
-
25
- def current_currency
26
- pricing_options.currency
27
- end
28
- deprecate :current_currency, :current_currency=, deprecator: Spree::Deprecation
29
-
30
23
  def retrieve_products
31
24
  @products = get_base_scope
32
25
  curr_page = @properties[:page] || 1
@@ -37,19 +30,6 @@ module Spree
37
30
  @products = @products.page(curr_page).per(@properties[:per_page])
38
31
  end
39
32
 
40
- def method_missing(name)
41
- if @properties.key?(name)
42
- Spree::Deprecation.warn "Accessing Searcher's #{name} property using #{self.class.name}##{name} is deprecated without replacement"
43
- @properties[name]
44
- else
45
- super
46
- end
47
- end
48
-
49
- def respond_to_missing?(name)
50
- @properties.key?(name) || super(name)
51
- end
52
-
53
33
  protected
54
34
 
55
35
  def get_base_scope
@@ -77,22 +57,25 @@ module Spree
77
57
  # separate queries most of the time but opt for a join as soon as any
78
58
  # `where` constraints affecting joined tables are added to the search;
79
59
  # which is the case as soon as a taxon is added to the base scope.
80
- scope = scope.preload(master: :currently_valid_prices)
60
+ scope = scope.preload(master: :prices)
81
61
  scope = scope.preload(master: :images) if @properties[:include_images]
82
62
  scope
83
63
  end
84
64
 
85
65
  def add_search_scopes(base_scope)
86
- if @properties[:search]
87
- @properties[:search].each do |name, scope_attribute|
88
- scope_name = name.to_sym
89
- if base_scope.respond_to?(:search_scopes) && base_scope.search_scopes.include?(scope_name.to_sym)
90
- base_scope = base_scope.send(scope_name, *scope_attribute)
91
- else
92
- base_scope = base_scope.merge(Spree::Product.ransack({ scope_name => scope_attribute }).result)
93
- end
66
+ return base_scope unless @properties[:search].present?
67
+ raise InvalidOptions.new(:search) unless @properties[:search].respond_to?(:each_pair)
68
+
69
+ @properties[:search].each_pair do |name, scope_attribute|
70
+ scope_name = name.to_sym
71
+
72
+ if base_scope.respond_to?(:search_scopes) && base_scope.search_scopes.include?(scope_name.to_sym)
73
+ base_scope = base_scope.send(scope_name, *scope_attribute)
74
+ else
75
+ base_scope = base_scope.merge(Spree::Product.ransack({ scope_name => scope_attribute }).result)
94
76
  end
95
77
  end
78
+
96
79
  base_scope
97
80
  end
98
81
 
@@ -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]
@@ -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
 
@@ -68,17 +68,8 @@ module Spree
68
68
 
69
69
  def order
70
70
  @order ||= begin
71
- if Spree::Config.use_legacy_order_state_machine
72
- Spree::Deprecation.warn(
73
- "Spree::Order state machine defined in Spree::Order::Checkout is deprecated. " \
74
- "Future versions of Solidus will use Spree::Core::StateMachines::Order}",
75
- caller
76
- )
77
- 'Spree::Order::Checkout'
78
- else
79
- require 'spree/core/state_machines/order'
80
- 'Spree::Core::StateMachines::Order'
81
- end
71
+ require 'spree/core/state_machines/order'
72
+ 'Spree::Core::StateMachines::Order'
82
73
  end
83
74
 
84
75
  @order.constantize
@@ -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
@@ -12,11 +12,13 @@ module Spree
12
12
  # end
13
13
  #
14
14
  class EmailValidator < ActiveModel::EachValidator
15
- EMAIL_REGEXP = /\A([^@\.]|[^@\.]([^@\s]*)[^@\.])@([^@\s]+\.)+[^@\s]+\z/
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 EMAIL_REGEXP.match? value
19
- record.errors.add(attribute, :invalid, { value: value }.merge!(options))
20
+ unless Spree::Config.default_email_regexp.match? value
21
+ record.errors.add(attribute, :invalid, **{ value: value }.merge!(options))
20
22
  end
21
23
  end
22
24
  end
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spree
4
- VERSION = "2.11.10"
4
+ VERSION = "3.3.1"
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.2'
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
data/lib/spree/core.rb CHANGED
@@ -1,27 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails/all'
3
+ require "action_controller/railtie"
4
+ require "action_mailer/railtie"
5
+ require "action_view/railtie"
6
+ require "active_job/railtie"
7
+ require "active_model/railtie"
8
+ require "active_record/railtie"
9
+ require "active_storage/engine"
10
+ require "sprockets/railtie"
11
+
4
12
  require 'acts_as_list'
5
13
  require 'awesome_nested_set'
6
14
  require 'cancan'
7
15
  require 'friendly_id'
8
16
  require 'kaminari/activerecord'
9
- require 'mail'
10
17
  require 'monetize'
11
18
  require 'paperclip'
12
- require 'paranoia'
13
19
  require 'ransack'
14
20
  require 'state_machines-activerecord'
15
21
 
16
22
  require 'spree/deprecation'
17
- require 'spree/paranoia_deprecations'
23
+ require 'spree/rails_compatibility'
18
24
 
19
25
  # This is required because ActiveModel::Validations#invalid? conflicts with the
20
26
  # invalid state of a Payment. In the future this should be removed.
21
27
  StateMachines::Machine.ignore_method_conflicts = true
22
28
 
23
29
  module Spree
24
- mattr_accessor :user_class
30
+ mattr_accessor :user_class, default: 'Spree::LegacyUser'
25
31
 
26
32
  def self.user_class
27
33
  if @@user_class.is_a?(Class)
@@ -31,6 +37,16 @@ module Spree
31
37
  end
32
38
  end
33
39
 
40
+ # Load the same version defaults for all available Solidus components
41
+ #
42
+ # @see Spree::Preferences::Configuration#load_defaults
43
+ def self.load_defaults(version)
44
+ Spree::Config.load_defaults(version)
45
+ Spree::Frontend::Config.load_defaults(version) if defined?(Spree::Frontend::Config)
46
+ Spree::Backend::Config.load_defaults(version) if defined?(Spree::Backend::Config)
47
+ Spree::Api::Config.load_defaults(version) if defined?(Spree::Api::Config)
48
+ end
49
+
34
50
  # Used to configure Spree.
35
51
  #
36
52
  # Example:
@@ -46,10 +62,25 @@ module Spree
46
62
  end
47
63
 
48
64
  module Core
49
- class GatewayError < RuntimeError; end
65
+ # @api private
66
+ def self.has_install_generator_been_run?(rails_paths: Rails.application.paths, initializer_name: 'spree.rb', dummy_app_name: 'DummyApp::Application')
67
+ does_spree_initializer_exist?(rails_paths, initializer_name) ||
68
+ running_solidus_test_suite_with_dummy_app?(dummy_app_name)
69
+ end
50
70
 
51
- include ActiveSupport::Deprecation::DeprecatedConstantAccessor
52
- deprecate_constant 'DestroyWithOrdersError', ActiveRecord::DeleteRestrictionError, deprecator: Spree::Deprecation
71
+ def self.running_solidus_test_suite_with_dummy_app?(dummy_app_name)
72
+ Rails.env.test? && Rails.application.class.name == dummy_app_name
73
+ end
74
+ private_class_method :running_solidus_test_suite_with_dummy_app?
75
+
76
+ def self.does_spree_initializer_exist?(rails_paths, initializer_name)
77
+ rails_paths['config/initializers'].any? do |path|
78
+ File.exist?(Pathname.new(path).join(initializer_name))
79
+ end
80
+ end
81
+ private_class_method :does_spree_initializer_exist?
82
+
83
+ class GatewayError < RuntimeError; end
53
84
  end
54
85
  end
55
86
 
@@ -61,10 +92,10 @@ require 'spree/core/environment_extension'
61
92
  require 'spree/core/environment/calculators'
62
93
  require 'spree/core/environment/promotions'
63
94
  require 'spree/core/environment'
64
- require 'spree/promo/environment'
65
95
  require 'spree/migrations'
66
96
  require 'spree/migration_helpers'
67
97
  require 'spree/event'
98
+ require 'spree/bus'
68
99
  require 'spree/core/engine'
69
100
 
70
101
  require 'spree/i18n'
@@ -75,10 +106,8 @@ require 'spree/permitted_attributes'
75
106
  require 'spree/core/importer'
76
107
  require 'spree/core/permalinks'
77
108
  require 'spree/core/product_duplicator'
78
- require 'spree/core/current_store'
79
109
  require 'spree/core/controller_helpers/auth'
80
110
  require 'spree/core/controller_helpers/common'
81
- require 'spree/core/controller_helpers/current_host'
82
111
  require 'spree/core/controller_helpers/order'
83
112
  require 'spree/core/controller_helpers/payment_parameters'
84
113
  require 'spree/core/controller_helpers/pricing'
@@ -3,7 +3,7 @@
3
3
  require 'active_support/deprecation'
4
4
 
5
5
  module Spree
6
- Deprecation = ActiveSupport::Deprecation.new('3.0', 'Solidus')
6
+ Deprecation = ActiveSupport::Deprecation.new('4.0', 'Solidus')
7
7
 
8
8
  # This DeprecatedInstanceVariableProxy transforms instance variable to
9
9
  # deprecated instance variable.
@@ -7,11 +7,6 @@ module Spree
7
7
  @subscriber_registry ||= Spree::Event::SubscriberRegistry.new
8
8
  end
9
9
 
10
- def subscribers
11
- Spree::Deprecation.warn("`Spree::Config.events.subscribers` is deprecated. Please use `Spree::Config.events.subscriber_registry`.", caller)
12
- subscriber_registry.send(:registry).keys.map { |module_name| module_name.constantize }
13
- end
14
-
15
10
  attr_writer :adapter, :suffix, :autoload_subscribers
16
11
 
17
12
  def autoload_subscribers
@@ -59,14 +59,6 @@ module Spree
59
59
  # end
60
60
  # end
61
61
  def event_action(method_name, event_name: nil)
62
- mattr_writer "#{method_name}_handler"
63
-
64
- define_method "#{method_name}_handler" do
65
- Spree::Deprecation.warn("#{name}.#{method_name}_handler and #{name}.#{method_name}_handler= from the old events mapping interface are deprecated. Please use the new mapping stored in Spree::Event.subscribers.", caller)
66
-
67
- class_variable_get("@@#{method_name}_handler")
68
- end
69
-
70
62
  event_actions[method_name] = (event_name || method_name).to_s
71
63
  end
72
64
 
@@ -89,16 +81,6 @@ module Spree
89
81
  def deactivate(event_action_name = nil)
90
82
  Spree::Event.subscriber_registry.deactivate_subscriber(self, event_action_name)
91
83
  end
92
-
93
- def subscribe!
94
- Spree::Deprecation.warn("#{self}.subscribe! is deprecated. Please use `#{self}.activate`.", caller)
95
- activate
96
- end
97
-
98
- def unsubscribe!
99
- Spree::Deprecation.warn("#{self}.unsubscribe! is deprecated. Please use `#{self}.deactivate`.", caller)
100
- deactivate
101
- end
102
84
  end
103
85
  end
104
86
  end