effective_orders 3.0.2 → 3.0.3

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: 5d975c31db44e626807e5a0f7b1ccb5c21016034daeaad2aef937a79894a322e
4
- data.tar.gz: 5c0ced22f719a0e4c63004d7e0a973f7ae1415665788c0e7bab17519fe23c5e8
3
+ metadata.gz: 79642ded2e176dd43991e456466b69110f2e36ca107a9d49b5e1267ab57ed580
4
+ data.tar.gz: ec779c25f0fb3a8fcc55502105aa69e5a1d5586d2c4aedaef3bdbe4ad6194df3
5
5
  SHA512:
6
- metadata.gz: c2ab9082782d9ed8a5cf18881a1c2a6db96a863a7df47862053fa2a951c8d43c9ba7b5f5527a39f0f71a26ccf55fa477fb9c7605eb3352bef71affd1a84879c3
7
- data.tar.gz: b2241e34923fa1a102f96957763e3eaac53079f2c71c82a2863aae3a589659bcee0d536e07a92f4912025efd7621b9ca568d5ac988bfcf7af06622e1c93ca3b4
6
+ metadata.gz: 3fabbafe0cb9d7a3dc19e559f369ffc90a5a11fb3da6388bea46d6a9ea42255973f2b7467fadaa0b6e5d6752e56f788b422f9483612c25aeb581ff18d4b50a6f
7
+ data.tar.gz: 2caec2a2464df534b68004d4050f7ab1d638c6c5c831b7a172dce582b64b61bf0c23fdd25dc517e316d3868e3d7973e6250735a91e4275f9d4180aacc1f607f7
@@ -114,24 +114,40 @@ module Effective
114
114
 
115
115
  # Effective::Order.new()
116
116
  # Effective::Order.new(Product.first)
117
- # Effective::Order.new(Product.all)
118
- # Effective::Order.new(Product.first, user: User.first)
119
- # Effective::Order.new(Product.first, Product.second, user: User.first)
120
- # Effective::Order.new(user: User.first)
121
117
  # Effective::Order.new(current_cart)
118
+ # Effective::Order.new(Effective::Order.last)
122
119
 
123
- # items can be an Effective::Cart, a single acts_as_purchasable, or an array of acts_as_purchasables
124
- def initialize(*items, user: nil, billing_address: nil, shipping_address: nil)
125
- super() # Call super with no arguments
120
+ # Effective::Order.new(items: Product.first)
121
+ # Effective::Order.new(items: [Product.first, Product.second], user: User.first)
122
+ # Effective::Order.new(items: Product.first, user: User.first, billing_address: Effective::Address.new, shipping_address: Effective::Address.new)
126
123
 
127
- # Assign user
128
- self.user = user || (items.first.user if items.first.kind_of?(Effective::Cart))
124
+ def initialize(atts = nil, &block)
125
+ super(purchase_state: EffectiveOrders::PENDING) # Initialize with state: PENDING
129
126
 
130
- # Assign addresses
131
- self.billing_address = billing_address if billing_address
132
- self.shipping_address = shipping_address if shipping_address
127
+ return unless atts.present?
133
128
 
134
- add(items) if items.present?
129
+ if atts.kind_of?(Hash)
130
+ items = Array(atts.delete(:item)) + Array(atts.delete(:items))
131
+
132
+ self.user = atts.delete(:user) || (items.first.user if items.first.respond_to?(:user))
133
+
134
+ if (address = atts.delete(:billing_address)).present?
135
+ self.billing_address = address
136
+ self.billing_address.full_name ||= user.to_s.presence
137
+ end
138
+
139
+ if (address = atts.delete(:shipping_address)).present?
140
+ self.shipping_address = address
141
+ self.shipping_address.full_name ||= user.to_s.presence
142
+ end
143
+
144
+ atts.each { |key, value| self.send("#{key}=", value) }
145
+
146
+ add(items) if items.present?
147
+ else # Attributes are not a Hash
148
+ self.user = atts.user if atts.respond_to?(:user)
149
+ add(atts)
150
+ end
135
151
  end
136
152
 
137
153
  # add(Product.first) => returns an Effective::OrderItem
@@ -169,8 +185,7 @@ module Effective
169
185
  title: item.title,
170
186
  quantity: item.quantity,
171
187
  price: item.price,
172
- tax_exempt: item.tax_exempt || false,
173
- seller_id: (item.purchasable.try(:seller).try(:id) rescue nil)
188
+ tax_exempt: (item.tax_exempt || false),
174
189
  ).tap { |order_item| order_item.purchasable = item.purchasable }
175
190
  end
176
191
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '3.0.2'.freeze
2
+ VERSION = '3.0.3'.freeze
3
3
  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: 3.0.2
4
+ version: 3.0.3
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: 2019-08-06 00:00:00.000000000 Z
11
+ date: 2019-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails