Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a max_weight preference that is used to determine if this

Calculator/ShippingMethod can be used or not.
  • Loading branch information...
commit cb84babe6d52cbfb8d7f7394763e270baf085d8d 1 parent e67cdd7
Tyler Rick authored
Showing with 11 additions and 2 deletions.
  1. +11 −2 app/models/calculator/weight_bucket.rb
View
13 app/models/calculator/weight_bucket.rb
@@ -1,5 +1,6 @@
class Calculator::WeightBucket < Calculator::Advanced
preference :default_weight, :decimal, :default => 0
+ preference :max_weight, :decimal, :default => 0
def self.description
I18n.t("weight_bucket", :scope => :calculator_names)
@@ -15,10 +16,18 @@ def shipment_weight(shipment)
}.sum
end
+ def available?(object)
+ return true if preferred_max_weight.nil?
+ weight = shipment_weight(object)
+ Rails.logger.debug "... #{weight} <= #{preferred_max_weight} ? => #{weight <= preferred_max_weight}"
+ weight <= preferred_max_weight
+ end
+
# object will be Shipment
# calculable will be ShippingMethod
def compute(object)
- total_weight = shipment_weight(object)
- get_rate(total_weight) || self.preferred_default_amount
+ weight = shipment_weight(object)
+ get_rate(weight) || self.preferred_default_amount
end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.