Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sbeam/731422 to your computer and use it in GitHub Desktop.
Save sbeam/731422 to your computer and use it in GitHub Desktop.
commit 1a448022d42dd91021b042ecb7d31f60170352e5
Author: Sam Beam <sbeam@onsetcorps.net>
Date: Mon Dec 6 21:08:43 2010 -0500
return a nil from Calculator::ActiveShipping::compute when the method is not found in the API response, and pass it through so the customer is not presented with a free shipping option
diff --git a/app/controllers/checkouts_controller.rb b/app/controllers/checkouts_controller.rb
index 1b94dc2..7c56f8d 100644
--- a/app/controllers/checkouts_controller.rb
+++ b/app/controllers/checkouts_controller.rb
@@ -225,7 +225,7 @@ class CheckoutsController < Spree::BaseController
:name => ship_method.name,
:cost => ship_method.calculate_cost(@checkout.shipment)
}
- end.sort_by{|r| r[:cost]}
+ end.reject{ |r| r[:cost].nil? }.sort_by{|r| r[:cost]}
rescue Spree::ShippingError => ship_error
flash[:error] = ship_error.to_s
[]
diff --git a/app/models/shipping_method.rb b/app/models/shipping_method.rb
index ada66fc..f3f1b11 100644
--- a/app/models/shipping_method.rb
+++ b/app/models/shipping_method.rb
@@ -17,9 +17,9 @@ class ShippingMethod < ActiveRecord::Base
}.map{ |shipping_category_id, line_items|
calc = rate_calculators[shipping_category_id] || self.calculator
calc.compute(line_items)
- }.sum
+ }.reject(&:nil?)
- return(calculated_costs)
+ return calculated_costs.sum unless calculated_costs.blank?
end
def available?(order, display_on=nil)
diff --git a/vendor/extensions/active_shipping/app/models/calculator/active_shipping.rb b/vendor/extensions/active_shipping/app/models/calculator/active_shipping.rb
index 06ac2a5..df4452e 100644
--- a/vendor/extensions/active_shipping/app/models/calculator/active_shipping.rb
+++ b/vendor/extensions/active_shipping/app/models/calculator/active_shipping.rb
@@ -28,7 +28,7 @@ class Calculator::ActiveShipping < Calculator
rates = retrieve_rates(origin, destination, packages(order))
end
- return nil if rates.empty?
+ return nil if rates.empty? or rates[self.description].nil?
rate = rates[self.description].to_f + (Spree::ActiveShipping::Config[:handling_fee].to_f || 0.0)
return nil unless rate
# divide by 100 since active_shipping rates are expressed as cents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment