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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8d215c9f3f4da7bf1e7776c8a313f7e75c8e2cc611ec5bfa7aab447c9153b70
|
4
|
+
data.tar.gz: 6c6775a3ae086b767a3a2277afa1bbb874001a9c0ea4de7c5c13939791b1619c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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?
|
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
|
+
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-
|
11
|
+
date: 2023-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|