effective_orders 5.2.6 → 5.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/effective/order.rb +32 -7
- 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: d0353cf2ee2aded74188e0b12ebf53688b379ef454ae9427a0f7be42f58d97b2
|
4
|
+
data.tar.gz: 578ffb35d6763cd78abeb18857ce5f11fc9dc7a6acf452227a17e9675ad10f7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d0e19c0495b5b67fe7c66a1bf6cda6ce712221d87d6c6baea06a81212d8146ee49fc1237a193cc5340f57c19f426329b59804c97c6afc8c39d4b9a55eee9d2a
|
7
|
+
data.tar.gz: c59b93ef057b4fc5ef519b4752619b0fe83e03a6e39403c05a1ae92838bcbb3bb8c647878805b2e812f38f98b355ef3306576f0b6a712569d77d73b77494fc35
|
@@ -103,7 +103,7 @@ module Effective
|
|
103
103
|
end
|
104
104
|
|
105
105
|
# User validations -- An admin skips these when working in the admin/ namespace
|
106
|
-
with_options unless: -> { pending? || skip_buyer_validations? } do
|
106
|
+
with_options unless: -> { pending? || skip_buyer_validations? || purchased? } do
|
107
107
|
validates :tax_rate, presence: { message: "can't be determined based on billing address" }
|
108
108
|
validates :tax, presence: true
|
109
109
|
|
@@ -190,6 +190,31 @@ module Effective
|
|
190
190
|
self
|
191
191
|
end
|
192
192
|
|
193
|
+
def remove(*items)
|
194
|
+
raise 'unable to alter a purchased order' if purchased?
|
195
|
+
raise 'unable to alter a declined order' if declined?
|
196
|
+
|
197
|
+
removed = items.map do |item|
|
198
|
+
order_item = if item.kind_of?(Effective::OrderItem)
|
199
|
+
order_items.find { |oi| oi == item }
|
200
|
+
else
|
201
|
+
order_items.find { |oi| oi.purchasable == item }
|
202
|
+
end
|
203
|
+
|
204
|
+
raise("Unable to find order item for #{item}") if order_item.blank?
|
205
|
+
order_item
|
206
|
+
end
|
207
|
+
|
208
|
+
removed.each { |order_item| order_item.mark_for_destruction }
|
209
|
+
|
210
|
+
# Make sure to reset stored aggregates
|
211
|
+
self.total = nil
|
212
|
+
self.subtotal = nil
|
213
|
+
self.tax = nil
|
214
|
+
|
215
|
+
removed.length == 1 ? removed.first : removed
|
216
|
+
end
|
217
|
+
|
193
218
|
# Items can be an Effective::Cart, an Effective::order, a single acts_as_purchasable, or multiple acts_as_purchasables
|
194
219
|
# add(Product.first) => returns an Effective::OrderItem
|
195
220
|
# add(Product.first, current_cart) => returns an array of Effective::OrderItems
|
@@ -249,7 +274,7 @@ module Effective
|
|
249
274
|
raise('already purchased') if purchased?
|
250
275
|
raise('must be pending or confirmed') unless pending? || confirmed?
|
251
276
|
|
252
|
-
|
277
|
+
present_order_items.each do |item|
|
253
278
|
purchasable = item.purchasable
|
254
279
|
|
255
280
|
if purchasable.blank? || purchasable.marked_for_destruction?
|
@@ -318,9 +343,9 @@ module Effective
|
|
318
343
|
Effective::Order.new(self)
|
319
344
|
end
|
320
345
|
|
321
|
-
# For moneris and moneris_checkout. Just a unique value.
|
346
|
+
# For moneris and moneris_checkout. Just a unique value. Must be 50 characters or fewer or will raise moneris error.
|
322
347
|
def transaction_id
|
323
|
-
[to_param, billing_name.to_s.parameterize.presence, Time.zone.now.to_i].compact.join('-')
|
348
|
+
[to_param, billing_name.to_s.parameterize.first(20).presence, Time.zone.now.to_i, rand(1000..9999)].compact.join('-')
|
324
349
|
end
|
325
350
|
|
326
351
|
def billing_first_name
|
@@ -358,11 +383,11 @@ module Effective
|
|
358
383
|
end
|
359
384
|
|
360
385
|
def purchasables
|
361
|
-
|
386
|
+
present_order_items.map { |order_item| order_item.purchasable }
|
362
387
|
end
|
363
388
|
|
364
389
|
def subtotal
|
365
|
-
self[:subtotal] ||
|
390
|
+
self[:subtotal] || present_order_items.map { |oi| oi.subtotal }.sum
|
366
391
|
end
|
367
392
|
|
368
393
|
def tax_rate
|
@@ -386,7 +411,7 @@ module Effective
|
|
386
411
|
end
|
387
412
|
|
388
413
|
def num_items
|
389
|
-
|
414
|
+
present_order_items.map { |oi| oi.quantity }.sum
|
390
415
|
end
|
391
416
|
|
392
417
|
def send_order_receipt_to_admin?
|
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.2.
|
4
|
+
version: 5.2.10
|
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-12-
|
11
|
+
date: 2021-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|