solidus_core 2.0.3 → 2.1.0.beta1

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 (187) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +62 -3
  3. data/app/assets/javascripts/spree.js.coffee.erb +4 -1
  4. data/app/helpers/spree/base_helper.rb +7 -48
  5. data/app/models/spree/address.rb +5 -1
  6. data/app/models/spree/adjustment.rb +3 -3
  7. data/app/models/spree/app_configuration.rb +13 -0
  8. data/app/models/spree/calculator.rb +3 -2
  9. data/app/models/spree/calculator/default_tax.rb +6 -10
  10. data/app/models/spree/calculator/flat_percent_item_total.rb +0 -4
  11. data/app/models/spree/calculator/flat_rate.rb +0 -4
  12. data/app/models/spree/calculator/flexi_rate.rb +0 -4
  13. data/app/models/spree/calculator/free_shipping.rb +0 -3
  14. data/app/models/spree/calculator/percent_on_line_item.rb +0 -4
  15. data/app/models/spree/calculator/percent_per_item.rb +0 -4
  16. data/app/models/spree/calculator/price_sack.rb +0 -4
  17. data/app/models/spree/calculator/returns/default_refund_amount.rb +0 -3
  18. data/app/models/spree/calculator/shipping/flat_percent_item_total.rb +0 -4
  19. data/app/models/spree/calculator/shipping/flat_rate.rb +0 -4
  20. data/app/models/spree/calculator/shipping/flexi_rate.rb +0 -4
  21. data/app/models/spree/calculator/shipping/per_item.rb +0 -4
  22. data/app/models/spree/calculator/shipping/price_sack.rb +0 -4
  23. data/app/models/spree/calculator/tiered_flat_rate.rb +0 -4
  24. data/app/models/spree/calculator/tiered_percent.rb +0 -4
  25. data/app/models/spree/credit_card.rb +27 -14
  26. data/app/models/spree/gateway.rb +4 -0
  27. data/app/models/spree/inventory_unit.rb +2 -0
  28. data/app/models/spree/line_item.rb +31 -26
  29. data/app/models/spree/option_type.rb +0 -3
  30. data/app/models/spree/order.rb +28 -31
  31. data/app/models/spree/order/checkout.rb +0 -2
  32. data/app/models/spree/order_contents.rb +0 -45
  33. data/app/models/spree/order_merger.rb +6 -6
  34. data/app/models/spree/order_update_attributes.rb +0 -2
  35. data/app/models/spree/order_updater.rb +91 -13
  36. data/app/models/spree/payment.rb +9 -2
  37. data/app/models/spree/payment/processing.rb +15 -9
  38. data/app/models/spree/payment_method.rb +48 -5
  39. data/app/models/spree/price.rb +7 -9
  40. data/app/models/spree/product.rb +1 -25
  41. data/app/models/spree/promotion.rb +22 -14
  42. data/app/models/spree/promotion/actions/create_adjustment.rb +12 -1
  43. data/app/models/spree/promotion/actions/create_item_adjustments.rb +15 -1
  44. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +5 -3
  45. data/app/models/spree/promotion/actions/free_shipping.rb +14 -0
  46. data/app/models/spree/promotion/rules/taxon.rb +7 -2
  47. data/app/models/spree/promotion/rules/user_role.rb +43 -0
  48. data/app/models/spree/promotion_action.rb +19 -2
  49. data/app/models/spree/promotion_handler/coupon.rb +1 -4
  50. data/app/models/spree/promotion_handler/free_shipping.rb +22 -17
  51. data/app/models/spree/promotion_rule_role.rb +6 -0
  52. data/app/models/spree/property.rb +0 -3
  53. data/app/models/spree/return_authorization.rb +2 -0
  54. data/app/models/spree/shipment.rb +5 -21
  55. data/app/models/spree/shipping_method.rb +23 -2
  56. data/app/models/spree/shipping_rate.rb +3 -0
  57. data/app/models/spree/stock/estimator.rb +1 -1
  58. data/app/models/spree/stock_location.rb +3 -0
  59. data/app/models/spree/store.rb +7 -0
  60. data/app/models/spree/tax/item_adjuster.rb +27 -12
  61. data/app/models/spree/tax/order_adjuster.rb +2 -5
  62. data/app/models/spree/tax/tax_helpers.rb +4 -8
  63. data/app/models/spree/tax_rate.rb +1 -15
  64. data/app/models/spree/taxon.rb +0 -3
  65. data/app/models/spree/transfer_item.rb +1 -1
  66. data/app/models/spree/user_class_handle.rb +14 -9
  67. data/app/models/spree/variant/pricing_options.rb +1 -1
  68. data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +1 -1
  69. data/app/models/spree/zone.rb +20 -13
  70. data/config/locales/en.yml +144 -62
  71. data/db/migrate/20120831092320_spree_one_two.rb +0 -7
  72. data/db/migrate/20150723224133_remove_unnecessary_indexes.rb +0 -2
  73. data/db/migrate/20160924135758_remove_is_default_from_prices.rb +5 -0
  74. data/db/migrate/20161009141333_remove_currency_from_line_items.rb +5 -0
  75. data/db/migrate/20161014221052_add_available_to_columns_and_remove_display_on_from_payment_methods.rb +28 -0
  76. data/db/migrate/20161123154034_add_available_to_users_and_remove_display_on_from_shipping_methods.rb +20 -0
  77. data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +4 -0
  78. data/lib/generators/spree/dummy/dummy_generator.rb +0 -2
  79. data/lib/spree/core.rb +0 -5
  80. data/lib/spree/core/controller_helpers/pricing.rb +2 -1
  81. data/lib/spree/core/engine.rb +14 -0
  82. data/lib/spree/core/version.rb +1 -1
  83. data/lib/spree/deprecation.rb +1 -1
  84. data/lib/spree/localized_number.rb +3 -2
  85. data/lib/spree/permission_sets/configuration_display.rb +0 -1
  86. data/lib/spree/permission_sets/configuration_management.rb +0 -1
  87. data/lib/spree/permission_sets/product_display.rb +0 -1
  88. data/lib/spree/permission_sets/product_management.rb +0 -1
  89. data/lib/spree/permission_sets/user_management.rb +2 -4
  90. data/lib/spree/permitted_attributes.rb +3 -2
  91. data/lib/spree/testing_support/capybara_ext.rb +0 -12
  92. data/lib/spree/testing_support/factories/address_factory.rb +1 -1
  93. data/lib/spree/testing_support/factories/line_item_factory.rb +0 -1
  94. data/lib/spree/testing_support/factories/payment_factory.rb +4 -0
  95. data/lib/spree/testing_support/factories/payment_method_factory.rb +8 -1
  96. data/lib/spree/testing_support/factories/user_factory.rb +2 -2
  97. data/solidus_core.gemspec +4 -3
  98. data/spec/helpers/base_helper_spec.rb +0 -40
  99. data/spec/lib/spree/core/controller_helpers/pricing_spec.rb +16 -0
  100. data/spec/lib/spree/core/importer/order_spec.rb +27 -18
  101. data/spec/lib/spree/core/price_migrator_spec.rb +3 -1
  102. data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +16 -0
  103. data/spec/lib/spree/core/unreturned_item_charger_spec.rb +0 -2
  104. data/spec/lib/tasks/exchanges_spec.rb +4 -2
  105. data/spec/lib/tasks/migrations/create_vat_prices_spec.rb +5 -3
  106. data/spec/models/spree/adjustment_spec.rb +136 -0
  107. data/spec/models/spree/calculator/default_tax_spec.rb +13 -7
  108. data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +3 -0
  109. data/spec/models/spree/calculator/flat_rate_spec.rb +3 -0
  110. data/spec/models/spree/calculator/flexi_rate_spec.rb +3 -0
  111. data/spec/models/spree/calculator/free_shipping_spec.rb +6 -0
  112. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +9 -4
  113. data/spec/models/spree/calculator/percent_per_item_spec.rb +10 -0
  114. data/spec/models/spree/calculator/price_sack_spec.rb +3 -0
  115. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +3 -0
  116. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +3 -0
  117. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +3 -0
  118. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +3 -0
  119. data/spec/models/spree/calculator/shipping/per_item_spec.rb +3 -0
  120. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +4 -1
  121. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +3 -0
  122. data/spec/models/spree/calculator/tiered_percent_spec.rb +3 -0
  123. data/spec/models/spree/credit_card_spec.rb +27 -1
  124. data/spec/models/spree/line_item_spec.rb +58 -65
  125. data/spec/models/spree/order/checkout_spec.rb +2 -1
  126. data/spec/models/spree/order/payment_spec.rb +9 -10
  127. data/spec/models/spree/order/tax_spec.rb +22 -7
  128. data/spec/models/spree/order/updating_spec.rb +1 -3
  129. data/spec/models/spree/order_cancellations_spec.rb +6 -4
  130. data/spec/models/spree/order_contents_spec.rb +34 -50
  131. data/spec/models/spree/order_inventory_spec.rb +3 -5
  132. data/spec/models/spree/order_merger_spec.rb +20 -0
  133. data/spec/models/spree/order_spec.rb +28 -64
  134. data/spec/models/spree/order_update_attributes_spec.rb +1 -5
  135. data/spec/models/spree/order_updater_spec.rb +251 -0
  136. data/spec/models/spree/payment_method_spec.rb +178 -28
  137. data/spec/models/spree/payment_spec.rb +35 -19
  138. data/spec/models/spree/permission_sets/configuration_display.rb +0 -4
  139. data/spec/models/spree/permission_sets/configuration_management_spec.rb +0 -2
  140. data/spec/models/spree/permission_sets/product_display_spec.rb +0 -4
  141. data/spec/models/spree/permission_sets/product_management_spec.rb +0 -2
  142. data/spec/models/spree/permission_sets/user_management_spec.rb +9 -2
  143. data/spec/models/spree/price_spec.rb +16 -1
  144. data/spec/models/spree/product_spec.rb +0 -75
  145. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +20 -0
  146. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +39 -15
  147. data/spec/models/spree/promotion/actions/create_quantity_adjustments_spec.rb +203 -22
  148. data/spec/models/spree/promotion/actions/free_shipping_spec.rb +22 -3
  149. data/spec/models/spree/promotion/rules/taxon_spec.rb +26 -0
  150. data/spec/models/spree/promotion/rules/user_role_spec.rb +86 -0
  151. data/spec/models/spree/promotion_action_spec.rb +38 -0
  152. data/spec/models/spree/promotion_handler/coupon_spec.rb +36 -33
  153. data/spec/models/spree/promotion_handler/free_shipping_spec.rb +21 -22
  154. data/spec/models/spree/promotion_spec.rb +46 -6
  155. data/spec/models/spree/reimbursement_spec.rb +1 -1
  156. data/spec/models/spree/reimbursement_tax_calculator_spec.rb +2 -2
  157. data/spec/models/spree/shipment_spec.rb +68 -50
  158. data/spec/models/spree/shipping_method_spec.rb +41 -0
  159. data/spec/models/spree/shipping_rate_spec.rb +9 -3
  160. data/spec/models/spree/stock/estimator_spec.rb +4 -2
  161. data/spec/models/spree/store_credit_spec.rb +3 -3
  162. data/spec/models/spree/tax/item_adjuster_spec.rb +31 -21
  163. data/spec/models/spree/tax/order_adjuster_spec.rb +6 -10
  164. data/spec/models/spree/tax/taxation_integration_spec.rb +19 -0
  165. data/spec/models/spree/tax_rate_spec.rb +5 -26
  166. data/spec/models/spree/transfer_item_spec.rb +11 -0
  167. data/spec/models/spree/variant/pricing_options_spec.rb +7 -17
  168. data/spec/models/spree/variant_spec.rb +2 -4
  169. data/spec/models/spree/zone_spec.rb +60 -20
  170. data/spec/shared_examples/calculator_shared_examples.rb +8 -0
  171. metadata +19 -24
  172. data/app/models/spree/item_adjustments.rb +0 -89
  173. data/app/models/spree/option_type_prototype.rb +0 -6
  174. data/app/models/spree/property_prototype.rb +0 -6
  175. data/app/models/spree/prototype.rb +0 -14
  176. data/app/models/spree/prototype_taxon.rb +0 -6
  177. data/app/models/spree/tracker.rb +0 -8
  178. data/db/migrate/20150128032538_remove_environment_from_tracker.rb +0 -6
  179. data/lib/generators/spree/dummy/templates/initializers/custom_user.rb +0 -1
  180. data/lib/spree/core/delegate_belongs_to.rb +0 -94
  181. data/lib/spree/testing_support/factories/prototype_factory.rb +0 -8
  182. data/lib/spree/testing_support/factories/tracker_factory.rb +0 -6
  183. data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -24
  184. data/spec/lib/spree/core/testing_support/factories/prototype_factory_spec.rb +0 -12
  185. data/spec/lib/spree/core/testing_support/factories/tracker_factory_spec.rb +0 -12
  186. data/spec/models/spree/item_adjustments_spec.rb +0 -306
  187. data/spec/models/spree/tracker_spec.rb +0 -21
@@ -27,7 +27,7 @@ module Spree
27
27
  order: order,
28
28
  source: self,
29
29
  promotion_code: options[:promotion_code],
30
- label: "#{Spree.t(:promotion)} (#{promotion.name})"
30
+ label: Spree.t('adjustment_labels.order', promotion: Spree::Promotion.model_name.human, promotion_name: promotion.name)
31
31
  )
32
32
  true
33
33
  end
@@ -39,6 +39,17 @@ module Spree
39
39
  [(calculable.item_total + calculable.ship_total), amount].min * -1
40
40
  end
41
41
 
42
+ # Removes any adjustments generated by this action from the order.
43
+ # @param order [Spree::Order] the order to remove the action from.
44
+ # @return [void]
45
+ def remove_from(order)
46
+ order.adjustments.each do |adjustment|
47
+ if adjustment.source == self
48
+ order.adjustments.destroy(adjustment)
49
+ end
50
+ end
51
+ end
52
+
42
53
  private
43
54
 
44
55
  # Tells us if there if the specified promotion is already associated with the line item
@@ -35,6 +35,20 @@ module Spree
35
35
  [adjustable.amount, promotion_amount].min * -1
36
36
  end
37
37
 
38
+ # Removes any adjustments generated by this action from the order's
39
+ # line items.
40
+ # @param order [Spree::Order] the order to remove the action from.
41
+ # @return [void]
42
+ def remove_from(order)
43
+ order.line_items.each do |line_item|
44
+ line_item.adjustments.each do |adjustment|
45
+ if adjustment.source == self
46
+ line_item.adjustments.destroy(adjustment)
47
+ end
48
+ end
49
+ end
50
+ end
51
+
38
52
  private
39
53
 
40
54
  def create_adjustment(adjustable, order, promotion_code)
@@ -45,7 +59,7 @@ module Spree
45
59
  amount: amount,
46
60
  order: order,
47
61
  promotion_code: promotion_code,
48
- label: "#{Spree.t(:promotion)} (#{promotion.name})"
62
+ label: Spree.t('adjustment_labels.line_item', promotion: Spree::Promotion.model_name.human, promotion_name: promotion.name)
49
63
  )
50
64
  true
51
65
  end
@@ -1,7 +1,5 @@
1
1
  module Spree::Promotion::Actions
2
2
  class CreateQuantityAdjustments < CreateItemAdjustments
3
- include Spree::CalculatedAdjustments
4
-
5
3
  preference :group_size, :integer, default: 1
6
4
 
7
5
  has_many :line_item_actions, foreign_key: :action_id, dependent: :destroy
@@ -80,7 +78,7 @@ module Spree::Promotion::Actions
80
78
  private
81
79
 
82
80
  def actionable_line_items(order)
83
- order.line_items.reload.select do |item|
81
+ order.line_items.select do |item|
84
82
  promotion.line_item_actionable? order, item
85
83
  end
86
84
  end
@@ -121,6 +119,10 @@ module Spree::Promotion::Actions
121
119
  @line_item.price
122
120
  end
123
121
 
122
+ def order
123
+ @line_item.order
124
+ end
125
+
124
126
  def currency
125
127
  @line_item.currency
126
128
  end
@@ -30,6 +30,20 @@ module Spree
30
30
  shipment.cost * -1
31
31
  end
32
32
 
33
+ # Removes any adjustments generated by this action from the order's
34
+ # shipments.
35
+ # @param order [Spree::Order] the order to remove the action from.
36
+ # @return [void]
37
+ def remove_from(order)
38
+ order.shipments.each do |shipment|
39
+ shipment.adjustments.each do |adjustment|
40
+ if adjustment.source == self
41
+ shipment.adjustments.destroy(adjustment)
42
+ end
43
+ end
44
+ end
45
+ end
46
+
33
47
  private
34
48
 
35
49
  def promotion_credit_exists?(shipment)
@@ -6,12 +6,11 @@ module Spree
6
6
  dependent: :destroy
7
7
  has_many :taxons, through: :promotion_rule_taxons, class_name: 'Spree::Taxon'
8
8
 
9
- MATCH_POLICIES = %w(any all)
9
+ MATCH_POLICIES = %w(any all none)
10
10
 
11
11
  validates_inclusion_of :preferred_match_policy, in: MATCH_POLICIES
12
12
 
13
13
  preference :match_policy, :string, default: MATCH_POLICIES.first
14
-
15
14
  def applicable?(promotable)
16
15
  promotable.is_a?(Spree::Order)
17
16
  end
@@ -28,6 +27,10 @@ module Spree
28
27
  unless taxons.any?{ |taxon| order_taxons.include? taxon }
29
28
  eligibility_errors.add(:base, eligibility_error_message(:no_matching_taxons))
30
29
  end
30
+ when 'none'
31
+ unless taxons.none?{ |taxon| order_taxons.include? taxon }
32
+ eligibility_errors.add(:base, eligibility_error_message(:has_excluded_taxon))
33
+ end
31
34
  else
32
35
  # Change this to an exception in a future version of Solidus
33
36
  warn_invalid_match_policy(assume: 'any')
@@ -43,6 +46,8 @@ module Spree
43
46
  case preferred_match_policy
44
47
  when 'any', 'all'
45
48
  taxon_product_ids.include?(line_item.variant.product_id)
49
+ when 'none'
50
+ taxon_product_ids.exclude? line_item.variant.product_id
46
51
  else
47
52
  # Change this to an exception in a future version of Solidus
48
53
  warn_invalid_match_policy(assume: 'any')
@@ -0,0 +1,43 @@
1
+ module Spree
2
+ class Promotion
3
+ module Rules
4
+ class UserRole < PromotionRule
5
+ preference :role_ids, :array, default: []
6
+
7
+ MATCH_POLICIES = %w(any all)
8
+ preference :match_policy, default: MATCH_POLICIES.first
9
+
10
+ def applicable?(promotable)
11
+ promotable.is_a?(Spree::Order)
12
+ end
13
+
14
+ def eligible?(order, _options = {})
15
+ return false unless order.user
16
+ if all_match_policy?
17
+ match_all_roles?(order)
18
+ else
19
+ match_any_roles?(order)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def all_match_policy?
26
+ preferred_match_policy == 'all' && preferred_role_ids.present?
27
+ end
28
+
29
+ def user_roles(order)
30
+ order.user.spree_roles.where(id: preferred_role_ids)
31
+ end
32
+
33
+ def match_all_roles?(order)
34
+ user_roles(order).count == preferred_role_ids.count
35
+ end
36
+
37
+ def match_any_roles?(order)
38
+ user_roles(order).exists?
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -6,9 +6,9 @@ module Spree
6
6
  class PromotionAction < Spree::Base
7
7
  acts_as_paranoid
8
8
 
9
- belongs_to :promotion, class_name: 'Spree::Promotion'
9
+ belongs_to :promotion, class_name: 'Spree::Promotion', inverse_of: :promotion_actions
10
10
 
11
- scope :of_type, ->(t) { where(type: t) }
11
+ scope :of_type, ->(t) { where(type: t.to_s) }
12
12
 
13
13
  # Updates the state of the order or performs some other action depending on
14
14
  # the subclass options will contain the payload from the event that
@@ -19,5 +19,22 @@ module Spree
19
19
  def perform(_options = {})
20
20
  raise 'perform should be implemented in a sub-class of PromotionAction'
21
21
  end
22
+
23
+ # Removes the action from an order
24
+ #
25
+ # @note This method should be overriden in subclassses.
26
+ #
27
+ # @param order [Spree::Order] the order to remove the action from
28
+ # @return [void]
29
+ def remove_from(order)
30
+ Spree::Deprecation.warn("#{self.class.name.inspect} does not define #remove_from. The default behavior may be incorrect and will be removed in a future version of Solidus.", caller)
31
+ [order, *order.line_items, *order.shipments].each do |item|
32
+ item.adjustments.each do |adjustment|
33
+ if adjustment.source == self
34
+ item.adjustments.destroy(adjustment)
35
+ end
36
+ end
37
+ end
38
+ end
22
39
  end
23
40
  end
@@ -94,10 +94,7 @@ module Spree
94
94
  discount ||= order.shipment_adjustments.promotion.detect(&detector)
95
95
  discount ||= order.adjustments.promotion.detect(&detector)
96
96
 
97
- # Check for applied line items.
98
- created_line_items = promotion.actions.detect { |a| a.type == 'Spree::Promotion::Actions::CreateLineItems' }
99
-
100
- if (discount && discount.eligible) || created_line_items
97
+ if discount && discount.eligible
101
98
  order.update_totals
102
99
  order.persist_totals
103
100
  set_success_code :coupon_code_applied
@@ -2,19 +2,21 @@ module Spree
2
2
  module PromotionHandler
3
3
  # Used for activating promotions with shipping rules
4
4
  class FreeShipping
5
- attr_reader :order, :order_promo_ids
5
+ attr_reader :order
6
6
  attr_accessor :error, :success
7
7
 
8
8
  def initialize(order)
9
9
  @order = order
10
- @order_promo_ids = order.promotions.pluck(:id)
11
10
  end
12
11
 
13
12
  def activate
14
13
  promotions.each do |promotion|
15
- next if promotion.codes.any? && !order_promo_ids.include?(promotion.id)
16
-
17
- if promotion.eligible?(order)
14
+ if order_promotion = existing_order_promotion(promotion)
15
+ promotion.activate(
16
+ order: order,
17
+ promotion_code: order_promotion.promotion_code,
18
+ )
19
+ elsif promotion.apply_automatically?
18
20
  promotion.activate(order: order)
19
21
  end
20
22
  end
@@ -23,20 +25,23 @@ module Spree
23
25
  private
24
26
 
25
27
  def promotions
26
- promo_table = Promotion.arel_table
27
- code_table = PromotionCode.arel_table
28
+ Spree::Promotion.
29
+ active.
30
+ joins(:promotion_actions).
31
+ merge(
32
+ Spree::PromotionAction.of_type(
33
+ Spree::Promotion::Actions::FreeShipping
34
+ )
35
+ ).
36
+ distinct
37
+ end
28
38
 
29
- promotion_code_join = promo_table.join(code_table, Arel::Nodes::OuterJoin).on(
30
- promo_table[:id].eq(code_table[:promotion_id])
31
- ).join_sources
39
+ def existing_order_promotion(promotion)
40
+ @lookup ||= order.order_promotions.map do |order_promotion|
41
+ [order_promotion.promotion_id, order_promotion]
42
+ end.to_h
32
43
 
33
- Spree::Promotion.active.
34
- joins(promotion_code_join).
35
- where({
36
- id: Spree::Promotion::Actions::FreeShipping.pluck(:promotion_id), # This would probably be more efficient by joining instead
37
- spree_promotion_codes: { id: nil },
38
- path: nil
39
- })
44
+ @lookup[promotion.id]
40
45
  end
41
46
  end
42
47
  end
@@ -0,0 +1,6 @@
1
+ module Spree
2
+ class PromotionRuleRole < ActiveRecord::Base
3
+ belongs_to :promotion_rule, class_name: 'Spree::PromotionRule'
4
+ belongs_to :role, class_name: 'Spree::Role'
5
+ end
6
+ end
@@ -1,8 +1,5 @@
1
1
  module Spree
2
2
  class Property < Spree::Base
3
- has_many :property_prototypes
4
- has_many :prototypes, through: :property_prototypes
5
-
6
3
  has_many :product_properties, dependent: :delete_all, inverse_of: :property
7
4
  has_many :products, through: :product_properties
8
5
 
@@ -1,4 +1,6 @@
1
1
  module Spree
2
+ # Models the return of Inventory Units to a Stock Location for an Order.
3
+ #
2
4
  class ReturnAuthorization < Spree::Base
3
5
  belongs_to :order, class_name: 'Spree::Order', inverse_of: :return_authorizations
4
6
 
@@ -1,11 +1,13 @@
1
1
  module Spree
2
+ # An order's planned shipments including tracking and cost.
3
+ #
2
4
  class Shipment < Spree::Base
3
5
  belongs_to :order, class_name: 'Spree::Order', touch: true, inverse_of: :shipments
4
6
  belongs_to :stock_location, class_name: 'Spree::StockLocation'
5
7
 
6
8
  has_many :adjustments, as: :adjustable, inverse_of: :adjustable, dependent: :delete_all
7
9
  has_many :inventory_units, dependent: :destroy, inverse_of: :shipment
8
- has_many :shipping_rates, -> { order(:cost) }, dependent: :delete_all
10
+ has_many :shipping_rates, -> { order(:cost) }, dependent: :destroy
9
11
  has_many :shipping_methods, through: :shipping_rates
10
12
  has_many :state_changes, as: :stateful
11
13
  has_many :cartons, -> { uniq }, through: :inventory_units
@@ -280,11 +282,9 @@ module Spree
280
282
  def update_amounts
281
283
  if selected_shipping_rate
282
284
  self.cost = selected_shipping_rate.cost
283
- self.adjustment_total = adjustments.additional.map(&:update!).compact.sum
284
285
  if changed?
285
286
  update_columns(
286
287
  cost: cost,
287
- adjustment_total: adjustment_total,
288
288
  updated_at: Time.current
289
289
  )
290
290
  end
@@ -296,25 +296,9 @@ module Spree
296
296
  if update_attributes params
297
297
  if params.key? :selected_shipping_rate_id
298
298
  # Changing the selected Shipping Rate won't update the cost (for now)
299
- # so we persist the Shipment#cost before calculating order shipment
300
- # total and updating payment state (given a change in shipment cost
301
- # might change the Order#payment_state)
299
+ # so we persist the Shipment#cost before running `order.update!`
302
300
  update_amounts
303
-
304
- order.updater.update_shipment_total
305
- order.updater.update_payment_state
306
-
307
- # Update shipment state only after order total is updated because it
308
- # (via Order#paid?) affects the shipment state (YAY)
309
- update_columns(
310
- state: determine_state(order),
311
- updated_at: Time.current
312
- )
313
-
314
- # And then it's time to update shipment states and finally persist
315
- # order changes
316
- order.updater.update_shipment_state
317
- order.updater.persist_totals
301
+ order.update!
318
302
  end
319
303
 
320
304
  true
@@ -1,8 +1,14 @@
1
1
  module Spree
2
+ # Represents a means of having a shipment delivered, such as FedEx or UPS.
3
+ #
2
4
  class ShippingMethod < Spree::Base
3
5
  acts_as_paranoid
4
6
  include Spree::CalculatedAdjustments
5
- DISPLAY = [:both, :front_end, :back_end]
7
+ DISPLAY = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(
8
+ [:both, :front_end, :back_end],
9
+ "Spree::ShippingMethod::DISPLAY is deprecated",
10
+ Spree::Deprecation
11
+ )
6
12
 
7
13
  has_many :shipping_method_categories, dependent: :destroy
8
14
  has_many :shipping_categories, through: :shipping_method_categories
@@ -77,10 +83,25 @@ module Spree
77
83
  tracking_url.gsub(/:tracking/, ERB::Util.url_encode(tracking)) # :url_encode exists in 1.8.7 through 2.1.0
78
84
  end
79
85
 
86
+ def display_on
87
+ if available_to_users?
88
+ "both"
89
+ else
90
+ "back_end"
91
+ end
92
+ end
93
+ deprecate display_on: :available_to_users?, deprecator: Spree::Deprecation
94
+
95
+ def display_on=(value)
96
+ self.available_to_users = (value != "back_end")
97
+ end
98
+ deprecate 'display_on=': :available_to_users=, deprecator: Spree::Deprecation
99
+
80
100
  # Some shipping methods are only meant to be set via backend
81
101
  def frontend?
82
- display_on != "back_end"
102
+ available_to_users?
83
103
  end
104
+ deprecate frontend?: :available_to_users?, deprecator: Spree::Deprecation
84
105
 
85
106
  private
86
107
 
@@ -1,4 +1,7 @@
1
1
  module Spree
2
+ # Records the costs of different shipping methods for a shipment and which
3
+ # method has been selected to deliver the shipment.
4
+ #
2
5
  class ShippingRate < Spree::Base
3
6
  belongs_to :shipment, class_name: 'Spree::Shipment'
4
7
  belongs_to :shipping_method, -> { with_deleted }, class_name: 'Spree::ShippingMethod', inverse_of: :shipping_rates
@@ -16,7 +16,7 @@ module Spree
16
16
  raise OrderRequired if package.shipment.order.nil?
17
17
 
18
18
  rates = calculate_shipping_rates(package)
19
- rates.select! { |rate| rate.shipping_method.frontend? } if frontend_only
19
+ rates.select! { |rate| rate.shipping_method.available_to_users? } if frontend_only
20
20
  choose_default_shipping_rate(rates)
21
21
  Spree::Config.shipping_rate_sorter_class.new(rates).sort
22
22
  end
@@ -1,4 +1,7 @@
1
1
  module Spree
2
+ # Records the name and addresses from which stock items are fulfilled in
3
+ # cartons.
4
+ #
2
5
  class StockLocation < Spree::Base
3
6
  class InvalidMovementError < StandardError; end
4
7