solidus_core 2.10.0.beta1 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/base_helper.rb +4 -4
  3. data/app/helpers/spree/products_helper.rb +2 -1
  4. data/app/jobs/spree/promotion_code_batch_job.rb +2 -2
  5. data/app/models/concerns/spree/user_methods.rb +2 -2
  6. data/app/models/spree/address.rb +11 -15
  7. data/app/models/spree/adjustment.rb +11 -0
  8. data/app/models/spree/calculator/price_sack.rb +1 -1
  9. data/app/models/spree/calculator/shipping/flexi_rate.rb +2 -2
  10. data/app/models/spree/calculator/tiered_flat_rate.rb +5 -5
  11. data/app/models/spree/calculator/tiered_percent.rb +6 -6
  12. data/app/models/spree/carton.rb +1 -1
  13. data/app/models/spree/credit_card.rb +2 -2
  14. data/app/models/spree/inventory_unit.rb +1 -19
  15. data/app/models/spree/line_item.rb +1 -1
  16. data/app/models/spree/order.rb +3 -2
  17. data/app/models/spree/order/checkout.rb +1 -1
  18. data/app/models/spree/order/payments.rb +2 -2
  19. data/app/models/spree/order_capturing.rb +2 -2
  20. data/app/models/spree/order_taxation.rb +2 -2
  21. data/app/models/spree/payment.rb +4 -41
  22. data/app/models/spree/payment/processing.rb +2 -2
  23. data/app/models/spree/payment_method.rb +2 -2
  24. data/app/models/spree/product.rb +3 -3
  25. data/app/models/spree/product/scopes.rb +8 -7
  26. data/app/models/spree/promotion.rb +27 -12
  27. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +1 -1
  28. data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
  29. data/app/models/spree/promotion/rules/option_value.rb +2 -2
  30. data/app/models/spree/promotion/rules/product.rb +3 -3
  31. data/app/models/spree/promotion_action.rb +1 -1
  32. data/app/models/spree/promotion_chooser.rb +2 -2
  33. data/app/models/spree/promotion_code.rb +9 -8
  34. data/app/models/spree/promotion_code/batch_builder.rb +3 -3
  35. data/app/models/spree/promotion_rule.rb +1 -1
  36. data/app/models/spree/refund.rb +2 -2
  37. data/app/models/spree/reimbursement.rb +3 -11
  38. data/app/models/spree/reimbursement/reimbursement_type_engine.rb +1 -1
  39. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +2 -2
  40. data/app/models/spree/return_authorization.rb +1 -7
  41. data/app/models/spree/return_item.rb +3 -42
  42. data/app/models/spree/return_item/eligibility_validator/default.rb +1 -1
  43. data/app/models/spree/shipment.rb +4 -38
  44. data/app/models/spree/shipping_calculator.rb +0 -4
  45. data/app/models/spree/shipping_method.rb +1 -1
  46. data/app/models/spree/state.rb +1 -1
  47. data/app/models/spree/stock/differentiator.rb +1 -1
  48. data/app/models/spree/stock/package.rb +1 -1
  49. data/app/models/spree/stock_item.rb +1 -1
  50. data/app/models/spree/stock_quantities.rb +13 -12
  51. data/app/models/spree/tax_calculator/default.rb +0 -4
  52. data/app/models/spree/tax_calculator/shipping_rate.rb +0 -3
  53. data/app/models/spree/tax_rate.rb +4 -0
  54. data/app/models/spree/taxon/paperclip_attachment.rb +13 -0
  55. data/app/models/spree/user_last_url_storer.rb +46 -0
  56. data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +36 -0
  57. data/app/models/spree/variant.rb +9 -9
  58. data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +1 -1
  59. data/app/models/spree/zone.rb +1 -1
  60. data/config/initializers/money.rb +2 -0
  61. data/config/locales/en.yml +12 -0
  62. data/lib/generators/spree/install/install_generator.rb +3 -0
  63. data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +8 -0
  64. data/lib/spree/app_configuration.rb +18 -3
  65. data/lib/spree/core.rb +12 -0
  66. data/lib/spree/core/controller_helpers/auth.rb +1 -13
  67. data/lib/spree/core/engine.rb +2 -2
  68. data/lib/spree/core/environment_extension.rb +9 -0
  69. data/lib/spree/core/importer/order.rb +26 -26
  70. data/lib/spree/core/product_filters.rb +15 -15
  71. data/lib/spree/core/role_configuration.rb +2 -2
  72. data/lib/spree/core/search/variant.rb +1 -1
  73. data/lib/spree/core/state_machines.rb +78 -0
  74. data/lib/spree/core/state_machines/inventory_unit.rb +42 -0
  75. data/lib/spree/core/state_machines/payment.rb +61 -0
  76. data/lib/spree/core/state_machines/reimbursement.rb +33 -0
  77. data/lib/spree/core/state_machines/return_authorization.rb +32 -0
  78. data/lib/spree/core/state_machines/return_item/acceptance_status.rb +51 -0
  79. data/lib/spree/core/state_machines/return_item/reception_status.rb +42 -0
  80. data/lib/spree/core/state_machines/shipment.rb +58 -0
  81. data/lib/spree/core/stock_configuration.rb +1 -0
  82. data/lib/spree/core/validators/email.rb +1 -8
  83. data/lib/spree/core/version.rb +1 -1
  84. data/lib/spree/money.rb +2 -2
  85. data/lib/spree/permission_sets/user_management.rb +3 -0
  86. data/lib/spree/permitted_attributes.rb +3 -3
  87. data/lib/spree/preferences/static_model_preferences.rb +2 -2
  88. data/lib/spree/testing_support/dummy_app.rb +4 -1
  89. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +8 -1
  90. data/lib/spree/testing_support/factories/promotion_factory.rb +7 -0
  91. data/lib/spree/testing_support/factories/stock_package_factory.rb +1 -1
  92. data/solidus_core.gemspec +2 -2
  93. data/spec/lib/spree/core/environment_extension_spec.rb +12 -1
  94. data/spec/lib/spree/core/stock_configuration_spec.rb +36 -0
  95. data/spec/lib/spree/core/validators/email_spec.rb +18 -18
  96. data/spec/models/spree/address_spec.rb +23 -0
  97. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +1 -1
  98. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +1 -1
  99. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +2 -2
  100. data/spec/models/spree/calculator/shipping/per_item_spec.rb +1 -1
  101. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +24 -15
  102. data/spec/models/spree/carton_spec.rb +8 -0
  103. data/spec/models/spree/classification_spec.rb +21 -9
  104. data/spec/models/spree/concerns/user_address_book_spec.rb +4 -4
  105. data/spec/models/spree/concerns/user_methods_spec.rb +2 -1
  106. data/spec/models/spree/order_merger_spec.rb +3 -3
  107. data/spec/models/spree/order_spec.rb +8 -15
  108. data/spec/models/spree/order_updater_spec.rb +4 -3
  109. data/spec/models/spree/payment_create_spec.rb +4 -14
  110. data/spec/models/spree/permission_sets/user_management_spec.rb +2 -0
  111. data/spec/models/spree/preference_spec.rb +4 -4
  112. data/spec/models/spree/preferences/preferable_spec.rb +3 -3
  113. data/spec/models/spree/preferences/statically_configurable_spec.rb +2 -2
  114. data/spec/models/spree/promotion_rule_spec.rb +6 -6
  115. data/spec/models/spree/promotion_spec.rb +73 -52
  116. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +1 -1
  117. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +1 -1
  118. data/spec/models/spree/returns_calculator_spec.rb +2 -2
  119. data/spec/models/spree/shipping_calculator_spec.rb +1 -13
  120. data/spec/models/spree/shipping_method_spec.rb +32 -0
  121. data/spec/models/spree/stock/availability_validator_spec.rb +2 -2
  122. data/spec/models/spree/stock/differentiator_spec.rb +2 -2
  123. data/spec/models/spree/stock/estimator_spec.rb +3 -3
  124. data/spec/models/spree/stock/package_spec.rb +28 -28
  125. data/spec/models/spree/stock/simple_coordinator_spec.rb +11 -11
  126. data/spec/models/spree/stock/splitter/base_spec.rb +4 -4
  127. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +7 -7
  128. data/spec/models/spree/stock_quantities_spec.rb +1 -1
  129. data/spec/models/spree/store_credit_spec.rb +1 -1
  130. data/spec/models/spree/tax_rate_spec.rb +1 -0
  131. data/spec/models/spree/taxons/paperclip_attachment_spec.rb +29 -0
  132. data/spec/models/spree/user_last_url_storer/rules/authentication_rule_spec.rb +31 -0
  133. data/spec/models/spree/user_last_url_storer_spec.rb +60 -0
  134. metadata +17 -12
  135. data/spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb +0 -162
  136. data/spec/models/spree/order/updating_spec.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d36219391d7785627d0a35a8929f818350001dbe3f06149bc0f954daadaf301
4
- data.tar.gz: 982ce1d0d2866b852b7e421361f06c81b6b4a98066093e5d6c8ae03ceb0d5866
3
+ metadata.gz: 0aabcb199c31d99f564afef69740c95363dff238117b5692ff26226f91f6bf06
4
+ data.tar.gz: fd982fa13569c953468edb060c7019f541b435cd404787b8c0674ff3db324606
5
5
  SHA512:
6
- metadata.gz: 1cedc37f87d1641177f28e8172b6c667da086cd3ed4c1e8081390ffb8026974dd582731c5a4a2d827ff3333495e51705c0975b3efff5e25bce7d3b030302a7b4
7
- data.tar.gz: f577d26426c6723f1b6bba21d11c647549a6569851b286b29756dfe9b8eccd710f235452393b12f8bd3ab43666eefd7b2d519024888e737233c9a69b14a81fc5
6
+ metadata.gz: d0532174df1e8cac35d61f180102c5123dec9f43d41b29d61a6ce37a87cb1d29f60a902de56ba5b0394094ef5c0ea28e13ca81033df598de93209dcf7105dbc5
7
+ data.tar.gz: 9df7b935ee802245a93da97b4341aacb7343aac7e6319b5b1673b30a0145f9f46d539aa5c2e3ab190e1e7dbf69b37843ff8c4739497ef24233a572fa49eb6d4d
@@ -79,16 +79,16 @@ module Spree
79
79
 
80
80
  crumbs << [t('spree.products'), products_path]
81
81
  if taxon
82
- crumbs += taxon.ancestors.collect { |a| [a.name, spree.nested_taxons_path(a.permalink)] } unless taxon.ancestors.empty?
82
+ crumbs += taxon.ancestors.collect { |ancestor| [ancestor.name, spree.nested_taxons_path(ancestor.permalink)] } unless taxon.ancestors.empty?
83
83
  crumbs << [taxon.name, spree.nested_taxons_path(taxon.permalink)]
84
84
  end
85
85
 
86
86
  separator = raw(separator)
87
87
 
88
- items = crumbs.each_with_index.collect do |crumb, i|
88
+ items = crumbs.each_with_index.collect do |crumb, index|
89
89
  content_tag(:li, itemprop: 'itemListElement', itemscope: '', itemtype: 'https://schema.org/ListItem') do
90
90
  link_to(crumb.last, itemprop: 'item') do
91
- content_tag(:span, crumb.first, itemprop: 'name') + tag('meta', { itemprop: 'position', content: (i + 1).to_s }, false, false)
91
+ content_tag(:span, crumb.first, itemprop: 'name') + tag('meta', { itemprop: 'position', content: (index + 1).to_s }, false, false)
92
92
  end + (crumb == crumbs.last ? '' : separator)
93
93
  end
94
94
  end
@@ -122,7 +122,7 @@ module Spree
122
122
  countries.collect do |country|
123
123
  country.name = country_names.fetch(country.iso, country.name)
124
124
  country
125
- end.sort_by { |c| c.name.parameterize }
125
+ end.sort_by { |country| country.name.parameterize }
126
126
  end
127
127
 
128
128
  def seo_url(taxon)
@@ -36,7 +36,8 @@ module Spree
36
36
  def variant_full_price(variant)
37
37
  return if variant.product.variants
38
38
  .with_prices(current_pricing_options)
39
- .all? { |v| v.price_same_as_master?(current_pricing_options) }
39
+ .all? { |variant_with_prices| variant_with_prices.price_same_as_master?(current_pricing_options) }
40
+
40
41
  variant.price_for(current_pricing_options).to_html
41
42
  end
42
43
 
@@ -14,13 +14,13 @@ module Spree
14
14
  .promotion_code_batch_finished(promotion_code_batch)
15
15
  .deliver_now
16
16
  end
17
- rescue StandardError => e
17
+ rescue StandardError => error
18
18
  if promotion_code_batch.email?
19
19
  Spree::Config.promotion_code_batch_mailer_class
20
20
  .promotion_code_batch_errored(promotion_code_batch)
21
21
  .deliver_now
22
22
  end
23
- raise e
23
+ raise error
24
24
  end
25
25
  end
26
26
  end
@@ -73,8 +73,8 @@ module Spree
73
73
  deprecate total_available_store_credit: :available_store_credit_total, deprecator: Spree::Deprecation
74
74
 
75
75
  def available_store_credit_total(currency:)
76
- store_credits.reload.to_a.
77
- select { |c| c.currency == currency }.
76
+ store_credits.to_a.
77
+ select { |credit| credit.currency == currency }.
78
78
  sum(&:amount_remaining)
79
79
  end
80
80
 
@@ -30,8 +30,9 @@ module Spree
30
30
  where(value_attributes(attributes))
31
31
  end
32
32
 
33
- def self.build_default
34
- new(country: Spree::Country.default)
33
+ # @return [Address] an address with default attributes
34
+ def self.build_default(*args, &block)
35
+ where(country: Spree::Country.default).build(*args, &block)
35
36
  end
36
37
 
37
38
  # @return [Address] an equal address already in the database or a newly created one
@@ -58,21 +59,16 @@ module Spree
58
59
  end
59
60
 
60
61
  # @return [Hash] hash of attributes contributing to value equality with optional merge
61
- def self.value_attributes(base_attributes, merge_attributes = nil)
62
- # dup because we may modify firstname/lastname.
63
- base = base_attributes.dup
64
-
65
- base.stringify_keys!
66
-
67
- if merge_attributes
68
- base.merge!(merge_attributes.stringify_keys)
69
- end
62
+ def self.value_attributes(base_attributes, merge_attributes = {})
63
+ base = base_attributes.stringify_keys.merge(merge_attributes.stringify_keys)
70
64
 
71
65
  # TODO: Deprecate these aliased attributes
72
- base['firstname'] = base.delete('first_name') if base.key?('first_name')
73
- base['lastname'] = base.delete('last_name') if base.key?('last_name')
66
+ base['firstname'] = base['first_name'] if base.key?('first_name')
67
+ base['lastname'] = base['last_name'] if base.key?('last_name')
68
+
69
+ excluded_attributes = DB_ONLY_ATTRS + %w(first_name last_name)
74
70
 
75
- base.except!(*DB_ONLY_ATTRS)
71
+ base.except(*excluded_attributes)
76
72
  end
77
73
 
78
74
  # @return [Hash] hash of attributes contributing to value equality
@@ -121,7 +117,7 @@ module Spree
121
117
  # @deprecated Do not use this
122
118
  def empty?
123
119
  Spree::Deprecation.warn("Address#empty? is deprecated.", caller)
124
- attributes.except('id', 'created_at', 'updated_at', 'country_id').all? { |_, v| v.nil? }
120
+ attributes.except('id', 'created_at', 'updated_at', 'country_id').all? { |_, value| value.nil? }
125
121
  end
126
122
 
127
123
  # This exists because the default Object#blank?, checks empty? if it is
@@ -56,6 +56,17 @@ module Spree
56
56
  extend DisplayMoney
57
57
  money_methods :amount
58
58
 
59
+ # Returns Adjustments of completed Orders.
60
+ #
61
+ # @param excluded_orders [Array<Spree::Order>] Orders to exclude from query
62
+ # @return [ActiveRecord::Relation] Scoped Adjustments
63
+ def self.in_completed_orders(excluded_orders: [])
64
+ joins(:order).
65
+ merge(Spree::Order.complete).
66
+ where.not(spree_orders: { id: excluded_orders }).
67
+ distinct
68
+ end
69
+
59
70
  def finalize!
60
71
  update!(finalized: true)
61
72
  end
@@ -12,7 +12,7 @@ module Spree
12
12
  # as object we always get line items, as calculable we have Coupon, ShippingMethod
13
13
  def compute(object)
14
14
  if object.is_a?(Array)
15
- base = object.map { |o| o.respond_to?(:amount) ? o.amount : BigDecimal(o.to_s) }.sum
15
+ base = object.map { |element| element.respond_to?(:amount) ? element.amount : BigDecimal(element.to_s) }.sum
16
16
  else
17
17
  base = object.respond_to?(:amount) ? object.amount : BigDecimal(object.to_s)
18
18
  end
@@ -18,9 +18,9 @@ module Spree
18
18
  def compute_from_quantity(quantity)
19
19
  sum = 0
20
20
  max = preferred_max_items.to_i
21
- quantity.times do |i|
21
+ quantity.times do |index|
22
22
  # check max value to avoid divide by 0 errors
23
- if (max == 0 && i == 0) || (max > 0) && (i % max == 0)
23
+ if (max == 0 && index == 0) || (max > 0) && (index % max == 0)
24
24
  sum += preferred_first_item.to_f
25
25
  else
26
26
  sum += preferred_additional_item.to_f
@@ -11,8 +11,8 @@ module Spree
11
11
  before_validation do
12
12
  # Convert tier values to decimals. Strings don't do us much good.
13
13
  if preferred_tiers.is_a?(Hash)
14
- self.preferred_tiers = preferred_tiers.map do |k, v|
15
- [cast_to_d(k.to_s), cast_to_d(v.to_s)]
14
+ self.preferred_tiers = preferred_tiers.map do |key, value|
15
+ [cast_to_d(key.to_s), cast_to_d(value.to_s)]
16
16
  end.to_h
17
17
  end
18
18
  end
@@ -20,8 +20,8 @@ module Spree
20
20
  validate :preferred_tiers_content
21
21
 
22
22
  def compute(object)
23
- _base, amount = preferred_tiers.sort.reverse.detect do |b, _|
24
- object.amount >= b
23
+ _base, amount = preferred_tiers.sort.reverse.detect do |value, _|
24
+ object.amount >= value
25
25
  end
26
26
 
27
27
  if preferred_currency.casecmp(object.currency).zero?
@@ -41,7 +41,7 @@ module Spree
41
41
 
42
42
  def preferred_tiers_content
43
43
  if preferred_tiers.is_a? Hash
44
- unless preferred_tiers.keys.all?{ |k| k.is_a?(Numeric) && k > 0 }
44
+ unless preferred_tiers.keys.all?{ |key| key.is_a?(Numeric) && key > 0 }
45
45
  errors.add(:base, :keys_should_be_positive_number)
46
46
  end
47
47
  else
@@ -11,8 +11,8 @@ module Spree
11
11
  before_validation do
12
12
  # Convert tier values to decimals. Strings don't do us much good.
13
13
  if preferred_tiers.is_a?(Hash)
14
- self.preferred_tiers = preferred_tiers.map do |k, v|
15
- [cast_to_d(k.to_s), cast_to_d(v.to_s)]
14
+ self.preferred_tiers = preferred_tiers.map do |key, value|
15
+ [cast_to_d(key.to_s), cast_to_d(value.to_s)]
16
16
  end.to_h
17
17
  end
18
18
  end
@@ -26,8 +26,8 @@ module Spree
26
26
  def compute(object)
27
27
  order = object.is_a?(Order) ? object : object.order
28
28
 
29
- _base, percent = preferred_tiers.sort.reverse.detect do |b, _|
30
- order.item_total >= b
29
+ _base, percent = preferred_tiers.sort.reverse.detect do |value, _|
30
+ order.item_total >= value
31
31
  end
32
32
 
33
33
  if preferred_currency.casecmp(order.currency).zero?
@@ -48,10 +48,10 @@ module Spree
48
48
 
49
49
  def preferred_tiers_content
50
50
  if preferred_tiers.is_a? Hash
51
- unless preferred_tiers.keys.all?{ |k| k.is_a?(Numeric) && k > 0 }
51
+ unless preferred_tiers.keys.all?{ |key| key.is_a?(Numeric) && key > 0 }
52
52
  errors.add(:base, :keys_should_be_positive_number)
53
53
  end
54
- unless preferred_tiers.values.all?{ |k| k.is_a?(Numeric) && k >= 0 && k <= 100 }
54
+ unless preferred_tiers.values.all?{ |key| key.is_a?(Numeric) && key >= 0 && key <= 100 }
55
55
  errors.add(:base, :values_should_be_percent)
56
56
  end
57
57
  else
@@ -3,7 +3,7 @@
3
3
  class Spree::Carton < Spree::Base
4
4
  belongs_to :address, class_name: 'Spree::Address', optional: true
5
5
  belongs_to :stock_location, class_name: 'Spree::StockLocation', inverse_of: :cartons, optional: true
6
- belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', inverse_of: :cartons, optional: true
6
+ belongs_to :shipping_method, -> { with_discarded }, class_name: 'Spree::ShippingMethod', inverse_of: :cartons, optional: true
7
7
 
8
8
  has_many :inventory_units, class_name: "Spree::InventoryUnit", inverse_of: :carton, dependent: :nullify
9
9
  has_many :orders, -> { distinct }, through: :inventory_units
@@ -47,13 +47,13 @@ module Spree
47
47
  }.freeze
48
48
 
49
49
  def default
50
- Spree::Deprecation.warn("CreditCard.default is deprecated. Please use user.wallet.default_wallet_payment_source instead.", caller)
50
+ Spree::Deprecation.warn("CreditCard#default is deprecated. Please use user.wallet.default_wallet_payment_source instead.", caller)
51
51
  return false if user.nil?
52
52
  user.wallet.default_wallet_payment_source.try!(:payment_source) == self
53
53
  end
54
54
 
55
55
  def default=(set_as_default)
56
- Spree::Deprecation.warn("CreditCard.default= is deprecated. Please use user.wallet.default_wallet_payment_source= instead.", caller)
56
+ Spree::Deprecation.warn("CreditCard#default= is deprecated. Please use user.wallet.default_wallet_payment_source= instead.", caller)
57
57
  if user.nil?
58
58
  raise "Cannot set 'default' on a credit card without a user"
59
59
  elsif set_as_default # setting this card as default
@@ -58,25 +58,7 @@ module Spree
58
58
 
59
59
  scope :shippable, -> { on_hand }
60
60
 
61
- # state machine (see http://github.com/pluginaweek/state_machine/tree/master for details)
62
- state_machine initial: :on_hand do
63
- event :fill_backorder do
64
- transition to: :on_hand, from: :backordered
65
- end
66
- after_transition on: :fill_backorder, do: :fulfill_order
67
-
68
- event :ship do
69
- transition to: :shipped, if: :allow_ship?
70
- end
71
-
72
- event :return do
73
- transition to: :returned, from: :shipped
74
- end
75
-
76
- event :cancel do
77
- transition to: :canceled, from: CANCELABLE_STATES.map(&:to_sym)
78
- end
79
- end
61
+ include ::Spree::Config.state_machines.inventory_unit
80
62
 
81
63
  # Updates the given inventory units to not be pending.
82
64
  #
@@ -72,7 +72,7 @@ module Spree
72
72
  # @return [BigDecimal] the amount of this item, taking into consideration
73
73
  # all non-tax adjustments.
74
74
  def total_before_tax
75
- amount + adjustments.select { |a| !a.tax? && a.eligible? }.sum(&:amount)
75
+ amount + adjustments.select { |value| !value.tax? && value.eligible? }.sum(&:amount)
76
76
  end
77
77
 
78
78
  # @return [BigDecimal] the amount of this line item before VAT tax
@@ -93,6 +93,7 @@ module Spree
93
93
 
94
94
  # Payments
95
95
  has_many :payments, dependent: :destroy, inverse_of: :order
96
+ has_many :valid_store_credit_payments, -> { store_credits.valid }, inverse_of: :order, class_name: 'Spree::Payment', foreign_key: :order_id
96
97
 
97
98
  # Returns
98
99
  has_many :return_authorizations, dependent: :destroy, inverse_of: :order
@@ -531,7 +532,7 @@ module Spree
531
532
  def create_proposed_shipments
532
533
  if completed?
533
534
  raise CannotRebuildShipments.new(I18n.t('spree.cannot_rebuild_shipments_order_completed'))
534
- elsif shipments.any? { |s| !s.pending? }
535
+ elsif shipments.any? { |shipment| !shipment.pending? }
535
536
  raise CannotRebuildShipments.new(I18n.t('spree.cannot_rebuild_shipments_shipments_not_pending'))
536
537
  else
537
538
  shipments.destroy_all
@@ -686,7 +687,7 @@ module Spree
686
687
 
687
688
  def total_applicable_store_credit
688
689
  if can_complete? || complete?
689
- payments.store_credits.valid.sum(:amount)
690
+ valid_store_credit_payments.to_a.sum(&:amount)
690
691
  else
691
692
  [total, (user.try(:available_store_credit_total, currency: currency) || 0.0)].min
692
693
  end
@@ -41,7 +41,7 @@ module Spree
41
41
  # On first definition, state_machines will not be defined
42
42
  state_machines.clear if respond_to?(:state_machines)
43
43
  state_machine :state, initial: :cart, use_transactions: false do
44
- klass.next_event_transitions.each { |t| transition(t.merge(on: :next)) }
44
+ klass.next_event_transitions.each { |state| transition(state.merge(on: :next)) }
45
45
 
46
46
  # Persist the state on the order
47
47
  after_transition do |order, transition|
@@ -46,9 +46,9 @@ module Spree
46
46
 
47
47
  payment.public_send(method)
48
48
  end
49
- rescue Core::GatewayError => e
49
+ rescue Core::GatewayError => error
50
50
  result = !!Spree::Config[:allow_checkout_on_gateway_error]
51
- errors.add(:base, e.message) && (return result)
51
+ errors.add(:base, error.message) && (return result)
52
52
  end
53
53
  end
54
54
  end
@@ -41,8 +41,8 @@ class Spree::OrderCapturing
41
41
  private
42
42
 
43
43
  def sorted_payments(order)
44
- order.payments.pending.sort_by do |p|
45
- [@sorted_payment_method_classes.index(p.payment_method.class), p.id]
44
+ order.payments.pending.sort_by do |payment|
45
+ [@sorted_payment_method_classes.index(payment.payment_method.class), payment.id]
46
46
  end
47
47
  end
48
48
  end
@@ -25,12 +25,12 @@ module Spree
25
25
  # @return [void]
26
26
  def apply(taxes)
27
27
  @order.line_items.each do |item|
28
- taxed_items = taxes.line_item_taxes.select { |i| i.item_id == item.id }
28
+ taxed_items = taxes.line_item_taxes.select { |element| element.item_id == item.id }
29
29
  update_adjustments(item, taxed_items)
30
30
  end
31
31
 
32
32
  @order.shipments.each do |item|
33
- taxed_items = taxes.shipment_taxes.select { |i| i.item_id == item.id }
33
+ taxed_items = taxes.shipment_taxes.select { |element| element.item_id == item.id }
34
34
  update_adjustments(item, taxed_items)
35
35
  end
36
36
  end
@@ -47,7 +47,7 @@ module Spree
47
47
  default_scope -> { order(:created_at) }
48
48
 
49
49
  scope :from_credit_card, -> { where(source_type: 'Spree::CreditCard') }
50
- scope :with_state, ->(s) { where(state: s.to_s) }
50
+ scope :with_state, ->(state) { where(state: state.to_s) }
51
51
  # "offset" is reserved by activerecord
52
52
  scope :offset_payment, -> { where("source_type = 'Spree::Payment' AND amount < 0 AND state = 'completed'") }
53
53
 
@@ -63,44 +63,7 @@ module Spree
63
63
  scope :store_credits, -> { where(source_type: Spree::StoreCredit.to_s) }
64
64
  scope :not_store_credits, -> { where(arel_table[:source_type].not_eq(Spree::StoreCredit.to_s).or(arel_table[:source_type].eq(nil))) }
65
65
 
66
- # order state machine (see http://github.com/pluginaweek/state_machine/tree/master for details)
67
- state_machine initial: :checkout do
68
- # With card payments, happens before purchase or authorization happens
69
- #
70
- # Setting it after creating a profile and authorizing a full amount will
71
- # prevent the payment from being authorized again once Order transitions
72
- # to complete
73
- event :started_processing do
74
- transition from: [:checkout, :pending, :completed, :processing], to: :processing
75
- end
76
- # When processing during checkout fails
77
- event :failure do
78
- transition from: [:pending, :processing], to: :failed
79
- end
80
- # With card payments this represents authorizing the payment
81
- event :pend do
82
- transition from: [:checkout, :processing], to: :pending
83
- end
84
- # With card payments this represents completing a purchase or capture transaction
85
- event :complete do
86
- transition from: [:processing, :pending, :checkout], to: :completed
87
- end
88
- event :void do
89
- transition from: [:pending, :processing, :completed, :checkout], to: :void
90
- end
91
- # when the card brand isnt supported
92
- event :invalidate do
93
- transition from: [:checkout], to: :invalid
94
- end
95
-
96
- after_transition do |payment, transition|
97
- payment.state_changes.create!(
98
- previous_state: transition.from,
99
- next_state: transition.to,
100
- name: 'payment'
101
- )
102
- end
103
- end
66
+ include ::Spree::Config.state_machines.payment
104
67
 
105
68
  # @return [String] this payment's response code
106
69
  def transaction_id
@@ -232,8 +195,8 @@ module Spree
232
195
  return if source.imported
233
196
 
234
197
  payment_method.create_profile(self)
235
- rescue ActiveMerchant::ConnectionError => e
236
- gateway_error e
198
+ rescue ActiveMerchant::ConnectionError => error
199
+ gateway_error error
237
200
  end
238
201
 
239
202
  def invalidate_old_payments
@@ -199,8 +199,8 @@ module Spree
199
199
 
200
200
  def protect_from_connection_error
201
201
  yield
202
- rescue ActiveMerchant::ConnectionError => e
203
- gateway_error(e)
202
+ rescue ActiveMerchant::ConnectionError => error
203
+ gateway_error(error)
204
204
  end
205
205
 
206
206
  def gateway_error(error)