Permalink
Browse files

Refactor out shipping_method checks so they can be performed individu…

…ally

This would help to determine why a particular shipping method may not apply to an order
  • Loading branch information...
1 parent c66dcc3 commit 82a45fc29b3d0dbe3241ebf43c4d9b633291d4a9 @radar radar committed May 25, 2012
Showing with 17 additions and 8 deletions.
  1. +17 −8 core/app/models/spree/shipping_method.rb
@@ -12,16 +12,25 @@ class ShippingMethod < ActiveRecord::Base
calculated_adjustments
def available?(order, display_on = nil)
- display_check = (self.display_on == display_on.to_s || self.display_on.blank?)
- calculator_check = calculator.available?(order)
- display_check && calculator_check
+ displayable? && calculator.available?(order)
end
- def available_to_order?(order, display_on = nil)
- availability_check = available?(order,display_on)
- zone_check = zone && zone.include?(order.ship_address)
- category_check = category_match?(order)
- availability_check && zone_check && category_check
+ def displayable?
+ (self.display_on == display_on.to_s || self.display_on.blank?)
+ end
+
+ def calculator_available?(order)
+ caluclator.available?(order)
+ end
+
+ def within_zone?(order)
+ zone && zone.include?(order.ship_address)
+ end
+
+ def available_to_order?(order, display_on= nil)
+ available?(order, display_on) &&
+ within_zone?(order) &&
+ category_match?(order)
end
# Indicates whether or not the category rules for this shipping method

0 comments on commit 82a45fc

Please sign in to comment.