effective_orders 5.1.5 → 5.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/effective/concerns/purchase.rb +1 -1
- data/app/models/effective/order.rb +39 -13
- data/lib/effective_orders/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '063584ca12ed4cb46363a9c7c99f729889bf536eb0a1afb6021e04f07349532b'
|
4
|
+
data.tar.gz: 313908b8ff6797d96c7139a3598b6790a3fda9fb358e69a240e0ccb5afcd8569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71a032b3e32b4387801d3630e58df4ee9b91f890a0d87e42c1c4eacb5cb49875e7494316089c01d9d9bdf8a10e246d09caa8d4d2bb400897221661957fc63034
|
7
|
+
data.tar.gz: 7149e03e2c5f5f830a53f235eafd6c712213d5dd6eb4958554d752e7f8e51d124188cebe432284a8ddde462e2fd5ff7ec21999a00465220fbc9d4cb5f5a84a08
|
@@ -11,7 +11,7 @@ module Effective
|
|
11
11
|
Effective::Cart.where(user: @order.user).destroy_all
|
12
12
|
|
13
13
|
if flash[:success].blank?
|
14
|
-
if email &&
|
14
|
+
if email && @order.send_order_receipt_to_buyer?
|
15
15
|
flash[:success] = "Payment successful! A receipt has been sent to #{@order.emails_send_to}"
|
16
16
|
else
|
17
17
|
flash[:success] = "Payment successful! An email receipt has not been sent."
|
@@ -69,6 +69,7 @@ module Effective
|
|
69
69
|
before_validation { assign_billing_name }
|
70
70
|
before_validation { assign_email }
|
71
71
|
before_validation { assign_last_address }
|
72
|
+
before_validation { assign_user_address }
|
72
73
|
|
73
74
|
before_validation(if: -> { confirmed_checkout }) do
|
74
75
|
self.state = EffectiveOrders::CONFIRMED if pending?
|
@@ -156,30 +157,34 @@ module Effective
|
|
156
157
|
def initialize(atts = nil, &block)
|
157
158
|
super(state: EffectiveOrders::PENDING) # Initialize with state: PENDING
|
158
159
|
|
159
|
-
return unless atts.present?
|
160
|
+
return self unless atts.present?
|
160
161
|
|
161
162
|
if atts.kind_of?(Hash)
|
162
|
-
items = Array(atts
|
163
|
+
items = Array(atts[:item]) + Array(atts[:items])
|
163
164
|
|
164
|
-
self.user = atts
|
165
|
+
self.user = atts[:user] || (items.first.user if items.first.respond_to?(:user))
|
165
166
|
|
166
|
-
if (address = atts
|
167
|
+
if (address = atts[:billing_address]).present?
|
167
168
|
self.billing_address = address
|
168
169
|
self.billing_address.full_name ||= user.to_s.presence
|
169
170
|
end
|
170
171
|
|
171
|
-
if (address = atts
|
172
|
+
if (address = atts[:shipping_address]).present?
|
172
173
|
self.shipping_address = address
|
173
174
|
self.shipping_address.full_name ||= user.to_s.presence
|
174
175
|
end
|
175
176
|
|
176
|
-
atts.
|
177
|
+
atts.except(:item, :items, :user, :billing_address, :shipping_address).each do |key, value|
|
178
|
+
self.send("#{key}=", value)
|
179
|
+
end
|
177
180
|
|
178
181
|
add(items) if items.present?
|
179
182
|
else # Attributes are not a Hash
|
180
183
|
self.user = atts.user if atts.respond_to?(:user)
|
181
184
|
add(atts)
|
182
185
|
end
|
186
|
+
|
187
|
+
self
|
183
188
|
end
|
184
189
|
|
185
190
|
# Items can be an Effective::Cart, an Effective::order, a single acts_as_purchasable, or multiple acts_as_purchasables
|
@@ -345,6 +350,14 @@ module Effective
|
|
345
350
|
order_items.map { |oi| oi.quantity }.sum
|
346
351
|
end
|
347
352
|
|
353
|
+
def send_order_receipt_to_admin?
|
354
|
+
EffectiveOrders.mailer[:send_order_receipt_to_admin] && !free?
|
355
|
+
end
|
356
|
+
|
357
|
+
def send_order_receipt_to_buyer?
|
358
|
+
EffectiveOrders.mailer[:send_order_receipt_to_buyer] && !free?
|
359
|
+
end
|
360
|
+
|
348
361
|
def send_payment_request_to_buyer?
|
349
362
|
EffectiveResources.truthy?(send_payment_request_to_buyer) && !free? && !refund?
|
350
363
|
end
|
@@ -425,11 +438,7 @@ module Effective
|
|
425
438
|
def defer!(provider: 'none', email: true)
|
426
439
|
return false if purchased?
|
427
440
|
|
428
|
-
assign_attributes(
|
429
|
-
state: EffectiveOrders::DEFERRED,
|
430
|
-
payment_provider: provider
|
431
|
-
)
|
432
|
-
|
441
|
+
assign_attributes(state: EffectiveOrders::DEFERRED, payment_provider: provider)
|
433
442
|
save!
|
434
443
|
|
435
444
|
send_payment_request_to_buyer! if email
|
@@ -477,8 +486,8 @@ module Effective
|
|
477
486
|
end
|
478
487
|
|
479
488
|
def send_order_receipts!
|
480
|
-
send_order_receipt_to_admin! if
|
481
|
-
send_order_receipt_to_buyer! if
|
489
|
+
send_order_receipt_to_admin! if send_order_receipt_to_admin?
|
490
|
+
send_order_receipt_to_buyer! if send_order_receipt_to_buyer?
|
482
491
|
send_refund_notification! if refund?
|
483
492
|
end
|
484
493
|
|
@@ -562,6 +571,23 @@ module Effective
|
|
562
571
|
end
|
563
572
|
end
|
564
573
|
|
574
|
+
def assign_user_address
|
575
|
+
return unless user.present?
|
576
|
+
return unless (EffectiveOrders.billing_address || EffectiveOrders.shipping_address)
|
577
|
+
return if EffectiveOrders.billing_address && billing_address.present?
|
578
|
+
return if EffectiveOrders.shipping_address && shipping_address.present?
|
579
|
+
|
580
|
+
if billing_address.blank? && user.respond_to?(:billing_address) && user.billing_address.present?
|
581
|
+
self.billing_address = user.billing_address
|
582
|
+
self.billing_address.full_name ||= user.to_s.presence
|
583
|
+
end
|
584
|
+
|
585
|
+
if shipping_address.blank? && user.respond_to?(:shipping_address) && user.shipping_address.present?
|
586
|
+
self.shipping_address = user.shipping_address
|
587
|
+
self.shipping_address.full_name ||= user.to_s.presence
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
565
591
|
def update_purchasables_purchased_order!
|
566
592
|
order_items.each { |oi| oi.purchasable&.update_column(:purchased_order_id, self.id) }
|
567
593
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_orders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.1.
|
4
|
+
version: 5.1.6
|
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: 2021-
|
11
|
+
date: 2021-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|