solidus_core 4.3.5 → 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 +15 -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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f94aaf314615fe63ec5c41581cd2b1b1fe537d9cf83bf24d5ce7de347b69cb2f
4
- data.tar.gz: e391dc6f778dcdecc5640abbab4d8034570ccd276e318008081994b6bf6e8760
3
+ metadata.gz: 2a65544dbf1bc4080f863f20536ce1d7d886183329e9c7fc456c575fbf17c856
4
+ data.tar.gz: f23b80167add2aa1d054af79397ca03c1dc4210ee0a7649276440e519cd4b8e1
5
5
  SHA512:
6
- metadata.gz: f2e16434691f8d081fd2a8bb9de77728d396da83019fad6bc88901757ed816d349fef10e7d3c65c267b4fc696a483e004c3ebe2b8913deb7bba4677d66a8bace
7
- data.tar.gz: 59034679f50f30a91d7883a2b3f31cbeaf957d992bee8a62ea9fb60f283ff9b130a420446bc98a476ff35bec8a117bf83a640161caf77bc9d3ab2c3fff7132d4
6
+ metadata.gz: cf3fe6657b4884a70e838d8bf7ec6c77d5b83fe5ba242e49d33c808c71cb9228b36525aae42532aeecf12c28ec5cb41beead0b851f0bcc6ba8d3b44f4dd297f6
7
+ data.tar.gz: 8185232f7e5a42224db6b7b201b49d312e762608813caffed760aa4c212894ea56ad602e996da69573391c5593d88fbdff60bb36392afff8ee6ead3e64302b55
@@ -48,7 +48,7 @@ module Spree
48
48
 
49
49
  def meta_data_tags
50
50
  meta_data.map do |name, content|
51
- tag('meta', name: name, content: content)
51
+ tag('meta', name:, content:)
52
52
  end.join("\n")
53
53
  end
54
54
 
@@ -111,7 +111,7 @@ module Spree
111
111
  end
112
112
 
113
113
  def available_countries(restrict_to_zone: Spree::Config[:checkout_zone])
114
- countries = Spree::Country.available(restrict_to_zone: restrict_to_zone)
114
+ countries = Spree::Country.available(restrict_to_zone:)
115
115
 
116
116
  country_names = Carmen::Country.all.map do |country|
117
117
  [country.code, country.name]
@@ -11,7 +11,7 @@ module Spree
11
11
  end
12
12
 
13
13
  def money(amount, currency = Spree::Config[:currency])
14
- Spree::Money.new(amount, currency: currency).to_s
14
+ Spree::Money.new(amount, currency:).to_s
15
15
  end
16
16
  helper_method :money
17
17
 
@@ -19,7 +19,7 @@ module Spree
19
19
  @store = @order.store
20
20
  subject = (options[:resend] ? "[#{t('spree.resend').upcase}] " : '')
21
21
  subject += "#{@store.name} #{t('spree.shipment_mailer.shipped_email.subject')} ##{@order.number}"
22
- mail(to: @order.email, from: from_address(@store), subject: subject)
22
+ mail(to: @order.email, from: from_address(@store), subject:)
23
23
  end
24
24
  end
25
25
  end
@@ -7,7 +7,7 @@ module Spree
7
7
  @store = @order.store
8
8
  subject = build_subject(t('.subject'), resend)
9
9
 
10
- mail(to: @order.email, bcc: bcc_address(@store), from: from_address(@store), subject: subject)
10
+ mail(to: @order.email, bcc: bcc_address(@store), from: from_address(@store), subject:)
11
11
  end
12
12
 
13
13
  def cancel_email(order, resend = false)
@@ -15,7 +15,7 @@ module Spree
15
15
  @store = @order.store
16
16
  subject = build_subject(t('.subject'), resend)
17
17
 
18
- mail(to: @order.email, from: from_address(@store), subject: subject)
18
+ mail(to: @order.email, from: from_address(@store), subject:)
19
19
  end
20
20
 
21
21
  def inventory_cancellation_email(order, inventory_units, resend = false)
@@ -23,7 +23,7 @@ module Spree
23
23
  @store = @order.store
24
24
  subject = build_subject(t('spree.order_mailer.inventory_cancellation.subject'), resend)
25
25
 
26
- mail(to: @order.email, from: from_address(@store), subject: subject)
26
+ mail(to: @order.email, from: from_address(@store), subject:)
27
27
  end
28
28
 
29
29
  private
@@ -7,7 +7,7 @@ module Spree
7
7
  store = @reimbursement.order.store
8
8
  subject = (resend ? "[#{t('spree.resend').upcase}] " : '')
9
9
  subject += "#{store.name} #{t('.subject')} ##{@reimbursement.order.number}"
10
- mail(to: @reimbursement.order.email, from: from_address(store), subject: subject)
10
+ mail(to: @reimbursement.order.email, from: from_address(store), subject:)
11
11
  end
12
12
  end
13
13
  end
@@ -32,7 +32,7 @@ module Spree
32
32
  end
33
33
  attachable.rewind
34
34
 
35
- { io: attachable, filename: filename }
35
+ { io: attachable, filename: }
36
36
  end
37
37
  end
38
38
  end
@@ -34,7 +34,7 @@ module Spree
34
34
  method_name = attachment_name
35
35
  override = Module.new do
36
36
  define_method method_name do |*args|
37
- attachment = Attachment.new(super(), styles: styles)
37
+ attachment = Attachment.new(super(), styles:)
38
38
  if args.empty?
39
39
  attachment
40
40
  else
@@ -24,7 +24,7 @@ module Spree
24
24
  money_method = { money_method => {} } unless money_method.is_a? Hash
25
25
  money_method.each do |method_name, opts|
26
26
  define_method("display_#{method_name}") do
27
- default_opts = respond_to?(:currency) ? { currency: currency } : {}
27
+ default_opts = respond_to?(:currency) ? { currency: } : {}
28
28
  Spree::Money.new(send(method_name), default_opts.merge(opts))
29
29
  end
30
30
  end
@@ -18,8 +18,8 @@ module Spree
18
18
 
19
19
  def property_name=(name)
20
20
  unless name.blank?
21
- unless property = Spree::Property.find_by(name: name)
22
- property = Spree::Property.create(name: name, presentation: name)
21
+ unless property = Spree::Property.find_by(name:)
22
+ property = Spree::Property.create(name:, presentation: name)
23
23
  end
24
24
  self.property = property
25
25
  end
@@ -120,7 +120,7 @@ module Spree
120
120
  remove_from_address_book(address_attributes[:id])
121
121
  end
122
122
 
123
- user_addresses.mark_default(user_address, address_type: address_type) if default || first_one
123
+ user_addresses.mark_default(user_address, address_type:) if default || first_one
124
124
 
125
125
  if persisted?
126
126
  user_address.save!
@@ -140,15 +140,15 @@ module Spree
140
140
  end
141
141
 
142
142
  def mark_default_ship_address(address)
143
- user_addresses.mark_default(user_addresses.find_by(address: address))
143
+ user_addresses.mark_default(user_addresses.find_by(address:))
144
144
  end
145
145
 
146
146
  def mark_default_bill_address(address)
147
- user_addresses.mark_default(user_addresses.find_by(address: address), address_type: :billing)
147
+ user_addresses.mark_default(user_addresses.find_by(address:), address_type: :billing)
148
148
  end
149
149
 
150
150
  def remove_from_address_book(address_id)
151
- user_address = user_addresses.find_by(address_id: address_id)
151
+ user_address = user_addresses.find_by(address_id:)
152
152
  if user_address
153
153
  remove_user_address_reference(address_id)
154
154
  user_address.update(archived: true, default: false)
@@ -58,7 +58,7 @@ module Spree
58
58
  def last_incomplete_spree_order(store: nil, only_frontend_viewable: true)
59
59
  self_orders = orders
60
60
  self_orders = self_orders.where(frontend_viewable: true) if only_frontend_viewable
61
- self_orders = self_orders.where(store: store) if store
61
+ self_orders = self_orders.where(store:) if store
62
62
  self_orders = self_orders.where('updated_at > ?', Spree::Config.completable_order_updated_cutoff_days.days.ago) if Spree::Config.completable_order_updated_cutoff_days
63
63
  self_orders = self_orders.where('created_at > ?', Spree::Config.completable_order_created_cutoff_days.days.ago) if Spree::Config.completable_order_created_cutoff_days
64
64
  last_order = self_orders.order(:created_at).last
@@ -73,8 +73,8 @@ module Spree
73
73
 
74
74
  def display_available_store_credit_total(currency:)
75
75
  Spree::Money.new(
76
- available_store_credit_total(currency: currency),
77
- currency: currency,
76
+ available_store_credit_total(currency:),
77
+ currency:,
78
78
  )
79
79
  end
80
80
 
@@ -97,14 +97,14 @@ module Spree
97
97
  # @return [Hash] an ActiveMerchant compatible address hash
98
98
  def active_merchant_hash
99
99
  {
100
- name: name,
101
- address1: address1,
102
- address2: address2,
103
- city: city,
100
+ name:,
101
+ address1:,
102
+ address2:,
103
+ city:,
104
104
  state: state_text,
105
105
  zip: zipcode,
106
106
  country: country.try(:iso),
107
- phone: phone
107
+ phone:
108
108
  }
109
109
  end
110
110
 
@@ -132,7 +132,7 @@ module Spree
132
132
  # @return [Country] setter that sets self.country to the Country with a matching 2 letter iso
133
133
  # @raise [ActiveRecord::RecordNotFound] if country with the iso doesn't exist
134
134
  def country_iso=(iso)
135
- self.country = Spree::Country.find_by!(iso: iso)
135
+ self.country = Spree::Country.find_by!(iso:)
136
136
  end
137
137
 
138
138
  def country_iso
@@ -4,29 +4,18 @@ module Spree
4
4
  # Adjustments represent a change to the +item_total+ of an Order. Each
5
5
  # adjustment has an +amount+ that can be either positive or negative.
6
6
  #
7
- # Adjustments can be "opened" or "closed". Once an adjustment is closed, it
7
+ # Adjustments can be "unfinalized" or "finalized". Once an adjustment is finalized, it
8
8
  # will not be automatically updated.
9
- #
10
- # == Boolean attributes
11
- #
12
- # 1. *eligible?*
13
- #
14
- # This boolean attributes stores whether this adjustment is currently
15
- # eligible for its order. Only eligible adjustments count towards the
16
- # order's adjustment total. This allows an adjustment to be preserved if
17
- # it becomes ineligible so it might be reinstated.
18
9
  class Adjustment < Spree::Base
19
10
  belongs_to :adjustable, polymorphic: true, touch: true, optional: true
20
11
  belongs_to :source, polymorphic: true, optional: true
21
12
  belongs_to :order, class_name: 'Spree::Order', inverse_of: :all_adjustments, optional: true
22
- belongs_to :promotion_code, class_name: 'Spree::PromotionCode', optional: true
23
13
  belongs_to :adjustment_reason, class_name: 'Spree::AdjustmentReason', inverse_of: :adjustments, optional: true
24
14
 
25
15
  validates :adjustable, presence: true
26
16
  validates :order, presence: true
27
17
  validates :label, presence: true
28
18
  validates :amount, numericality: true
29
- validates :promotion_code, presence: true, if: :require_promotion_code?
30
19
 
31
20
  scope :not_finalized, -> { where(finalized: false) }
32
21
  scope :finalized, -> { where(finalized: true) }
@@ -38,18 +27,23 @@ module Spree
38
27
  end
39
28
  scope :price, -> { where(adjustable_type: 'Spree::LineItem') }
40
29
  scope :shipping, -> { where(adjustable_type: 'Spree::Shipment') }
41
- scope :eligible, -> { where(eligible: true) }
30
+ scope :eligible, -> { all }
31
+ class << self
32
+ deprecate :eligible, deprecator: Spree.deprecator
33
+ end
42
34
  scope :charge, -> { where("#{quoted_table_name}.amount >= 0") }
43
35
  scope :credit, -> { where("#{quoted_table_name}.amount < 0") }
44
36
  scope :nonzero, -> { where("#{quoted_table_name}.amount != 0") }
45
- scope :promotion, -> { where(source_type: 'Spree::PromotionAction') }
46
- scope :non_promotion, -> { where.not(source_type: 'Spree::PromotionAction') }
37
+ scope :promotion, -> { where(source_type: Spree::Config.adjustment_promotion_source_types.map(&:to_s)) }
38
+ scope :non_promotion, -> { where.not(source_type: Spree::Config.adjustment_promotion_source_types.map(&:to_s)) }
47
39
  scope :return_authorization, -> { where(source_type: "Spree::ReturnAuthorization") }
48
40
  scope :is_included, -> { where(included: true) }
49
41
  scope :additional, -> { where(included: false) }
50
42
 
51
43
  singleton_class.deprecate :return_authorization, deprecator: Spree.deprecator
52
44
 
45
+ allowed_ransackable_attributes << 'label'
46
+
53
47
  extend DisplayMoney
54
48
  money_methods :amount
55
49
 
@@ -75,7 +69,7 @@ module Spree
75
69
 
76
70
  # @return [Boolean] true when this is a promotion adjustment (Promotion adjustments have a {PromotionAction} source)
77
71
  def promotion?
78
- source_type == 'Spree::PromotionAction'
72
+ source_type.to_s.in?(Spree::Config.adjustment_promotion_source_types.map(&:to_s))
79
73
  end
80
74
 
81
75
  # @return [Boolean] true when this is a tax adjustment (Tax adjustments have a {TaxRate} source)
@@ -88,56 +82,9 @@ module Spree
88
82
  source_type == 'Spree::UnitCancel'
89
83
  end
90
84
 
91
- # Recalculate and persist the amount from this adjustment's source based on
92
- # the adjustable ({Order}, {Shipment}, or {LineItem})
93
- #
94
- # If the adjustment has no source (such as when created manually from the
95
- # admin) or is closed, this is a noop.
96
- #
97
- # @return [BigDecimal] New amount of this adjustment
98
- def recalculate
99
- if finalized? && !tax?
100
- return amount
101
- end
102
-
103
- # If the adjustment has no source, do not attempt to re-calculate the
104
- # amount.
105
- # Some scenarios where this happens:
106
- # - Adjustments that are manually created via the admin backend
107
- # - PromotionAction adjustments where the PromotionAction was deleted
108
- # after the order was completed.
109
- if source.present?
110
- self.amount = source.compute_amount(adjustable)
111
-
112
- if promotion?
113
- self.eligible = calculate_eligibility
114
- end
115
-
116
- # Persist only if changed
117
- # This is only not a save! to avoid the extra queries to load the order
118
- # (for validations) and to touch the adjustment.
119
- update_columns(eligible: eligible, amount: amount, updated_at: Time.current) if changed?
120
- end
121
- amount
122
- end
123
-
124
- # Calculates based on attached promotion (if this is a promotion
125
- # adjustment) whether this promotion is still eligible.
126
- # @api private
127
- # @return [true,false] Whether this adjustment is eligible
128
- def calculate_eligibility
129
- if !finalized? && source && promotion?
130
- source.promotion.eligible?(adjustable, promotion_code: promotion_code)
131
- else
132
- eligible?
133
- end
134
- end
135
- deprecate :calculate_eligibility, deprecator: Spree.deprecator
136
-
137
- private
138
-
139
- def require_promotion_code?
140
- promotion? && !source.promotion.apply_automatically && source.promotion.codes.any?
85
+ def eligible?
86
+ true
141
87
  end
88
+ alias_method :eligible, :eligible?
142
89
  end
143
90
  end
@@ -14,7 +14,7 @@ module Spree
14
14
  private
15
15
 
16
16
  def weighted_order_adjustment_amount(inventory_unit)
17
- inventory_unit.order.adjustments.eligible.non_tax.sum(:amount) * percentage_of_order_total(inventory_unit)
17
+ inventory_unit.order.adjustments.non_tax.sum(:amount) * percentage_of_order_total(inventory_unit)
18
18
  end
19
19
 
20
20
  def weighted_line_item_amount(inventory_unit)
@@ -46,11 +46,11 @@ class Spree::Carton < Spree::Base
46
46
  end
47
47
 
48
48
  def manifest
49
- @manifest ||= Spree::ShippingManifest.new(inventory_units: inventory_units).items
49
+ @manifest ||= Spree::ShippingManifest.new(inventory_units:).items
50
50
  end
51
51
 
52
52
  def manifest_for_order(order)
53
- Spree::ShippingManifest.new(inventory_units: inventory_units).for_order(order).items
53
+ Spree::ShippingManifest.new(inventory_units:).for_order(order).items
54
54
  end
55
55
 
56
56
  def any_exchanges?
@@ -155,12 +155,12 @@ module Spree
155
155
  # card that represents this credit card
156
156
  def to_active_merchant
157
157
  ActiveMerchant::Billing::CreditCard.new(
158
- number: number,
159
- month: month,
160
- year: year,
161
- verification_value: verification_value,
162
- first_name: first_name,
163
- last_name: last_name
158
+ number:,
159
+ month:,
160
+ year:,
161
+ verification_value:,
162
+ first_name:,
163
+ last_name:
164
164
  )
165
165
  end
166
166
 
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ class DeprecatedConfigurableClass
5
+ def self.new(*_args, &_block)
6
+ @deprecation_proxy ||= DeprecationProxy.new
7
+ end
8
+
9
+ def self.method_missing(method_name, *args, &block)
10
+ @deprecation_proxy ||= DeprecationProxy.new
11
+ @deprecation_proxy.send(method_name, args, block)
12
+ end
13
+
14
+ def self.respond_to_missing?(_method_name, _include_private = false)
15
+ true
16
+ end
17
+
18
+ class DeprecationProxy
19
+ def method_missing(_method_name, *_args, &_block)
20
+ issue_deprecation_warning
21
+ self
22
+ end
23
+
24
+ def respond_to_missing?(_method_name, _include_private = false)
25
+ true
26
+ end
27
+
28
+ private
29
+
30
+ def issue_deprecation_warning
31
+ Spree.deprecator.warn(
32
+ <<-WARNING
33
+ It appears you are using Solidus' Legacy promotion system. This system has been extracted into the
34
+ `solidus_legacy_promotions` gem. Please add the gem to your Gemfile and follow in the instructions in the README.
35
+ WARNING
36
+ )
37
+ end
38
+ end
39
+ end
40
+ end
@@ -107,14 +107,14 @@ module Spree
107
107
  # We order by state, because `'backordered' < 'on_hand'`.
108
108
  current_shipment.
109
109
  inventory_units.
110
- where(variant: variant).
110
+ where(variant:).
111
111
  order(state: :asc).
112
112
  limit(new_on_hand_quantity).
113
113
  update_all(shipment_id: desired_shipment.id, state: :on_hand)
114
114
 
115
115
  current_shipment.
116
116
  inventory_units.
117
- where(variant: variant).
117
+ where(variant:).
118
118
  order(state: :asc).
119
119
  limit(quantity - new_on_hand_quantity).
120
120
  update_all(shipment_id: desired_shipment.id, state: :backordered)
@@ -127,7 +127,7 @@ module Spree
127
127
  ActiveRecord::Base.transaction do
128
128
  current_shipment.
129
129
  inventory_units.
130
- where(variant: variant).
130
+ where(variant:).
131
131
  order(state: :asc).
132
132
  limit(quantity).
133
133
  update_all(shipment_id: desired_shipment.id)
@@ -145,7 +145,7 @@ module Spree
145
145
  if current_stock_location != desired_stock_location
146
146
  0
147
147
  else
148
- current_shipment.inventory_units.where(variant: variant).on_hand.count
148
+ current_shipment.inventory_units.where(variant:).on_hand.count
149
149
  end
150
150
  end
151
151
 
@@ -64,7 +64,7 @@ module Spree
64
64
  # stock location that is associated with this inventory unit's variant
65
65
  def find_stock_item
66
66
  Spree::StockItem.where(stock_location_id: shipment.stock_location_id,
67
- variant_id: variant_id).first
67
+ variant_id:).first
68
68
  end
69
69
 
70
70
  # @return [Spree::ReturnItem] a valid return item for this inventory unit
@@ -114,7 +114,7 @@ module Spree
114
114
 
115
115
  def ensure_can_destroy
116
116
  if !backordered? && !on_hand?
117
- errors.add(:state, :cannot_destroy, state: state)
117
+ errors.add(:state, :cannot_destroy, state:)
118
118
  throw :abort
119
119
  end
120
120
 
@@ -62,7 +62,7 @@ module Spree
62
62
  # @return [BigDecimal] the amount of this item, taking into consideration
63
63
  # all non-tax adjustments.
64
64
  def total_before_tax
65
- amount + adjustments.select { |value| !value.tax? && value.eligible? }.sum(&:amount)
65
+ amount + adjustments.reject(&:tax?).sum(&:amount)
66
66
  end
67
67
 
68
68
  # @return [BigDecimal] the amount of this line item before VAT tax
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ class NullPromotionAdjuster
5
+ def initialize(order)
6
+ @order = order
7
+ end
8
+
9
+ def call
10
+ @order
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ class NullPromotionAdvertiser
5
+ def self.for_product(_product)
6
+ []
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module NullPromotionFinder
5
+ def self.by_code_or_id(*)
6
+ raise ActiveRecord::RecordNotFound, "No promotion system configured."
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ class NullPromotionHandler
5
+ attr_reader :order, :coupon_code
6
+
7
+ def initialize(order)
8
+ @order = order
9
+ @coupon_code = order.coupon_code&.downcase
10
+ end
11
+
12
+ def activate
13
+ @order
14
+ end
15
+
16
+ def apply
17
+ self
18
+ end
19
+
20
+ def can_apply?
21
+ true
22
+ end
23
+
24
+ def error
25
+ nil
26
+ end
27
+
28
+ def success
29
+ true
30
+ end
31
+
32
+ def successful?
33
+ true
34
+ end
35
+
36
+ def status_code
37
+ :coupon_code_applied
38
+ end
39
+
40
+ def status
41
+ I18n.t(:coupon_code_applied, scope: [:spree, :null_promotion_handler])
42
+ end
43
+ end
44
+ end