effective_orders 4.6.1 → 5.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/app/controllers/admin/orders_controller.rb +1 -1
- data/app/controllers/effective/orders_controller.rb +3 -3
- data/app/models/effective/order.rb +7 -10
- data/app/models/effective/order_item.rb +10 -0
- 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: 982893ebe426c1097f68ffaccbd87a1977c5d48f4ce1a45dbbf5b13752572542
|
4
|
+
data.tar.gz: 1742602893eb3c98aea29e31161c05e60b67929802ed51a39c40d20fb3c4f2b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa41b81eba8d7c6364fe8192f3e072149562228a666cd8b7b2b41845258e1684a00947bce0b890d9f77f5887ae1a87ba377b68909c7f99d2773ac1801acd12c4
|
7
|
+
data.tar.gz: f7759f4669a5a66492b6dd0259d5e744d64c403775112d0577280397d4b31e2d98dd66bf764e18c4e5359b16346d22b9444ecb65b087b55c4638e2bf28eccfa2
|
data/README.md
CHANGED
@@ -351,7 +351,10 @@ The permissions you actually want to define for a regular user are as follows (u
|
|
351
351
|
|
352
352
|
```ruby
|
353
353
|
can [:manage], Effective::Cart, user_id: user.id
|
354
|
+
|
354
355
|
can [:manage], Effective::Order, user_id: user.id # Orders cannot be deleted
|
356
|
+
cannot [:edit, :update], Effective::Order, state: 'purchased'
|
357
|
+
|
355
358
|
can [:manage], Effective::Subscription, user_id: user.id
|
356
359
|
```
|
357
360
|
|
@@ -68,13 +68,13 @@ module Effective
|
|
68
68
|
|
69
69
|
# Always step1
|
70
70
|
def edit
|
71
|
-
@order ||= Effective::Order.find(params[:id])
|
71
|
+
@order ||= Effective::Order.not_purchased.find(params[:id])
|
72
72
|
EffectiveResources.authorize!(self, :edit, @order)
|
73
73
|
end
|
74
74
|
|
75
75
|
# Confirms the order from existing order
|
76
76
|
def update
|
77
|
-
@order ||= Effective::Order.find(params[:id])
|
77
|
+
@order ||= Effective::Order.not_purchased.find(params[:id])
|
78
78
|
EffectiveResources.authorize!(self, :update, @order)
|
79
79
|
|
80
80
|
@order.assign_attributes(checkout_params)
|
@@ -110,7 +110,7 @@ module Effective
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def send_buyer_receipt
|
113
|
-
@order = Effective::Order.find(params[:id])
|
113
|
+
@order = Effective::Order.purchased.find(params[:id])
|
114
114
|
EffectiveResources.authorize!(self, :show, @order)
|
115
115
|
|
116
116
|
if @order.send_order_receipt_to_buyer!
|
@@ -34,10 +34,6 @@ module Effective
|
|
34
34
|
belongs_to :user, polymorphic: true, validate: false # This is the buyer/user of the order. We validate it below.
|
35
35
|
has_many :order_items, -> { order(:id) }, inverse_of: :order, dependent: :delete_all
|
36
36
|
|
37
|
-
if defined?(EffectiveQbSync)
|
38
|
-
has_one :qb_order_item
|
39
|
-
end
|
40
|
-
|
41
37
|
accepts_nested_attributes_for :order_items, allow_destroy: false, reject_if: :all_blank
|
42
38
|
accepts_nested_attributes_for :user, allow_destroy: false, update_only: true
|
43
39
|
|
@@ -78,6 +74,10 @@ module Effective
|
|
78
74
|
self.state = EffectiveOrders::CONFIRMED if pending?
|
79
75
|
end
|
80
76
|
|
77
|
+
before_save(if: -> { state_was == EffectiveOrders::PURCHASED }) do
|
78
|
+
raise EffectiveOrders::AlreadyPurchasedException.new('cannot unpurchase an order') unless purchased?
|
79
|
+
end
|
80
|
+
|
81
81
|
# Order validations
|
82
82
|
validates :user_id, presence: true
|
83
83
|
validates :email, presence: true, email: true # email and cc validators are from effective_resources
|
@@ -261,12 +261,6 @@ module Effective
|
|
261
261
|
end
|
262
262
|
end
|
263
263
|
|
264
|
-
# first or build
|
265
|
-
def qb_item_name
|
266
|
-
raise('expected EffectiveQbSync gem') unless defined?(EffectiveQbSync)
|
267
|
-
(qb_order_item || build_qb_order_item(name: purchasable.qb_item_name)).name
|
268
|
-
end
|
269
|
-
|
270
264
|
def pending?
|
271
265
|
state == EffectiveOrders::PENDING
|
272
266
|
end
|
@@ -338,6 +332,8 @@ module Effective
|
|
338
332
|
# It skips any address or bad user validations
|
339
333
|
# It's basically the same as save! on a new order, except it might send the payment request to buyer
|
340
334
|
def pending!
|
335
|
+
return false if purchased?
|
336
|
+
|
341
337
|
self.state = EffectiveOrders::PENDING
|
342
338
|
self.addresses.clear if addresses.any? { |address| address.valid? == false }
|
343
339
|
save!
|
@@ -348,6 +344,7 @@ module Effective
|
|
348
344
|
|
349
345
|
# Used by admin checkout only
|
350
346
|
def confirm!
|
347
|
+
return false if purchased?
|
351
348
|
update!(state: EffectiveOrders::CONFIRMED)
|
352
349
|
end
|
353
350
|
|
@@ -5,6 +5,10 @@ module Effective
|
|
5
5
|
belongs_to :order
|
6
6
|
belongs_to :purchasable, polymorphic: true
|
7
7
|
|
8
|
+
if defined?(EffectiveQbSync)
|
9
|
+
has_one :qb_order_item
|
10
|
+
end
|
11
|
+
|
8
12
|
effective_resource do
|
9
13
|
name :string
|
10
14
|
quantity :integer
|
@@ -61,5 +65,11 @@ module Effective
|
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
68
|
+
# first or build
|
69
|
+
def qb_item_name
|
70
|
+
raise('expected EffectiveQbSync gem') unless defined?(EffectiveQbSync)
|
71
|
+
(qb_order_item || build_qb_order_item(name: purchasable.qb_item_name)).name
|
72
|
+
end
|
73
|
+
|
64
74
|
end
|
65
75
|
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:
|
4
|
+
version: 5.0.2
|
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-03-
|
11
|
+
date: 2021-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|