effective_resources 2.17.4 → 2.17.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb41fb3f61a31219410a41bd018e2ae57558f876e40074d79d598ebeacf84330
4
- data.tar.gz: 6f1538d2b6ffc782fc37f4283bb41b31608fab3505e88a7c0a5a406c09a15d2a
3
+ metadata.gz: c8d215c9f3f4da7bf1e7776c8a313f7e75c8e2cc611ec5bfa7aab447c9153b70
4
+ data.tar.gz: 6c6775a3ae086b767a3a2277afa1bbb874001a9c0ea4de7c5c13939791b1619c
5
5
  SHA512:
6
- metadata.gz: 53783dfd73fb23feef274bf4f4a646cb007adb648b23bc4c969ff3a15e12e5feffb0cbf03a3651d105279122a2f620ca92aad10ad41ac5d0727c860e43b32abf
7
- data.tar.gz: 779f6c3e0e9d23ffea318b511e0570310cc11fdb2e8c5cfce81160e3eb7f46b8ef8600e4a9dda15e29b0165e534bbab6a1d61bc90616592db6cc67a7333e6044
6
+ metadata.gz: ebb84318ad63c0cd8cdedf95bab1f72784a10d9e0cd80cdf3dd667c9fbc51bbdb7325686a614c963940ca92bd1bc39f2fa498e1c4733833d8c3b63ed663fc9a0
7
+ data.tar.gz: b58c8776531032a60c827a5e78224ebaf23778de79dc0bf2fc86c94dbc949da231606dfc71628ea5abd11083594ba99dfa6ee1f06de7e4dd3ca9096cc20bfcbb
@@ -77,6 +77,9 @@ module ActsAsPurchasableWizard
77
77
  # This will update all order items to match the prices from their purchasable
78
78
  order.try(:update_purchasable_attributes)
79
79
 
80
+ # Handle effective_memberships coupon fees price reduction
81
+ reduce_order_item_coupon_fee_price(order)
82
+
80
83
  # Hook to extend for coupon fees
81
84
  order = before_submit_order_save(order)
82
85
  raise('before_submit_order_save must return an Effective::Order') unless order.kind_of?(Effective::Order)
@@ -91,6 +94,32 @@ module ActsAsPurchasableWizard
91
94
  order
92
95
  end
93
96
 
97
+ # This is used by effective_memberships and effective_events
98
+ # Which both add coupon_fees to their submit_fees
99
+ def reduce_order_item_coupon_fee_price(order)
100
+ # This only applies to orders with coupon fees
101
+ order_items = order.order_items.select { |oi| oi.purchasable.try(:coupon_fee?) }
102
+ return order unless order_items.present?
103
+ raise('multiple coupon fees not supported') if order_items.length > 1
104
+
105
+ # Get the coupon fee
106
+ order_item = order_items.first
107
+ coupon_fee = order_item.purchasable
108
+ raise('expected order item for coupon fee to be a negative price') unless coupon_fee.price.to_i < 0
109
+
110
+ # Calculate price
111
+ subtotal = order.order_items.reject { |oi| oi.purchasable.try(:coupon_fee?) }.sum(&:subtotal)
112
+
113
+ price = 0 if subtotal <= 0
114
+ price ||= [coupon_fee.price, (0 - subtotal)].max
115
+
116
+ # Assign the price to this order item. Underlying fee price stays the same.
117
+ order_item.assign_attributes(price: price)
118
+
119
+ # Return the order
120
+ order
121
+ end
122
+
94
123
  # Should be indempotent.
95
124
  def build_submit_fees_and_order
96
125
  return false if was_submitted?
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.17.4'.freeze
2
+ VERSION = '2.17.5'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.17.4
4
+ version: 2.17.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-23 00:00:00.000000000 Z
11
+ date: 2023-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails