solidus_core 4.3.4 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/base_helper.rb +2 -2
  3. data/app/mailers/spree/base_mailer.rb +1 -1
  4. data/app/mailers/spree/carton_mailer.rb +1 -1
  5. data/app/mailers/spree/order_mailer.rb +3 -3
  6. data/app/mailers/spree/reimbursement_mailer.rb +1 -1
  7. data/app/models/concerns/spree/active_storage_adapter/normalization.rb +1 -1
  8. data/app/models/concerns/spree/active_storage_adapter.rb +1 -1
  9. data/app/models/concerns/spree/display_money.rb +1 -1
  10. data/app/models/concerns/spree/ordered_property_value_list.rb +2 -2
  11. data/app/models/concerns/spree/user_address_book.rb +4 -4
  12. data/app/models/concerns/spree/user_methods.rb +3 -3
  13. data/app/models/spree/address.rb +6 -6
  14. data/app/models/spree/adjustment.rb +13 -66
  15. data/app/models/spree/calculator/returns/default_refund_amount.rb +1 -1
  16. data/app/models/spree/carton.rb +2 -2
  17. data/app/models/spree/credit_card.rb +6 -6
  18. data/app/models/spree/deprecated_configurable_class.rb +40 -0
  19. data/app/models/spree/fulfilment_changer.rb +4 -4
  20. data/app/models/spree/inventory_unit.rb +2 -2
  21. data/app/models/spree/line_item.rb +1 -1
  22. data/app/models/spree/null_promotion_adjuster.rb +13 -0
  23. data/app/models/spree/null_promotion_advertiser.rb +9 -0
  24. data/app/models/spree/null_promotion_finder.rb +9 -0
  25. data/app/models/spree/null_promotion_handler.rb +44 -0
  26. data/app/models/spree/order.rb +15 -22
  27. data/app/models/spree/order_cancellations.rb +8 -8
  28. data/app/models/spree/order_mutex.rb +2 -2
  29. data/app/models/spree/order_shipping.rb +9 -9
  30. data/app/models/spree/order_updater.rb +6 -10
  31. data/app/models/spree/payment/processing.rb +2 -2
  32. data/app/models/spree/payment.rb +2 -2
  33. data/app/models/spree/payment_create.rb +1 -1
  34. data/app/models/spree/payment_method/store_credit.rb +1 -1
  35. data/app/models/spree/payment_source.rb +5 -1
  36. data/app/models/spree/permission_set.rb +11 -0
  37. data/app/models/spree/product.rb +7 -28
  38. data/app/models/spree/refund.rb +1 -1
  39. data/app/models/spree/reimbursement.rb +4 -4
  40. data/app/models/spree/reimbursement_performer.rb +3 -3
  41. data/app/models/spree/reimbursement_tax_calculator.rb +2 -2
  42. data/app/models/spree/reimbursement_type/credit.rb +1 -1
  43. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +6 -6
  44. data/app/models/spree/reimbursement_type/store_credit.rb +1 -1
  45. data/app/models/spree/return_item.rb +9 -9
  46. data/app/models/spree/role.rb +3 -1
  47. data/app/models/spree/role_permission.rb +8 -0
  48. data/app/models/spree/shipment.rb +7 -7
  49. data/app/models/spree/shipping_category.rb +2 -0
  50. data/app/models/spree/shipping_rate.rb +1 -1
  51. data/app/models/spree/{order_contents.rb → simple_order_contents.rb} +4 -11
  52. data/app/models/spree/stock/estimator.rb +1 -1
  53. data/app/models/spree/stock/inventory_unit_builder.rb +1 -1
  54. data/app/models/spree/stock/package.rb +2 -2
  55. data/app/models/spree/stock/simple_coordinator.rb +1 -1
  56. data/app/models/spree/stock_location.rb +5 -5
  57. data/app/models/spree/store.rb +1 -1
  58. data/app/models/spree/store_credit.rb +17 -15
  59. data/app/models/spree/store_credit_event.rb +3 -3
  60. data/app/models/spree/tax_calculator/default.rb +2 -2
  61. data/app/models/spree/tax_calculator/shipping_rate.rb +1 -1
  62. data/app/models/spree/tax_category.rb +3 -1
  63. data/app/models/spree/tax_rate.rb +3 -3
  64. data/app/models/spree/taxonomy.rb +2 -2
  65. data/app/models/spree/unit_cancel.rb +1 -2
  66. data/app/models/spree/variant/vat_price_generator.rb +1 -1
  67. data/app/models/spree/variant.rb +7 -2
  68. data/app/models/spree/wallet.rb +2 -2
  69. data/app/views/spree/order_mailer/cancel_email.html.erb +1 -1
  70. data/app/views/spree/order_mailer/cancel_email.text.erb +1 -1
  71. data/app/views/spree/order_mailer/confirm_email.html.erb +5 -5
  72. data/app/views/spree/order_mailer/confirm_email.text.erb +5 -5
  73. data/config/locales/en.yml +4 -90
  74. data/db/default/spree/permission_sets.rb +10 -0
  75. data/db/default/spree/return_reasons.rb +3 -1
  76. data/db/default/spree/states.rb +1 -1
  77. data/db/migrate/20160101010000_solidus_one_four.rb +0 -117
  78. data/db/migrate/20240821173254_create_spree_permission_sets_in_core.rb +9 -0
  79. data/db/migrate/20240821173341_create_spree_roles_permissions_in_core.rb +9 -0
  80. data/db/migrate/20240821173641_add_description_to_spree_roles.rb +5 -0
  81. data/db/migrate/20240904152041_add_privilege_and_category_to_spree_permission_sets.rb +6 -0
  82. data/db/seeds.rb +1 -0
  83. data/lib/generators/solidus/install/app_templates/frontend/starter.rb +1 -1
  84. data/lib/generators/solidus/update/update_generator.rb +1 -1
  85. data/lib/generators/spree/dummy/templates/rails/test.rb +6 -1
  86. data/lib/spree/app_configuration.rb +53 -84
  87. data/lib/spree/core/class_constantizer.rb +2 -2
  88. data/lib/spree/core/controller_helpers/payment_parameters.rb +1 -1
  89. data/lib/spree/core/engine.rb +1 -0
  90. data/lib/spree/core/environment/calculators.rb +35 -3
  91. data/lib/spree/core/environment/promotions.rb +25 -4
  92. data/lib/spree/core/environment_extension.rb +16 -2
  93. data/lib/spree/core/importer/order.rb +5 -5
  94. data/lib/spree/core/importer/product.rb +3 -3
  95. data/lib/spree/core/nested_class_set.rb +28 -0
  96. data/lib/spree/core/null_promotion_configuration.rb +84 -0
  97. data/lib/spree/core/product_filters.rb +1 -1
  98. data/lib/spree/core/search/variant.rb +2 -2
  99. data/lib/spree/core/state_machines/order.rb +0 -1
  100. data/lib/spree/core/validators/email.rb +1 -1
  101. data/lib/spree/core/version.rb +2 -2
  102. data/lib/spree/core.rb +2 -6
  103. data/lib/spree/deprecator.rb +9 -0
  104. data/lib/spree/i18n.rb +1 -1
  105. data/lib/spree/mailer_previews/carton_preview.rb +1 -1
  106. data/lib/spree/permission_sets/base.rb +13 -1
  107. data/lib/spree/permission_sets/configuration_display.rb +10 -0
  108. data/lib/spree/permission_sets/configuration_management.rb +10 -0
  109. data/lib/spree/permission_sets/dashboard_display.rb +12 -0
  110. data/lib/spree/permission_sets/default_customer.rb +11 -1
  111. data/lib/spree/permission_sets/order_display.rb +10 -0
  112. data/lib/spree/permission_sets/order_management.rb +10 -0
  113. data/lib/spree/permission_sets/product_display.rb +10 -0
  114. data/lib/spree/permission_sets/product_management.rb +10 -0
  115. data/lib/spree/permission_sets/restricted_stock_display.rb +10 -0
  116. data/lib/spree/permission_sets/restricted_stock_management.rb +10 -0
  117. data/lib/spree/permission_sets/stock_display.rb +10 -0
  118. data/lib/spree/permission_sets/stock_management.rb +10 -0
  119. data/lib/spree/permission_sets/super_user.rb +10 -0
  120. data/lib/spree/permission_sets/user_display.rb +10 -0
  121. data/lib/spree/permission_sets/user_management.rb +10 -0
  122. data/lib/spree/permission_sets.rb +0 -2
  123. data/lib/spree/permitted_attributes.rb +2 -2
  124. data/lib/spree/preferences/store.rb +2 -2
  125. data/lib/spree/testing_support/capybara_ext.rb +1 -1
  126. data/lib/spree/testing_support/dummy_ability.rb +7 -0
  127. data/lib/spree/testing_support/dummy_app/database.yml +2 -2
  128. data/lib/spree/testing_support/dummy_app/migrations.rb +8 -15
  129. data/lib/spree/testing_support/dummy_app/rake_tasks.rb +2 -2
  130. data/lib/spree/testing_support/dummy_app.rb +17 -12
  131. data/lib/spree/testing_support/factories/adjustment_factory.rb +1 -2
  132. data/lib/spree/testing_support/factories/calculator_factory.rb +1 -5
  133. data/lib/spree/testing_support/factories/carton_factory.rb +2 -2
  134. data/lib/spree/testing_support/factories/customer_return_factory.rb +2 -2
  135. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +3 -3
  136. data/lib/spree/testing_support/factories/order_factory.rb +5 -24
  137. data/lib/spree/testing_support/factories/product_factory.rb +1 -1
  138. data/lib/spree/testing_support/factories/shipment_factory.rb +1 -1
  139. data/lib/spree/testing_support/factories/stock_item_factory.rb +5 -1
  140. data/lib/spree/testing_support/factories/stock_package_factory.rb +1 -1
  141. data/lib/spree/testing_support/factories/user_factory.rb +1 -1
  142. data/lib/spree/testing_support/factories/zone_factory.rb +1 -1
  143. data/lib/spree/testing_support/order_walkthrough.rb +3 -3
  144. data/lib/spree/testing_support/shared_examples/calculator.rb +10 -0
  145. data/lib/spree/testing_support/shared_examples/order_factory.rb +141 -0
  146. data/lib/spree/testing_support/shared_examples/working_factory.rb +15 -0
  147. data/lib/tasks/colorado_delivery_fee.rake +2 -2
  148. data/solidus_core.gemspec +6 -6
  149. metadata +60 -91
  150. data/app/jobs/spree/promotion_code_batch_job.rb +0 -26
  151. data/app/mailers/spree/promotion_code_batch_mailer.rb +0 -15
  152. data/app/models/spree/calculator/distributed_amount.rb +0 -33
  153. data/app/models/spree/calculator/flat_percent_item_total.rb +0 -23
  154. data/app/models/spree/calculator/flexi_rate.rb +0 -22
  155. data/app/models/spree/calculator/percent_on_line_item.rb +0 -13
  156. data/app/models/spree/calculator/tiered_flat_rate.rb +0 -52
  157. data/app/models/spree/calculator/tiered_percent.rb +0 -62
  158. data/app/models/spree/order_promotion.rb +0 -27
  159. data/app/models/spree/promotion/actions/create_adjustment.rb +0 -81
  160. data/app/models/spree/promotion/actions/create_item_adjustments.rb +0 -98
  161. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -139
  162. data/app/models/spree/promotion/actions/free_shipping.rb +0 -59
  163. data/app/models/spree/promotion/order_adjustments_recalculator.rb +0 -92
  164. data/app/models/spree/promotion/rules/first_order.rb +0 -38
  165. data/app/models/spree/promotion/rules/first_repeat_purchase_since.rb +0 -36
  166. data/app/models/spree/promotion/rules/item_total.rb +0 -86
  167. data/app/models/spree/promotion/rules/minimum_quantity.rb +0 -59
  168. data/app/models/spree/promotion/rules/nth_order.rb +0 -45
  169. data/app/models/spree/promotion/rules/one_use_per_user.rb +0 -25
  170. data/app/models/spree/promotion/rules/option_value.rb +0 -50
  171. data/app/models/spree/promotion/rules/product.rb +0 -86
  172. data/app/models/spree/promotion/rules/store.rb +0 -26
  173. data/app/models/spree/promotion/rules/taxon.rb +0 -91
  174. data/app/models/spree/promotion/rules/user.rb +0 -34
  175. data/app/models/spree/promotion/rules/user_logged_in.rb +0 -20
  176. data/app/models/spree/promotion/rules/user_role.rb +0 -45
  177. data/app/models/spree/promotion.rb +0 -271
  178. data/app/models/spree/promotion_action.rb +0 -47
  179. data/app/models/spree/promotion_category.rb +0 -8
  180. data/app/models/spree/promotion_chooser.rb +0 -34
  181. data/app/models/spree/promotion_code/batch_builder.rb +0 -64
  182. data/app/models/spree/promotion_code.rb +0 -54
  183. data/app/models/spree/promotion_code_batch.rb +0 -27
  184. data/app/models/spree/promotion_handler/cart.rb +0 -75
  185. data/app/models/spree/promotion_handler/coupon.rb +0 -123
  186. data/app/models/spree/promotion_handler/page.rb +0 -26
  187. data/app/models/spree/promotion_handler/shipping.rb +0 -61
  188. data/app/models/spree/promotion_rule.rb +0 -55
  189. data/app/models/spree/promotion_rule_store.rb +0 -10
  190. data/app/models/spree/promotion_rule_taxon.rb +0 -8
  191. data/app/models/spree/promotion_rule_user.rb +0 -10
  192. data/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_errored.text.erb +0 -2
  193. data/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_finished.text.erb +0 -2
  194. data/db/migrate/20161017102621_create_spree_promotion_code_batch.rb +0 -38
  195. data/db/migrate/20180202190713_create_promotion_rule_stores.rb +0 -12
  196. data/db/migrate/20180328172631_add_join_characters_to_promotion_code_batch.rb +0 -11
  197. data/db/migrate/20190106184413_remove_code_from_spree_promotions.rb +0 -42
  198. data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +0 -20
  199. data/db/migrate/20230322085416_remove_match_policy_from_spree_promotion.rb +0 -5
  200. data/db/migrate/20230325132905_remove_unused_columns_from_promotion_rules.rb +0 -6
  201. data/db/migrate/20230325161633_drop_unused_promo_action_line_items.rb +0 -13
  202. data/db/migrate/20231027084517_add_order_promotions_foreign_key.rb +0 -10
  203. data/db/migrate/20231031175215_add_promotion_order_promotion_foreign_key.rb +0 -10
  204. data/lib/solidus/migrations/promotions_with_code_handlers.rb +0 -66
  205. data/lib/spree/permission_sets/promotion_display.rb +0 -25
  206. data/lib/spree/permission_sets/promotion_management.rb +0 -25
  207. data/lib/spree/ransack_4_1_patch.rb +0 -16
  208. data/lib/spree/testing_support/factories/order_promotion_factory.rb +0 -8
  209. data/lib/spree/testing_support/factories/promotion_category_factory.rb +0 -7
  210. data/lib/spree/testing_support/factories/promotion_code_factory.rb +0 -8
  211. data/lib/spree/testing_support/factories/promotion_factory.rb +0 -98
@@ -26,6 +26,7 @@ require 'uri'
26
26
 
27
27
  module Spree
28
28
  class AppConfiguration < Preferences::Configuration
29
+ include Spree::Core::EnvironmentExtension
29
30
  # Preferences (alphabetized to more easily lookup particular preferences)
30
31
 
31
32
  # @!attribute [rw] address_requires_phone
@@ -216,10 +217,6 @@ module Spree
216
217
  # @return [Integer] Products to show per-page in the frontend (default: +12+)
217
218
  preference :products_per_page, :integer, default: 12
218
219
 
219
- # @!attribute [rw] promotions_per_page
220
- # @return [Integer] Promotions to show per-page in the admin (default: +15+)
221
- preference :promotions_per_page, :integer, default: 15
222
-
223
220
  # @!attribute [rw] require_master_price
224
221
  # @return [Boolean] Require a price on the master variant of a product (default: +true+)
225
222
  preference :require_master_price, :boolean, default: true
@@ -324,12 +321,6 @@ module Spree
324
321
  # Spree::Variant::VatPriceGenerator.
325
322
  class_name_attribute :variant_vat_prices_generator_class, default: 'Spree::Variant::VatPriceGenerator'
326
323
 
327
- # promotion_chooser_class allows extensions to provide their own PromotionChooser
328
- class_name_attribute :promotion_chooser_class, default: 'Spree::PromotionChooser'
329
-
330
- # promotion_adjuster_class allows extensions to provide their own Promotion Adjuster
331
- class_name_attribute :promotion_adjuster_class, default: 'Spree::Promotion::OrderAdjustmentsRecalculator'
332
-
333
324
  class_name_attribute :allocator_class, default: 'Spree::Stock::Allocator::OnHandFirst'
334
325
 
335
326
  class_name_attribute :shipping_rate_sorter_class, default: 'Spree::Stock::ShippingRateSorter'
@@ -367,31 +358,6 @@ module Spree
367
358
  # Spree::OrderUpdater.
368
359
  class_name_attribute :order_recalculator_class, default: 'Spree::OrderUpdater'
369
360
 
370
- # Allows providing a different coupon code handler.
371
- # @!attribute [rw] coupon_code_handler_class
372
- # @see Spree::PromotionHandler::Coupon
373
- # @return [Class] an object that conforms to the API of
374
- # the standard coupon code handler class
375
- # Spree::PromotionHandler::Coupon.
376
- class_name_attribute :coupon_code_handler_class, default: 'Spree::PromotionHandler::Coupon'
377
-
378
- # Allows providing a different shipping promotion handler.
379
- # @!attribute [rw] shipping_promotion_handler_class
380
- # @see Spree::PromotionHandler::Shipping
381
- # @return [Class] an object that conforms to the API of
382
- # the standard shipping promotion handler class
383
- # Spree::PromotionHandler::Coupon.
384
- class_name_attribute :shipping_promotion_handler_class, default: 'Spree::PromotionHandler::Shipping'
385
-
386
- # Allows providing your own Mailer for promotion code batch mailer.
387
- #
388
- # @!attribute [rw] promotion_code_batch_mailer_class
389
- # @return [ActionMailer::Base] an object that responds to "promotion_code_batch_finished",
390
- # and "promotion_code_batch_errored"
391
- # (e.g. an ActionMailer with a "promotion_code_batch_finished" method) with the same
392
- # signature as Spree::PromotionCodeBatchMailer.promotion_code_batch_finished.
393
- class_name_attribute :promotion_code_batch_mailer_class, default: 'Spree::PromotionCodeBatchMailer'
394
-
395
361
  # Allows providing your own Mailer for reimbursement mailer.
396
362
  #
397
363
  # @!attribute [rw] reimbursement_mailer_class
@@ -428,7 +394,7 @@ module Spree
428
394
  # @!attribute [rw] order_contents_class
429
395
  # @return [Class] a class with the same public interfaces as
430
396
  # Spree::OrderContents.
431
- class_name_attribute :order_contents_class, default: 'Spree::OrderContents'
397
+ class_name_attribute :order_contents_class, default: 'Spree::SimpleOrderContents'
432
398
 
433
399
  # Allows providing your own class for shipping an order.
434
400
  #
@@ -585,6 +551,9 @@ module Spree
585
551
  # Enumerable of taxons adhering to the present_taxon_class interface
586
552
  class_name_attribute :taxon_attachment_module, default: "Spree::Taxon::ActiveStorageAttachment"
587
553
 
554
+ # Set of classes that can be promotion adjustment sources
555
+ add_class_set :adjustment_promotion_source_types, default: []
556
+
588
557
  # Configures the absolute path that contains the Solidus engine
589
558
  # migrations. This will be checked at app boot to confirm that all Solidus
590
559
  # migrations are installed.
@@ -619,6 +588,54 @@ module Spree
619
588
  @stock_configuration ||= Spree::Core::StockConfiguration.new
620
589
  end
621
590
 
591
+ # Allows providing your own promotion configuration instance
592
+ # @!attribute [rw] promotions
593
+ # @return [Spree::Core::NullPromotionConfiguration] an object that conforms to the API of
594
+ # the example promotion configuration class Spree::Core::NullPromotionConfiguration.
595
+ attr_writer :promotions
596
+ def promotions
597
+ @promotions ||= Spree::Core::NullPromotionConfiguration.new
598
+ end
599
+
600
+ class << self
601
+ private
602
+
603
+ def promotions_deprecation_message(method, new_method_name = nil)
604
+ "The `Spree::Config.#{method}` preference is deprecated and will be removed in Solidus 5.0. " \
605
+ "Use `Spree::Config.promotions.#{new_method_name || method}` instead"
606
+ end
607
+ end
608
+
609
+ def promotion_adjuster_class
610
+ promotions.order_adjuster_class
611
+ end
612
+
613
+ def promotion_adjuster_class=(klass)
614
+ promotions.order_adjuster_class = klass
615
+ end
616
+ deprecate promotion_adjuster_class: promotions_deprecation_message("promotion_adjuster_class", "order_adjuster_class"), deprecator: Spree.deprecator
617
+ deprecate "promotion_adjuster_class=": promotions_deprecation_message("promotion_adjuster_class=", "order_adjuster_class="), deprecator: Spree.deprecator
618
+
619
+ delegate :promotion_chooser_class, :promotion_chooser_class=, to: :promotions
620
+ deprecate promotion_chooser_class: promotions_deprecation_message("promotion_chooser_class"), deprecator: Spree.deprecator
621
+ deprecate "promotion_chooser_class=": promotions_deprecation_message("promotion_chooser_class="), deprecator: Spree.deprecator
622
+
623
+ delegate :shipping_promotion_handler_class, :shipping_promotion_handler_class=, to: :promotions
624
+ deprecate shipping_promotion_handler_class: promotions_deprecation_message("shipping_promotion_handler_class"), deprecator: Spree.deprecator
625
+ deprecate "shipping_promotion_handler_class=": promotions_deprecation_message("shipping_promotion_handler_class="), deprecator: Spree.deprecator
626
+
627
+ delegate :coupon_code_handler_class, :coupon_code_handler_class=, to: :promotions
628
+ deprecate coupon_code_handler_class: promotions_deprecation_message("coupon_code_handler_class"), deprecator: Spree.deprecator
629
+ deprecate "coupon_code_handler_class=": promotions_deprecation_message("coupon_code_handler_class"), deprecator: Spree.deprecator
630
+
631
+ delegate :promotion_code_batch_mailer_class, :promotion_code_batch_mailer_class=, to: :promotions
632
+ deprecate promotion_code_batch_mailer_class: promotions_deprecation_message("promotion_code_batch_mailer_class"), deprecator: Spree.deprecator
633
+ deprecate "promotion_code_batch_mailer_class=": promotions_deprecation_message("promotion_code_batch_mailer_class="), deprecator: Spree.deprecator
634
+
635
+ delegate :preferred_promotions_per_page, :preferred_promotions_per_page=, to: :promotions
636
+ deprecate preferred_promotions_per_page: promotions_deprecation_message("preferred_promotions_per_page"), deprecator: Spree.deprecator
637
+ deprecate "preferred_promotions_per_page=": promotions_deprecation_message("preferred_promotions_per_page="), deprecator: Spree.deprecator
638
+
622
639
  def roles
623
640
  @roles ||= Spree::RoleConfiguration.new.tap do |roles|
624
641
  roles.assign_permissions :default, ['Spree::PermissionSets::DefaultCustomer']
@@ -634,27 +651,6 @@ module Spree
634
651
 
635
652
  def environment
636
653
  @environment ||= Spree::Core::Environment.new(self).tap do |env|
637
- env.calculators.promotion_actions_create_adjustments = %w[
638
- Spree::Calculator::FlatPercentItemTotal
639
- Spree::Calculator::FlatRate
640
- Spree::Calculator::FlexiRate
641
- Spree::Calculator::TieredPercent
642
- Spree::Calculator::TieredFlatRate
643
- ]
644
-
645
- env.calculators.promotion_actions_create_item_adjustments = %w[
646
- Spree::Calculator::DistributedAmount
647
- Spree::Calculator::FlatRate
648
- Spree::Calculator::FlexiRate
649
- Spree::Calculator::PercentOnLineItem
650
- Spree::Calculator::TieredPercent
651
- ]
652
-
653
- env.calculators.promotion_actions_create_quantity_adjustments = %w[
654
- Spree::Calculator::PercentOnLineItem
655
- Spree::Calculator::FlatRate
656
- ]
657
-
658
654
  env.calculators.shipping_methods = %w[
659
655
  Spree::Calculator::Shipping::FlatPercentItemTotal
660
656
  Spree::Calculator::Shipping::FlatRate
@@ -675,33 +671,6 @@ module Spree
675
671
  Spree::PaymentMethod::Check
676
672
  ]
677
673
 
678
- env.promotions.rules = %w[
679
- Spree::Promotion::Rules::ItemTotal
680
- Spree::Promotion::Rules::Product
681
- Spree::Promotion::Rules::User
682
- Spree::Promotion::Rules::FirstOrder
683
- Spree::Promotion::Rules::UserLoggedIn
684
- Spree::Promotion::Rules::OneUsePerUser
685
- Spree::Promotion::Rules::Taxon
686
- Spree::Promotion::Rules::MinimumQuantity
687
- Spree::Promotion::Rules::NthOrder
688
- Spree::Promotion::Rules::OptionValue
689
- Spree::Promotion::Rules::FirstRepeatPurchaseSince
690
- Spree::Promotion::Rules::UserRole
691
- Spree::Promotion::Rules::Store
692
- ]
693
-
694
- env.promotions.actions = %w[
695
- Spree::Promotion::Actions::CreateAdjustment
696
- Spree::Promotion::Actions::CreateItemAdjustments
697
- Spree::Promotion::Actions::CreateQuantityAdjustments
698
- Spree::Promotion::Actions::FreeShipping
699
- ]
700
-
701
- env.promotions.shipping_actions = %w[
702
- Spree::Promotion::Actions::FreeShipping
703
- ]
704
-
705
674
  env.stock_splitters = %w[
706
675
  Spree::Stock::Splitter::ShippingCategory
707
676
  Spree::Stock::Splitter::Backordered
@@ -8,8 +8,8 @@ module Spree
8
8
  class Set
9
9
  include Enumerable
10
10
 
11
- def initialize
12
- @collection = ::Set.new
11
+ def initialize(default: [])
12
+ @collection = ::Set.new(default)
13
13
  end
14
14
 
15
15
  def <<(klass)
@@ -106,7 +106,7 @@ module Spree
106
106
  params[:order][:payments_attributes] = [
107
107
  {
108
108
  source_attributes: {
109
- wallet_payment_source_id: wallet_payment_source_id,
109
+ wallet_payment_source_id:,
110
110
  verification_value: cvc_confirm
111
111
  }
112
112
  }
@@ -56,6 +56,7 @@ module Spree
56
56
  Spree::Bus.clear
57
57
 
58
58
  %i[
59
+ order_emptied
59
60
  order_finalized
60
61
  order_recalculated
61
62
  reimbursement_reimbursed
@@ -9,9 +9,41 @@ module Spree
9
9
  add_class_set :shipping_methods
10
10
  add_class_set :tax_rates
11
11
 
12
- add_class_set :promotion_actions_create_adjustments
13
- add_class_set :promotion_actions_create_item_adjustments
14
- add_class_set :promotion_actions_create_quantity_adjustments
12
+ def promotion_actions_create_adjustments
13
+ promotion_config.calculators["Spree::Promotion::Actions::CreateAdjustment"]
14
+ end
15
+ deprecate :promotion_actions_create_adjustments, deprecator: Spree.deprecator
16
+
17
+ def promotion_actions_create_adjustments=(value)
18
+ promotion_config.calculators["Spree::Promotion::Actions::CreateAdjustment"] = value
19
+ end
20
+ deprecate :promotion_actions_create_adjustments=, deprecator: Spree.deprecator
21
+
22
+ def promotion_actions_create_item_adjustments
23
+ promotion_config.calculators["Spree::Promotion::Actions::CreateItemAdjustments"]
24
+ end
25
+ deprecate :promotion_actions_create_item_adjustments, deprecator: Spree.deprecator
26
+
27
+ def promotion_actions_create_item_adjustments=(value)
28
+ promotion_config.calculators["Spree::Promotion::Actions::CreateItemAdjustments"] = value
29
+ end
30
+ deprecate :promotion_actions_create_item_adjustments=, deprecator: Spree.deprecator
31
+
32
+ def promotion_actions_create_quantity_adjustments
33
+ promotion_config.calculators["Spree::Promotion::Actions::CreateQuantityAdjustments"]
34
+ end
35
+ deprecate :promotion_actions_create_quantity_adjustments, deprecator: Spree.deprecator
36
+
37
+ def promotion_actions_create_quantity_adjustments=(value)
38
+ promotion_config.calculators["Spree::Promotion::Actions::CreateQuantityAdjustments"] = value
39
+ end
40
+ deprecate :promotion_actions_create_quantity_adjustments=, deprecator: Spree.deprecator
41
+
42
+ private
43
+
44
+ def promotion_config
45
+ Spree::Config.promotions
46
+ end
15
47
  end
16
48
  end
17
49
  end
@@ -4,11 +4,32 @@ module Spree
4
4
  module Core
5
5
  class Environment
6
6
  class Promotions
7
- include EnvironmentExtension
7
+ class << self
8
+ private
8
9
 
9
- add_class_set :rules
10
- add_class_set :actions
11
- add_class_set :shipping_actions
10
+ def promotions_deprecation_message(method)
11
+ "The `Rails.application.config.spree.promotions.#{method}` preference is deprecated and will be removed in Solidus 5.0. " \
12
+ "Use `Spree::Config.promotions.#{method}` instead."
13
+ end
14
+ end
15
+
16
+ delegate :rules, :rules=, to: :promotion_config
17
+ deprecate rules: promotions_deprecation_message("rules"), deprecator: Spree.deprecator
18
+ deprecate "rules=": promotions_deprecation_message("rules="), deprecator: Spree.deprecator
19
+
20
+ delegate :actions, :actions=, to: :promotion_config
21
+ deprecate actions: promotions_deprecation_message("actions"), deprecator: Spree.deprecator
22
+ deprecate "actions=": promotions_deprecation_message("actions="), deprecator: Spree.deprecator
23
+
24
+ delegate :shipping_actions, :shipping_actions=, to: :promotion_config
25
+ deprecate shipping_actions: promotions_deprecation_message("shipping_actions"), deprecator: Spree.deprecator
26
+ deprecate "shipping_actions=": promotions_deprecation_message("shipping_actions="), deprecator: Spree.deprecator
27
+
28
+ private
29
+
30
+ def promotion_config
31
+ Spree::Config.promotions
32
+ end
12
33
  end
13
34
  end
14
35
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'spree/core/class_constantizer'
4
+ require 'spree/core/nested_class_set'
4
5
 
5
6
  module Spree
6
7
  module Core
@@ -8,10 +9,10 @@ module Spree
8
9
  extend ActiveSupport::Concern
9
10
 
10
11
  class_methods do
11
- def add_class_set(name)
12
+ def add_class_set(name, default: [])
12
13
  define_method(name) do
13
14
  set = instance_variable_get("@#{name}")
14
- set ||= send("#{name}=", [])
15
+ set ||= send("#{name}=", default)
15
16
  set
16
17
  end
17
18
 
@@ -21,6 +22,19 @@ module Spree
21
22
  instance_variable_set("@#{name}", set)
22
23
  end
23
24
  end
25
+
26
+ def add_nested_class_set(name, default: {})
27
+ define_method(name) do
28
+ set = instance_variable_get(:"@#{name}")
29
+ set ||= send(:"#{name}=", default)
30
+ set
31
+ end
32
+
33
+ define_method(:"#{name}=") do |hash|
34
+ set = Spree::Core::NestedClassSet.new(hash)
35
+ instance_variable_set(:"@#{name}", set)
36
+ end
37
+ end
24
38
  end
25
39
  end
26
40
  end
@@ -74,7 +74,7 @@ module Spree
74
74
  # able to find the line item if line_item.variant_id |= iu.variant_id
75
75
  shipment.inventory_units.new(
76
76
  variant_id: inventory_unit[:variant_id],
77
- line_item: line_item
77
+ line_item:
78
78
  )
79
79
  end
80
80
 
@@ -91,7 +91,7 @@ module Spree
91
91
  shipment.save!
92
92
 
93
93
  shipping_method = Spree::ShippingMethod.find_by(name: target[:shipping_method]) || Spree::ShippingMethod.find_by!(admin_name: target[:shipping_method])
94
- rate = shipment.shipping_rates.create!(shipping_method: shipping_method,
94
+ rate = shipment.shipping_rates.create!(shipping_method:,
95
95
  cost: target[:cost])
96
96
  shipment.selected_shipping_rate_id = rate.id
97
97
  shipment.update_amounts
@@ -129,7 +129,7 @@ module Spree
129
129
  return [] unless adjustments
130
130
  adjustments.each do |target|
131
131
  adjustment = order.adjustments.build(
132
- order: order,
132
+ order:,
133
133
  amount: target[:amount].to_d,
134
134
  label: target[:label]
135
135
  )
@@ -141,7 +141,7 @@ module Spree
141
141
  def self.create_payments_from_params(payments_hash, order)
142
142
  return [] unless payments_hash
143
143
  payments_hash.each do |target|
144
- payment = order.payments.build order: order
144
+ payment = order.payments.build(order:)
145
145
  payment.amount = target[:amount].to_f
146
146
  # Order API should be using state as that's the normal payment field.
147
147
  # spree_wombat serializes payment state as status so imported orders should fall back to status field.
@@ -170,7 +170,7 @@ module Spree
170
170
  def self.ensure_variant_id_from_params(hash)
171
171
  sku = hash.delete(:sku)
172
172
  unless hash[:variant_id].present?
173
- hash[:variant_id] = Spree::Variant.with_prices.find_by!(sku: sku).id
173
+ hash[:variant_id] = Spree::Variant.with_prices.find_by!(sku:).id
174
174
  end
175
175
  hash
176
176
  end
@@ -18,7 +18,7 @@ module Spree
18
18
  if product.save
19
19
  variants_attrs.each do |variant_attribute|
20
20
  # make sure the product is assigned before the options=
21
- product.variants.create({ product: product }.merge(variant_attribute))
21
+ product.variants.create({ product: }.merge(variant_attribute))
22
22
  end
23
23
 
24
24
  set_up_options
@@ -35,7 +35,7 @@ module Spree
35
35
  product.variants.find(variant_attribute['id'].to_i).update(variant_attribute)
36
36
  else
37
37
  # make sure the product is assigned before the options=
38
- product.variants.create({ product: product }.merge(variant_attribute))
38
+ product.variants.create({ product: }.merge(variant_attribute))
39
39
  end
40
40
  end
41
41
 
@@ -49,7 +49,7 @@ module Spree
49
49
 
50
50
  def set_up_options
51
51
  options_attrs.each do |name|
52
- option_type = Spree::OptionType.where(name: name).first_or_initialize do |ot|
52
+ option_type = Spree::OptionType.where(name:).first_or_initialize do |ot|
53
53
  ot.presentation = name
54
54
  ot.save!
55
55
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spree/core/class_constantizer"
4
+
5
+ module Spree
6
+ module Core
7
+ class NestedClassSet
8
+ attr_reader :klass_sets
9
+
10
+ def initialize(hash = {})
11
+ @klass_sets = hash.map do |key, value|
12
+ [
13
+ key.to_s,
14
+ ClassConstantizer::Set.new(default: value)
15
+ ]
16
+ end.to_h
17
+ end
18
+
19
+ def [](klass)
20
+ klass_sets[klass.to_s] || []
21
+ end
22
+
23
+ def []=(klass, klasses)
24
+ klass_sets[klass.to_s] = ClassConstantizer::Set.new(default: klasses.map(&:to_s))
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module Core
5
+ class NullPromotionConfiguration < Spree::Preferences::Configuration
6
+ include Spree::Core::EnvironmentExtension
7
+
8
+ # order_adjuster_class allows extensions to provide their own Order Adjuster
9
+ class_name_attribute :order_adjuster_class, default: 'Spree::NullPromotionAdjuster'
10
+
11
+ # Allows providing a different coupon code handler.
12
+ # @!attribute [rw] coupon_code_handler_class
13
+ # @see Spree::NullPromotionHandler
14
+ # @return [Class] an object that conforms to the API of
15
+ # the standard coupon code handler class
16
+ # Spree::NullPromotionHandler.
17
+ class_name_attribute :coupon_code_handler_class, default: 'Spree::NullPromotionHandler'
18
+
19
+ # Allows providing a different promotion finder.
20
+ # @!attribute [rw] promotion_finder_class
21
+ # @see Spree::NullPromotionFinder
22
+ # @return [Class] an object that conforms to the API of
23
+ # the standard promotion finder class
24
+ # Spree::NullPromotionFinder.
25
+ class_name_attribute :promotion_finder_class, default: 'Spree::NullPromotionFinder'
26
+
27
+ # Allows getting and setting `Spree::Config.promotion_code_batch_mailer_class`.
28
+ # Both will issue a deprecation warning.
29
+ class_name_attribute :promotion_code_batch_mailer_class, default: 'Spree::DeprecatedConfigurableClass'
30
+ deprecate :promotion_code_batch_mailer_class, :promotion_code_batch_mailer_class=, deprecator: Spree.deprecator
31
+
32
+ # Allows getting and setting `Spree::Config.promotion_chooser_class`.
33
+ # Both will issue a deprecation warning.
34
+ class_name_attribute :promotion_chooser_class, default: 'Spree::DeprecatedConfigurableClass'
35
+ deprecate :promotion_chooser_class, :promotion_chooser_class=, deprecator: Spree.deprecator
36
+
37
+ # Allows getting and setting rules. Deprecated.
38
+ # @!attribute [rw] rules
39
+ # @return [Array] a set of rules
40
+ add_class_set :rules
41
+ deprecate :rules, :rules=, deprecator: Spree.deprecator
42
+
43
+ # Allows getting and setting actions. Deprecated.
44
+ # @!attribute [rw] actions
45
+ # @return [Array] a set of actions
46
+ add_class_set :actions
47
+ deprecate :actions, :actions=, deprecator: Spree.deprecator
48
+
49
+ # Allows getting and setting shipping actions. Deprecated.
50
+ # @!attribute [rw] shipping_actions
51
+ # @return [Array] a set of shipping_actions
52
+ add_class_set :shipping_actions
53
+ deprecate :shipping_actions, :shipping_actions=, deprecator: Spree.deprecator
54
+
55
+ # Allows getting an setting calculators for actions. Deprecated.
56
+ # @!attribute [rw] calculators
57
+ # @return [Spree::Core::NestedClassSet] a set of calculators
58
+ add_nested_class_set :calculators
59
+ deprecate :calculators, :calculators=, deprecator: Spree.deprecator
60
+
61
+ # Allows providing a different promotion shipping promotion handler.
62
+ # @!attribute [rw] shipping_promotion_handler_class
63
+ # @see Spree::NullPromotionHandler
64
+ # @return [Class] an object that conforms to the API of
65
+ # the standard promotion finder class
66
+ # Spree::NullPromotionHandler.
67
+ class_name_attribute :shipping_promotion_handler_class, default: 'Spree::NullPromotionHandler'
68
+ deprecate :shipping_promotion_handler_class, deprecator: Spree.deprecator
69
+ deprecate :shipping_promotion_handler_class=, deprecator: Spree.deprecator
70
+
71
+ # Allows providing a different promotion advertiser.
72
+ # @!attribute [rw] advertiser_class
73
+ # @see Spree::NullPromotionAdvertiser
74
+ # @return [Class] an object that conforms to the API of
75
+ # the standard promotion advertiser class
76
+ # Spree::NullPromotionAdvertiser.
77
+ class_name_attribute :advertiser_class, default: 'Spree::NullPromotionAdvertiser'
78
+
79
+ # !@attribute [rw] promotion_api_attributes
80
+ # @return [Array<Symbol>] Attributes to be returned by the API for a promotion
81
+ preference :promotion_api_attributes, :array, default: []
82
+ end
83
+ end
84
+ end
@@ -112,7 +112,7 @@ module Spree
112
112
  {
113
113
  name: 'Brands',
114
114
  scope: :brand_any,
115
- conds: conds,
115
+ conds:,
116
116
  labels: brands.sort.map { |key| [key, key] }
117
117
  }
118
118
  end
@@ -22,7 +22,7 @@ module Spree
22
22
 
23
23
  def initialize(query_string, scope: Spree::Variant.all)
24
24
  @query_string = query_string
25
- @scope = scope
25
+ @scope = scope.non_template_variants
26
26
  end
27
27
 
28
28
  # Searches the variants table using the ransack 'search_terms' defined on the class.
@@ -39,7 +39,7 @@ module Spree
39
39
  @scope.ransack(search_term_params(word)).result.pluck(:id)
40
40
  end
41
41
 
42
- Spree::Variant.where(id: matches.inject(:&))
42
+ @scope.where(id: matches.inject(:&))
43
43
  end
44
44
 
45
45
  private
@@ -106,7 +106,6 @@ module Spree
106
106
  before_transition to: :delivery, do: :ensure_shipping_address
107
107
  before_transition to: :delivery, do: :create_proposed_shipments
108
108
  before_transition to: :delivery, do: :ensure_available_shipping_rates
109
- before_transition from: :delivery, do: :apply_shipping_promotions
110
109
  end
111
110
 
112
111
  before_transition to: :resumed, do: :ensure_line_item_variants_are_not_deleted
@@ -14,7 +14,7 @@ module Spree
14
14
  class EmailValidator < ActiveModel::EachValidator
15
15
  def validate_each(record, attribute, value)
16
16
  unless Spree::Config.default_email_regexp.match? value
17
- record.errors.add(attribute, :invalid, **{ value: value }.merge!(options))
17
+ record.errors.add(attribute, :invalid, **{ value: }.merge!(options))
18
18
  end
19
19
  end
20
20
  end
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spree
4
- VERSION = "4.3.4"
4
+ VERSION = "4.4.0"
5
5
 
6
6
  def self.solidus_version
7
7
  VERSION
8
8
  end
9
9
 
10
10
  def self.previous_solidus_minor_version
11
- '4.2'
11
+ '4.3'
12
12
  end
13
13
 
14
14
  def self.solidus_gem_version
data/lib/spree/core.rb CHANGED
@@ -11,6 +11,7 @@ require "sprockets/railtie"
11
11
 
12
12
  require 'active_support/deprecation'
13
13
  require 'spree/deprecated_instance_variable_proxy'
14
+ require 'spree/deprecator'
14
15
  require 'acts_as_list'
15
16
  require 'awesome_nested_set'
16
17
  require 'cancan'
@@ -21,17 +22,11 @@ require 'paperclip'
21
22
  require 'ransack'
22
23
  require 'state_machines-activerecord'
23
24
 
24
- require_relative './ransack_4_1_patch'
25
-
26
25
  # This is required because ActiveModel::Validations#invalid? conflicts with the
27
26
  # invalid state of a Payment. In the future this should be removed.
28
27
  StateMachines::Machine.ignore_method_conflicts = true
29
28
 
30
29
  module Spree
31
- def self.deprecator
32
- @deprecator ||= ActiveSupport::Deprecation.new('5.0', 'Solidus')
33
- end
34
-
35
30
  autoload :Deprecation, 'spree/deprecation'
36
31
 
37
32
  mattr_accessor :user_class, default: 'Spree::LegacyUser'
@@ -123,6 +118,7 @@ require 'spree/core/controller_helpers/strong_parameters'
123
118
  require 'spree/core/role_configuration'
124
119
  require 'spree/core/state_machines'
125
120
  require 'spree/core/stock_configuration'
121
+ require 'spree/core/null_promotion_configuration'
126
122
  require 'spree/core/validators/email'
127
123
  require 'spree/permission_sets'
128
124
  require 'spree/user_class_handle'
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/deprecation'
4
+
5
+ module Spree
6
+ def self.deprecator
7
+ @deprecator ||= ActiveSupport::Deprecation.new('5.0', 'Solidus')
8
+ end
9
+ end
data/lib/spree/i18n.rb CHANGED
@@ -5,7 +5,7 @@ require 'i18n'
5
5
  module Spree
6
6
  def self.i18n_available_locales
7
7
  I18n.available_locales.select do |locale|
8
- I18n.t('spree.i18n.this_file_language', locale: locale, fallback: false, default: nil)
8
+ I18n.t('spree.i18n.this_file_language', locale:, fallback: false, default: nil)
9
9
  end
10
10
  end
11
11
 
@@ -7,7 +7,7 @@ module Spree
7
7
  carton = Carton.joins(:orders).last
8
8
  raise "Your database needs at least one shipped order with a carton to render this preview" unless carton
9
9
 
10
- Spree::Config.carton_shipped_email_class.shipped_email(order: carton.orders.first, carton: carton)
10
+ Spree::Config.carton_shipped_email_class.shipped_email(order: carton.orders.first, carton:)
11
11
  end
12
12
  end
13
13
  end