Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow Temando quote ETAs to be padded

  • Loading branch information...
commit f3489f53e90a7b8a5c29216c5711068bd2c205e4 1 parent acd9457
Jason Stirk authored
View
26 README.md
@@ -55,6 +55,32 @@ It's important to note that all products in the cart must have their
dimensions filled out (height, length, depth, weight), otherwise Temando
will not be able to quote.
+## Padding
+
+Depending on how you actually fulfil the shipments, you might like to
+add some padding to the ETA days provided by Temando. This allows you
+to better manage customer expectations.
+
+In this case, you have three fields to tweak:
+
+* `Minimum ETA` - the minimum days it will take to ship and deliver. The
+days provided will never be less than this value.
+* `Pad Minimum` - The number of days to pad the "Minimum ETA" by.
+* `Pad Maximum` - the number of days to pad the "Maximum ETA" by.
+
+For example, if you know it's always going to take at least 3 days to
+get an order boxed up before you can ship it, you might set each of the
+"pad" values to 3 days, turning a quote for 1-3 days into 4-6 days.
+
+Another example is where you know there are frequently delays with your
+usual shipping provider. In this case, you might set the minimum ETA to
+5, and set each of the padding values to 2. If temando offers a quote at
+1-2 days, this will turn into 5-7.
+
+In this case, the lowest number is forced by the minimum eta setting.
+The highest number is forced to the same value (as it's under 5) and
+then padded by 2.
+
## Customisations
To simplify all the options for feeding product data to Temando, you can
View
19 app/models/spree/calculator/temando_quote.rb
@@ -5,8 +5,11 @@ class Calculator::TemandoQuote < Calculator
preference :origin_suburb, :string
preference :origin_postcode, :string
preference :express, :boolean
+ preference :minimum_eta, :integer
+ preference :pad_minimum, :integer
+ preference :pad_maximum, :integer
- attr_accessible :preferred_origin_suburb, :preferred_origin_postcode, :preferred_express
+ attr_accessible :preferred_origin_suburb, :preferred_origin_postcode, :preferred_express, :preferred_minimum_eta, :preferred_pad_minimum, :preferred_pad_maximum
def self.description
I18n.t(:temando)
@@ -21,7 +24,7 @@ def cheapest(destination, line_items)
return nil if quotes.nil?
cheapest = quotes.sort_by { |q| q.total_price }.first
if cheapest then
- { :price => cheapest.total_price, :minimum_eta => cheapest.minimum_eta, :maximum_eta => cheapest.maximum_eta, :quote => cheapest }
+ pad_etas( :price => cheapest.total_price, :minimum_eta => cheapest.minimum_eta, :maximum_eta => cheapest.maximum_eta, :quote => cheapest )
else
nil
end
@@ -33,7 +36,7 @@ def fastest(destination, line_items)
fastest_eta = quotes.collect(&:maximum_eta).min
cheapest = quotes.reject { |q| q.maximum_eta > fastest_eta }.sort_by { |q| q.total_price }.first
if cheapest then
- { :price => cheapest.total_price, :minimum_eta => cheapest.minimum_eta, :maximum_eta => cheapest.maximum_eta, :quote => cheapest }
+ pad_etas( :price => cheapest.total_price, :minimum_eta => cheapest.minimum_eta, :maximum_eta => cheapest.maximum_eta, :quote => cheapest )
else
nil
end
@@ -69,7 +72,7 @@ def compute(object)
return if data.nil?
- quote = Spree::TemandoQuote.new_or_update_from_quote(self, object, data[:quote], destination)
+ quote = Spree::TemandoQuote.new_or_update_from_quote(self, object, data[:quote], destination, data.slice(:minimum_eta, :maximum_eta))
# Store the Quote data against the Order and these LineItems if they are persisted
if object.persisted? then
@@ -100,5 +103,13 @@ def find_quotes(destination, line_items)
return nil
end
end
+
+ # Pads the ETAs in such a way that both dates are increased by eta_padding,
+ # and the minimum_eta is never allowed lower than minimum_eta
+ def pad_etas(data)
+ data[:minimum_eta] = [ data[:minimum_eta] + (preferred_pad_minimum || 0), (preferred_minimum_eta || 0) ].max
+ data[:maximum_eta] = [ data[:maximum_eta], (preferred_minimum_eta || 0) ].max + (preferred_pad_maximum || 0)
+ data
+ end
end
end
View
6 app/models/spree/temando_quote.rb
@@ -26,7 +26,7 @@ def current_items_hash
Digest::SHA1.hexdigest(calculator_hash + address_hash + data)
end
- def self.new_or_update_from_quote(calculator, object, quote, address)
+ def self.new_or_update_from_quote(calculator, object, quote, address, data={})
q = object.temando_quotes.find_by_calculator_id(calculator.id) || object.temando_quotes.new
q.calculator = calculator
@@ -40,6 +40,10 @@ def self.new_or_update_from_quote(calculator, object, quote, address)
q.send("#{field}=".to_sym, quote.send(field))
end
+ data.each do |field, value|
+ q.send("#{field}=".to_sym, value)
+ end
+
q.address = address
q.cached_items_hash = q.current_items_hash
Please sign in to comment.
Something went wrong with that request. Please try again.