spree_temando 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -55,6 +55,32 @@ It's important to note that all products in the cart must have their
55
55
  dimensions filled out (height, length, depth, weight), otherwise Temando
56
56
  will not be able to quote.
57
57
 
58
+ ## Padding
59
+
60
+ Depending on how you actually fulfil the shipments, you might like to
61
+ add some padding to the ETA days provided by Temando. This allows you
62
+ to better manage customer expectations.
63
+
64
+ In this case, you have three fields to tweak:
65
+
66
+ * `Minimum ETA` - the minimum days it will take to ship and deliver. The
67
+ days provided will never be less than this value.
68
+ * `Pad Minimum` - The number of days to pad the "Minimum ETA" by.
69
+ * `Pad Maximum` - the number of days to pad the "Maximum ETA" by.
70
+
71
+ For example, if you know it's always going to take at least 3 days to
72
+ get an order boxed up before you can ship it, you might set each of the
73
+ "pad" values to 3 days, turning a quote for 1-3 days into 4-6 days.
74
+
75
+ Another example is where you know there are frequently delays with your
76
+ usual shipping provider. In this case, you might set the minimum ETA to
77
+ 5, and set each of the padding values to 2. If temando offers a quote at
78
+ 1-2 days, this will turn into 5-7.
79
+
80
+ In this case, the lowest number is forced by the minimum eta setting.
81
+ The highest number is forced to the same value (as it's under 5) and
82
+ then padded by 2.
83
+
58
84
  ## Customisations
59
85
 
60
86
  To simplify all the options for feeding product data to Temando, you can
@@ -5,8 +5,11 @@ module Spree
5
5
  preference :origin_suburb, :string
6
6
  preference :origin_postcode, :string
7
7
  preference :express, :boolean
8
+ preference :minimum_eta, :integer
9
+ preference :pad_minimum, :integer
10
+ preference :pad_maximum, :integer
8
11
 
9
- attr_accessible :preferred_origin_suburb, :preferred_origin_postcode, :preferred_express
12
+ attr_accessible :preferred_origin_suburb, :preferred_origin_postcode, :preferred_express, :preferred_minimum_eta, :preferred_pad_minimum, :preferred_pad_maximum
10
13
 
11
14
  def self.description
12
15
  I18n.t(:temando)
@@ -21,7 +24,7 @@ module Spree
21
24
  return nil if quotes.nil?
22
25
  cheapest = quotes.sort_by { |q| q.total_price }.first
23
26
  if cheapest then
24
- { :price => cheapest.total_price, :minimum_eta => cheapest.minimum_eta, :maximum_eta => cheapest.maximum_eta, :quote => cheapest }
27
+ pad_etas( :price => cheapest.total_price, :minimum_eta => cheapest.minimum_eta, :maximum_eta => cheapest.maximum_eta, :quote => cheapest )
25
28
  else
26
29
  nil
27
30
  end
@@ -33,7 +36,7 @@ module Spree
33
36
  fastest_eta = quotes.collect(&:maximum_eta).min
34
37
  cheapest = quotes.reject { |q| q.maximum_eta > fastest_eta }.sort_by { |q| q.total_price }.first
35
38
  if cheapest then
36
- { :price => cheapest.total_price, :minimum_eta => cheapest.minimum_eta, :maximum_eta => cheapest.maximum_eta, :quote => cheapest }
39
+ pad_etas( :price => cheapest.total_price, :minimum_eta => cheapest.minimum_eta, :maximum_eta => cheapest.maximum_eta, :quote => cheapest )
37
40
  else
38
41
  nil
39
42
  end
@@ -69,7 +72,7 @@ module Spree
69
72
 
70
73
  return if data.nil?
71
74
 
72
- quote = Spree::TemandoQuote.new_or_update_from_quote(self, object, data[:quote], destination)
75
+ quote = Spree::TemandoQuote.new_or_update_from_quote(self, object, data[:quote], destination, data.slice(:minimum_eta, :maximum_eta))
73
76
 
74
77
  # Store the Quote data against the Order and these LineItems if they are persisted
75
78
  if object.persisted? then
@@ -100,5 +103,13 @@ private
100
103
  return nil
101
104
  end
102
105
  end
106
+
107
+ # Pads the ETAs in such a way that both dates are increased by eta_padding,
108
+ # and the minimum_eta is never allowed lower than minimum_eta
109
+ def pad_etas(data)
110
+ data[:minimum_eta] = [ data[:minimum_eta] + (preferred_pad_minimum || 0), (preferred_minimum_eta || 0) ].max
111
+ data[:maximum_eta] = [ data[:maximum_eta], (preferred_minimum_eta || 0) ].max + (preferred_pad_maximum || 0)
112
+ data
113
+ end
103
114
  end
104
115
  end
@@ -26,7 +26,7 @@ module Spree
26
26
  Digest::SHA1.hexdigest(calculator_hash + address_hash + data)
27
27
  end
28
28
 
29
- def self.new_or_update_from_quote(calculator, object, quote, address)
29
+ def self.new_or_update_from_quote(calculator, object, quote, address, data={})
30
30
  q = object.temando_quotes.find_by_calculator_id(calculator.id) || object.temando_quotes.new
31
31
  q.calculator = calculator
32
32
 
@@ -40,6 +40,10 @@ module Spree
40
40
  q.send("#{field}=".to_sym, quote.send(field))
41
41
  end
42
42
 
43
+ data.each do |field, value|
44
+ q.send("#{field}=".to_sym, value)
45
+ end
46
+
43
47
  q.address = address
44
48
  q.cached_items_hash = q.current_items_hash
45
49
 
@@ -1,3 +1,3 @@
1
1
  module SpreeTemando
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_temando
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: