solidus_core 2.11.10 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -26,11 +26,41 @@ module Spree
26
26
  # @param [Spree::Variant::PricingOptions] price_options Pricing Options to abide by
27
27
  # @return [Spree::Money, nil] The most specific price for this set of pricing options.
28
28
  def price_for(price_options)
29
- variant.currently_valid_prices.detect do |price|
30
- ( price.country_iso == price_options.desired_attributes[:country_iso] ||
31
- price.country_iso.nil?
29
+ Spree::Deprecation.warn(
30
+ "price_for is deprecated and will be removed. The price_for method
31
+ should return a Spree::Price as described. Please use
32
+ #price_for_options and adjust your frontend code to explicitly call
33
+ &.money where required"
34
+ )
35
+ price_for_options(price_options)&.money
36
+ end
37
+
38
+ # The variant's Spree::Price record, given a set of pricing options
39
+ # @param [Spree::Variant::PricingOptions] price_options Pricing Options to abide by
40
+ # @return [Spree::Price, nil] The most specific price for this set of pricing options.
41
+ def price_for_options(price_options)
42
+ sorted_prices_for(variant).detect do |price|
43
+ (price.country_iso == price_options.desired_attributes[:country_iso] ||
44
+ price.country_iso.nil?
32
45
  ) && price.currency == price_options.desired_attributes[:currency]
33
- end.try!(:money)
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ # Returns `#prices` prioritized for being considered as default price
52
+ #
53
+ # @return [Array<Spree::Price>]
54
+ def sorted_prices_for(variant)
55
+ variant.prices.select do |price|
56
+ variant.discarded? || price.kept?
57
+ end.sort_by do |price|
58
+ [
59
+ price.country_iso.nil? ? 0 : 1,
60
+ price.updated_at || Time.zone.now,
61
+ price.id || Float::INFINITY,
62
+ ]
63
+ end.reverse
34
64
  end
35
65
  end
36
66
  end
@@ -23,20 +23,21 @@ module Spree
23
23
  after_discard do
24
24
  stock_items.discard_all
25
25
  images.destroy_all
26
- prices.discard_all
27
- currently_valid_prices.discard_all
28
26
  end
29
27
 
30
28
  attr_writer :rebuild_vat_prices
31
29
  include Spree::DefaultPrice
32
30
 
33
- belongs_to :product, -> { with_discarded }, touch: true, class_name: 'Spree::Product', inverse_of: :variants, optional: false
31
+ belongs_to :product, -> { with_discarded }, touch: true, class_name: 'Spree::Product', inverse_of: :variants_including_master, optional: false
34
32
  belongs_to :tax_category, class_name: 'Spree::TaxCategory', optional: true
33
+ belongs_to :shipping_category, class_name: "Spree::ShippingCategory", optional: true
35
34
 
36
35
  delegate :name, :description, :slug, :available_on, :discontinue_on, :discontinued?,
37
- :shipping_category_id, :meta_description, :meta_keywords, :shipping_category,
36
+ :meta_description, :meta_keywords,
38
37
  to: :product
39
38
  delegate :tax_category, to: :product, prefix: true
39
+ delegate :shipping_category, :shipping_category_id,
40
+ to: :product, prefix: true
40
41
  delegate :tax_rates, to: :tax_category
41
42
 
42
43
  has_many :inventory_units, inverse_of: :variant
@@ -53,13 +54,7 @@ module Spree
53
54
  has_many :images, -> { order(:position) }, as: :viewable, dependent: :destroy, class_name: "Spree::Image"
54
55
 
55
56
  has_many :prices,
56
- class_name: 'Spree::Price',
57
- dependent: :destroy,
58
- inverse_of: :variant,
59
- autosave: true
60
-
61
- has_many :currently_valid_prices,
62
- -> { currently_valid },
57
+ -> { with_discarded },
63
58
  class_name: 'Spree::Price',
64
59
  dependent: :destroy,
65
60
  inverse_of: :variant,
@@ -74,7 +69,7 @@ module Spree
74
69
 
75
70
  validates :cost_price, numericality: { greater_than_or_equal_to: 0, allow_nil: true }
76
71
  validates :price, numericality: { greater_than_or_equal_to: 0, allow_nil: true }
77
- validates_uniqueness_of :sku, allow_blank: true, case_sensitive: true, if: :enforce_unique_sku?
72
+ validates_uniqueness_of :sku, allow_blank: true, case_sensitive: true, conditions: -> { where(deleted_at: nil) }, if: :enforce_unique_sku?
78
73
 
79
74
  after_create :create_stock_items
80
75
  after_create :set_position
@@ -83,7 +78,7 @@ module Spree
83
78
  after_save :clear_in_stock_cache
84
79
  after_touch :clear_in_stock_cache
85
80
 
86
- after_real_destroy :destroy_option_values_variants
81
+ after_destroy :destroy_option_values_variants
87
82
 
88
83
  # Returns variants that are in stock. When stock locations are provided as
89
84
  # a parameter, the scope is limited to variants that are in stock in the
@@ -118,19 +113,8 @@ module Spree
118
113
  joins(:stock_items).where(arel_conditions.inject(:or)).distinct
119
114
  end
120
115
 
121
- self.whitelisted_ransackable_associations = %w[option_values product prices default_price]
122
- self.whitelisted_ransackable_attributes = %w[weight sku]
123
-
124
- # Returns variants that are not deleted and have a price in the given
125
- # currency.
126
- #
127
- # @deprecated Please use the .with_prices scope instead
128
- # @param currency [String] the currency to filter by; defaults to Spree's default
129
- # @return [ActiveRecord::Relation]
130
- def self.active(currency = nil)
131
- Spree::Deprecation.warn("`Variant.active(currency)` is deprecated. Please use `Variant.with_prices(pricing_options)` instead.", caller)
132
- joins(:prices).where(deleted_at: nil).where('spree_prices.currency' => currency || Spree::Config[:currency]).where('spree_prices.amount IS NOT NULL')
133
- end
116
+ self.allowed_ransackable_associations = %w[option_values product prices default_price]
117
+ self.allowed_ransackable_attributes = %w[weight sku]
134
118
 
135
119
  # Returns variants that have a price for the given pricing options
136
120
  # If you have modified the pricing options class, you might want to modify this scope too.
@@ -161,6 +145,23 @@ module Spree
161
145
  super || product_tax_category
162
146
  end
163
147
 
148
+ # @return [Spree::ShippingCategory] the variant's shipping category
149
+ #
150
+ # This returns the product's shipping category if the shipping category ID on the variant is nil. It looks
151
+ # like an association, but really is an override.
152
+ #
153
+ def shipping_category
154
+ super || product_shipping_category
155
+ end
156
+
157
+ # @return [Integer] the variant's shipping category id
158
+ #
159
+ # This returns the product's shipping category if if the shipping category ID on the variant is nil.
160
+ #
161
+ def shipping_category_id
162
+ super || product_shipping_category_id
163
+ end
164
+
164
165
  # Sets the cost_price for the variant.
165
166
  #
166
167
  # @param price [Any] the price to set
@@ -229,8 +230,8 @@ module Spree
229
230
 
230
231
  # Assign given options hash to option values.
231
232
  #
232
- # @param options [Array] array of hashes with a name and value.
233
- def options=(options = {})
233
+ # @param options [Array<Hash{name: String, value: String}>] array of hashes with a name and value.
234
+ def options=(options = [])
234
235
  options.each do |option|
235
236
  set_option_value(option[:name], option[:value])
236
237
  end
@@ -287,16 +288,17 @@ module Spree
287
288
  end
288
289
 
289
290
  # Chooses an appropriate price for the given pricing options
291
+ # This has been deprecated in favor of #price_for_options.
290
292
  #
291
- # @see Spree::Variant::PriceSelector#price_for
293
+ # @see Spree::Variant::PriceSelector#price_for_options
292
294
  delegate :price_for, to: :price_selector
293
295
 
294
296
  # Returns the difference in price from the master variant
295
297
  def price_difference_from_master(pricing_options = Spree::Config.default_pricing_options)
296
- master_price = product.master.price_for(pricing_options)
297
- variant_price = price_for(pricing_options)
298
+ master_price = product.master.price_for_options(pricing_options)
299
+ variant_price = price_for_options(pricing_options)
298
300
  return unless master_price && variant_price
299
- variant_price - master_price
301
+ Spree::Money.new(variant_price.amount - master_price.amount, currency: pricing_options.currency)
300
302
  end
301
303
 
302
304
  def price_same_as_master?(pricing_options = Spree::Config.default_pricing_options)
@@ -304,25 +306,16 @@ module Spree
304
306
  diff && diff.zero?
305
307
  end
306
308
 
307
- # Converts the variant's price to the given currency.
308
- #
309
- # @deprecated Please use #price_for(pricing_options) instead
310
- # @param currency [String] the desired currency
311
- # @return [Spree::Price] the price in the desired currency
312
- def price_in(currency)
313
- prices.currently_valid.find_by(currency: currency)
314
- end
315
- deprecate price_in: :price_for, deprecator: Spree::Deprecation
309
+ def price_for_options(price_options)
310
+ if price_selector.respond_to?(:price_for_options)
311
+ price_selector.price_for_options(price_options)
312
+ else
313
+ money = price_for(price_options)
314
+ return if money.nil?
316
315
 
317
- # Fetches the price amount in the specified currency.
318
- #
319
- # @deprecated Please use #price_for instead and use a money object rathern than a BigDecimal.
320
- # @param currency (see #price)
321
- # @return [Float] the amount in the specified currency.
322
- def amount_in(currency)
323
- price_in(currency).try(:amount)
316
+ Spree::Price.new(amount: money.to_d, variant: self, currency: price_options.currency)
317
+ end
324
318
  end
325
- deprecate amount_in: :price_for, deprecator: Spree::Deprecation
326
319
 
327
320
  # Generates a friendly name and sku string.
328
321
  #
@@ -346,16 +339,22 @@ module Spree
346
339
  end
347
340
 
348
341
  # @param quantity [Fixnum] how many are desired
342
+ # @param stock_location [Spree::StockLocation] Optionally restrict stock
343
+ # quantity check to a specific stock location. If unspecified it will
344
+ # check inventory in all available StockLocations.
349
345
  # @return [Boolean] true if the desired quantity can be supplied
350
- def can_supply?(quantity = 1)
351
- Spree::Stock::Quantifier.new(self).can_supply?(quantity)
346
+ def can_supply?(quantity = 1, stock_location = nil)
347
+ Spree::Stock::Quantifier.new(self, stock_location).can_supply?(quantity)
352
348
  end
353
349
 
354
350
  # Fetches the on-hand quantity of the variant.
355
351
  #
352
+ # @param stock_location [Spree::StockLocation] Optionally restrict stock
353
+ # quantity check to a specific stock location. If unspecified it will
354
+ # check inventory in all available StockLocations.
356
355
  # @return [Fixnum] the number currently on-hand
357
- def total_on_hand
358
- Spree::Stock::Quantifier.new(self).total_on_hand
356
+ def total_on_hand(stock_location = nil)
357
+ Spree::Stock::Quantifier.new(self, stock_location).total_on_hand
359
358
  end
360
359
 
361
360
  # Shortcut method to determine if inventory tracking is enabled for this
@@ -367,19 +366,6 @@ module Spree
367
366
  track_inventory? && Spree::Config.track_inventory_levels
368
367
  end
369
368
 
370
- # Image that can be used for the variant.
371
- #
372
- # Will first search for images on the variant. If it doesn't find any,
373
- # it'll fallback to any variant image (unless +fallback+ is +false+) or to
374
- # a new {Spree::Image}.
375
- # @param fallback [Boolean] whether or not we should fallback to an image
376
- # not from this variant
377
- # @return [Spree::Image] the image to display
378
- def display_image(fallback: true)
379
- Spree::Deprecation.warn('Spree::Variant#display_image is DEPRECATED. Choose an image from Spree::Variant#gallery instead')
380
- images.first || (fallback && product.variant_images.first) || Spree::Image.new
381
- end
382
-
383
369
  # Determines the variant's property values by verifying which of the product's
384
370
  # variant property rules apply to itself.
385
371
  #
@@ -42,7 +42,7 @@ module Spree
42
42
  alias :members :zone_members
43
43
  accepts_nested_attributes_for :zone_members, allow_destroy: true, reject_if: proc { |member| member['zoneable_id'].blank? }
44
44
 
45
- self.whitelisted_ransackable_attributes = %w[name description]
45
+ self.allowed_ransackable_attributes = %w[name description]
46
46
 
47
47
  # Returns all zones that contain any of the zone members of the zone passed
48
48
  # in. This also includes any country zones that contain the state of the
@@ -3,6 +3,10 @@
3
3
  require 'spree/event/subscriber'
4
4
 
5
5
  module Spree
6
+ # Legacy subscriber
7
+ #
8
+ # This subscriber module is used by the legacy pub/sub system (see
9
+ # {Spree::Event}).
6
10
  module MailerSubscriber
7
11
  include Spree::Event::Subscriber
8
12
 
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ # Mailing after events on a {Spree::Order}
5
+ class OrderMailerSubscriber
6
+ include Omnes::Subscriber
7
+
8
+ handle :order_finalized,
9
+ with: :send_confirmation_email,
10
+ id: :spree_order_mailer_send_confirmation_email
11
+
12
+ handle :reimbursement_reimbursed,
13
+ with: :send_reimbursement_email,
14
+ id: :spree_order_mailer_send_reimbursement_email
15
+
16
+ # Sends confirmation email to the user
17
+ #
18
+ # @param event [Omnes::UnstructuredEvent]
19
+ def send_confirmation_email(event)
20
+ order = event[:order]
21
+ unless order.confirmation_delivered?
22
+ Spree::Config.order_mailer_class.confirm_email(order).deliver_later
23
+ order.update_column(:confirmation_delivered, true)
24
+ end
25
+ end
26
+
27
+ # Sends reimbursement email to the user
28
+ #
29
+ # @param event [Omnes::UnstructuredEvent]
30
+ def send_reimbursement_email(event)
31
+ reimbursement = event[:reimbursement]
32
+ Spree::Config.reimbursement_mailer_class.reimbursement_email(reimbursement.id).deliver_later
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,134 @@
1
+ # i18n-tasks finds and manages missing and unused translations: https://github.com/glebm/i18n-tasks
2
+
3
+ # The "main" locale.
4
+ base_locale: en
5
+ ## All available locales are inferred from the data by default. Alternatively, specify them explicitly:
6
+ # locales: [es, fr]
7
+ ## Reporting locale, default: en. Available: en, ru.
8
+ # internal_locale: en
9
+
10
+ # Read and write translations.
11
+ data:
12
+ ## Translations are read from the file system. Supported format: YAML, JSON.
13
+ ## Provide a custom adapter:
14
+ # adapter: I18n::Tasks::Data::FileSystem
15
+
16
+ # Locale files or `File.find` patterns where translations are read from:
17
+ read:
18
+ ## Default:
19
+ # - config/locales/%{locale}.yml
20
+ ## More files:
21
+ # - config/locales/**/*.%{locale}.yml
22
+
23
+ # Locale files to write new keys to, based on a list of key pattern => file rules. Matched from top to bottom:
24
+ # `i18n-tasks normalize -p` will force move the keys according to these rules
25
+ write:
26
+ ## For example, write devise and simple form keys to their respective files:
27
+ # - ['{devise, simple_form}.*', 'config/locales/\1.%{locale}.yml']
28
+ ## Catch-all default:
29
+ # - config/locales/%{locale}.yml
30
+
31
+ # External locale data (e.g. gems).
32
+ # This data is not considered unused and is never written to.
33
+ external:
34
+ ## Example (replace %#= with %=):
35
+ # - "<%#= %x[bundle info vagrant --path].chomp %>/templates/locales/%{locale}.yml"
36
+
37
+ ## Specify the router (see Readme for details). Valid values: conservative_router, pattern_router, or a custom class.
38
+ # router: conservative_router
39
+
40
+ yaml:
41
+ write:
42
+ # do not wrap lines at 80 characters
43
+ line_width: -1
44
+
45
+ ## Pretty-print JSON:
46
+ # json:
47
+ # write:
48
+ # indent: ' '
49
+ # space: ' '
50
+ # object_nl: "\n"
51
+ # array_nl: "\n"
52
+
53
+ # Find translate calls
54
+ search:
55
+ ## Paths or `File.find` patterns to search in:
56
+ # paths:
57
+ # - app/
58
+
59
+ ## Root directories for relative keys resolution.
60
+ # relative_roots:
61
+ # - app/controllers
62
+ # - app/helpers
63
+ # - app/mailers
64
+ # - app/presenters
65
+ # - app/views
66
+
67
+ ## Files or `File.fnmatch` patterns to exclude from search. Some files are always excluded regardless of this setting:
68
+ ## %w(*.jpg *.png *.gif *.svg *.ico *.eot *.otf *.ttf *.woff *.woff2 *.pdf *.css *.sass *.scss *.less *.yml *.json)
69
+ exclude:
70
+ - app/assets/images
71
+ - app/assets/fonts
72
+ - app/assets/videos
73
+
74
+ ## Alternatively, the only files or `File.fnmatch patterns` to search in `paths`:
75
+ ## If specified, this settings takes priority over `exclude`, but `exclude` still applies.
76
+ # only: ["*.rb", "*.html.slim"]
77
+
78
+ ## If `strict` is `false`, guess usages such as t("categories.#{category}.title"). The default is `true`.
79
+ # strict: true
80
+
81
+ ## Multiple scanners can be used. Their results are merged.
82
+ ## The options specified above are passed down to each scanner. Per-scanner options can be specified as well.
83
+ ## See this example of a custom scanner: https://github.com/glebm/i18n-tasks/wiki/A-custom-scanner-example
84
+
85
+ ## Translation Services
86
+ # translation:
87
+ # # Google Translate
88
+ # # Get an API key and set billing info at https://code.google.com/apis/console to use Google Translate
89
+ # google_translate_api_key: "AbC-dEf5"
90
+ # # DeepL Pro Translate
91
+ # # Get an API key and subscription at https://www.deepl.com/pro to use DeepL Pro
92
+ # deepl_api_key: "48E92789-57A3-466A-9959-1A1A1A1A1A1A"
93
+
94
+ ## Do not consider these keys missing:
95
+ ignore_missing:
96
+ - 'number.currency.format.separator'
97
+ # - 'errors.messages.{accepted,blank,invalid,too_short,too_long}'
98
+ # - '{devise,simple_form}.*'
99
+
100
+ ## Consider these keys used:
101
+ #ignore_unused:
102
+ # - 'activerecord.attributes.*'
103
+ # - '{devise,kaminari,will_paginate}.*'
104
+ # - 'simple_form.{yes,no}'
105
+ # - 'simple_form.{placeholders,hints,labels}.*'
106
+ # - 'simple_form.{error_notification,required}.:'
107
+
108
+ ## Exclude these keys from the `i18n-tasks eq-base' report:
109
+ # ignore_eq_base:
110
+ # all:
111
+ # - common.ok
112
+ # fr,es:
113
+ # - common.brand
114
+
115
+ ## Exclude these keys from the `i18n-tasks check-consistent-interpolations` report:
116
+ # ignore_inconsistent_interpolations:
117
+ # - 'activerecord.attributes.*'
118
+
119
+ ## Ignore these keys completely:
120
+ # ignore:
121
+ # - kaminari.*
122
+
123
+ ## Sometimes, it isn't possible for i18n-tasks to match the key correctly,
124
+ ## e.g. in case of a relative key defined in a helper method.
125
+ ## In these cases you can use the built-in PatternMapper to map patterns to keys, e.g.:
126
+ #
127
+ # <%# I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper',
128
+ # only: %w(*.html.haml *.html.slim),
129
+ # patterns: [['= title\b', '.page_title']] %>
130
+ #
131
+ # The PatternMapper can also match key literals via a special %{key} interpolation, e.g.:
132
+ #
133
+ # <%# I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper',
134
+ # patterns: [['\bSpree\.t[( ]\s*%{key}', 'spree.%{key}']] %>