workarea-core 3.5.15 → 3.5.16

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: c18e8846e0d53604a413bfebe9180793059f63eef7478a6efb5e3c0762e95112
4
- data.tar.gz: 6bc004faf032a0172b6d6495ef3d666944cef5726f91a9d41fca8fc69ce03af3
3
+ metadata.gz: 569f33ae16d992354fca8761ef67ed5473a12755dda710cfff057ebd2d7aa2b4
4
+ data.tar.gz: 24b32513e4215b2aa1c67a5f1d930ae5f8a81ee098be08234eab95f69a6bc574
5
5
  SHA512:
6
- metadata.gz: b367c165ee4ead94e2969e1ced60328c3fe0696bcac53df7a0a67f0eea1faad9e6b82c1eb6a4d1de2530460a7424326357ab6173c70fb7f0362e5c6435bb7f20
7
- data.tar.gz: c7a378a34ebc05ee82b12bf92c85b89e22ca1035ed01a429986d4f82ad7cc664cc54ba411eef0419c9773848296dab6f5beae749e7206e33c5c88c9e032279ad
6
+ metadata.gz: 11b65e3f2de7268ec497fecb2019a10133e2a477cc5bf06cd64390976098baa97277a75a295633a4fd6e43b221d31453c6a4da99b1c05012534e19621a6c7d18
7
+ data.tar.gz: 614ed5b1d7970082ba8eb48b8448434737d194ed1fed7158537774b9e46dce862ab0cae2faafca35f40378a061e3a91c02b9ab4d36875201896ea33ff6b60991
@@ -47,11 +47,7 @@ module Workarea
47
47
  def inventory
48
48
  @inventory ||= Inventory::Transaction.from_order(
49
49
  order.id,
50
- order.items.inject({}) do |memo, item|
51
- memo[item.sku] ||= 0
52
- memo[item.sku] += item.quantity
53
- memo
54
- end
50
+ order.sku_quantities
55
51
  )
56
52
  end
57
53
 
@@ -142,11 +142,11 @@ module Workarea
142
142
  end
143
143
 
144
144
  def policy_class
145
- "Workarea::Inventory::Policies::#{policy.classify}".constantize
145
+ "Workarea::Inventory::Policies::#{policy.camelize}".constantize
146
146
  rescue NameError
147
147
  raise(
148
148
  InvalidPolicy,
149
- "Workarea::Inventory::Policies::#{policy.classify} must be a policy class"
149
+ "Workarea::Inventory::Policies::#{policy.camelize} must be a policy class"
150
150
  )
151
151
  end
152
152
 
@@ -110,14 +110,28 @@ module Workarea
110
110
  end
111
111
 
112
112
  def merge!(other)
113
- %w(orders revenue discounts cancellations refund).each do |field|
114
- self.send("#{field}=", send(field) + other.send(field))
115
- end
116
-
117
- self.first_order_at = [first_order_at, other.first_order_at].compact.min
118
- self.last_order_at = [last_order_at, other.last_order_at].compact.max
119
- self.average_order_value = average_order_value
120
- save!
113
+ # To recalculate average_order_value
114
+ self.orders += other.orders
115
+ self.revenue += other.revenue
116
+
117
+ update = {
118
+ '$set' => {
119
+ average_order_value: average_order_value,
120
+ updated_at: Time.current.utc
121
+ },
122
+ '$inc' => {
123
+ orders: other.orders,
124
+ revenue: other.revenue,
125
+ discounts: other.discounts,
126
+ cancellations: other.cancellations,
127
+ refund: other.refund
128
+ }
129
+ }
130
+
131
+ update['$min'] = { first_order_at: other.first_order_at.utc } if other.first_order_at.present?
132
+ update['$max'] = { last_order_at: other.last_order_at.utc } if other.last_order_at.present?
133
+
134
+ self.class.collection.update_one({ _id: id }, update, upsert: true)
121
135
 
122
136
  self.class.save_affinity(
123
137
  id: id,
@@ -133,6 +147,8 @@ module Workarea
133
147
  category_ids: other.purchased.category_ids,
134
148
  search_ids: other.purchased.search_ids
135
149
  )
150
+
151
+ reload
136
152
  end
137
153
  end
138
154
  end
@@ -375,6 +375,16 @@ module Workarea
375
375
  )
376
376
  end
377
377
 
378
+ # A hash with the quantity of each SKU in the order
379
+ #
380
+ # @return [Hash]
381
+ #
382
+ def sku_quantities
383
+ items.each_with_object(Hash.new(0)) do |item, quantities|
384
+ quantities[item.sku] += item.quantity
385
+ end
386
+ end
387
+
378
388
  private
379
389
 
380
390
  def item_count_limit
@@ -80,12 +80,7 @@ module Workarea
80
80
  build_credit_card unless credit_card
81
81
  credit_card.saved_card_id = nil
82
82
  credit_card.attributes = attrs.slice(
83
- :month,
84
- :year,
85
- :saved_card_id,
86
- :number,
87
- :cvv,
88
- :amount
83
+ *Workarea.config.credit_card_attributes
89
84
  )
90
85
  save
91
86
  end
@@ -1297,6 +1297,17 @@ module Workarea
1297
1297
 
1298
1298
  # The number of results that will show per-type in the admin jump to
1299
1299
  config.jump_to_results_per_type = 5
1300
+
1301
+ # Attributes that will be sliced out of params and persisted on
1302
+ # the credit card tender during checkout.
1303
+ config.credit_card_attributes = %i[
1304
+ month
1305
+ year
1306
+ saved_card_id
1307
+ number
1308
+ cvv
1309
+ amount
1310
+ ]
1300
1311
  end
1301
1312
  end
1302
1313
  end
@@ -1,7 +1,7 @@
1
1
  module Workarea
2
2
  module Configuration
3
3
  class AdministrableOptions < ActiveSupport::InheritableOptions
4
- def method_missing(name, *args)
4
+ def [](name)
5
5
  static_config = super
6
6
  return static_config if static_config.present? || static_config.to_s == 'false'
7
7
  return static_config unless check_fieldsets?(name)
@@ -9,10 +9,6 @@ module Workarea
9
9
  Configuration::Admin.instance.send(name)
10
10
  end
11
11
 
12
- def respond_to_missing?(name, include_private)
13
- true
14
- end
15
-
16
12
  private
17
13
 
18
14
  def check_fieldsets?(name)
@@ -2,7 +2,7 @@ module Workarea
2
2
  module VERSION
3
3
  MAJOR = 3
4
4
  MINOR = 5
5
- PATCH = 15
5
+ PATCH = 16
6
6
  PRE = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workarea-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.15
4
+ version: 3.5.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Crouse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-07 00:00:00.000000000 Z
11
+ date: 2020-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler