bodega 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.3
1
+ 0.4.4
@@ -7,7 +7,7 @@ module Bodega
7
7
  attr_accessible :order_products_attributes, :postal_code, :shipping_rate_code
8
8
 
9
9
  before_create :set_identifier
10
- before_save :set_shipping_rates, if: :postal_code_changed?
10
+ before_save :set_shipping_rates, if: :set_shipping_rates?
11
11
  before_save :calculate_shipping, if: :shipping_rate_code_changed?
12
12
  before_save :set_total
13
13
 
@@ -21,7 +21,6 @@ module Bodega
21
21
  maintain :status do
22
22
  state :new, 1, default: true
23
23
  state :complete, 2
24
-
25
24
  on :enter, :complete, :mark_order_products_as_purchased
26
25
  end
27
26
 
@@ -150,6 +149,10 @@ module Bodega
150
149
  @new_shipping_rates = true
151
150
  end
152
151
 
152
+ def set_shipping_rates?
153
+ postal_code_changed? || order_products.any?(&:quantity_changed?)
154
+ end
155
+
153
156
  def set_total
154
157
  self.total = subtotal + tax + shipping
155
158
  end
data/bodega.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "bodega"
8
- s.version = "0.4.3"
8
+ s.version = "0.4.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Flip Sasser"]
@@ -35,7 +35,7 @@ module Bodega
35
35
  end
36
36
 
37
37
  def location_for(location_object)
38
- Location.new(zip: location_object.postal_code)
38
+ Location.new(country: Bodega.config.shipping.origin.country, zip: location_object.postal_code)
39
39
  end
40
40
 
41
41
  def origin
@@ -44,18 +44,20 @@ module Bodega
44
44
 
45
45
  def packages
46
46
  @packages ||= [].tap do |packages|
47
- order.products.each do |product|
48
- packages.push(package_for(product)) if shippable?(product)
47
+ order.order_products.each do |order_product|
48
+ packages.push(package_for(order_product)) if shippable?(order_product.product)
49
49
  end
50
50
  end
51
51
  end
52
52
 
53
- def package_for(product)
54
- Package.new(
55
- product.weight,
56
- product.dimensions,
57
- units: Bodega.config.shipping.units
58
- )
53
+ def package_for(order_product)
54
+ product = order_product.product
55
+ weight = product.weight * order_product.quantity
56
+
57
+ dimensions = product.dimensions
58
+ dimensions[2] = dimensions[2] * order_product.quantity
59
+
60
+ Package.new(weight, dimensions, units: Bodega.config.shipping.units)
59
61
  end
60
62
 
61
63
  def shippable?(product)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bodega
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -158,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
158
  version: '0'
159
159
  segments:
160
160
  - 0
161
- hash: 1686414857410088116
161
+ hash: 272964422154723195
162
162
  required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  none: false
164
164
  requirements: