Class: Spree::ShippingMethod
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::ShippingMethod
- Defined in:
- app/models/spree/shipping_method.rb
Constant Summary collapse
- DISPLAY =
[:both, :front_end, :back_end]
Class Method Summary collapse
Instance Method Summary collapse
- #available?(order, display_on = nil) ⇒ Boolean
- #available_to_order?(order, display_on = nil) ⇒ Boolean
-
#category_match?(order) ⇒ Boolean
Indicates whether or not the category rules for this shipping method are satisfied (if applicable).
Class Method Details
.all_available(order, display_on = nil) ⇒ Object
38 39 40 |
# File 'app/models/spree/shipping_method.rb', line 38 def self.all_available(order, display_on=nil) all.select { |method| method.available_to_order?(order,display_on) } end |
Instance Method Details
#available?(order, display_on = nil) ⇒ Boolean
11 12 13 14 15 |
# File 'app/models/spree/shipping_method.rb', line 11 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 end |
#available_to_order?(order, display_on = nil) ⇒ Boolean
17 18 19 20 21 22 |
# File 'app/models/spree/shipping_method.rb', line 17 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 end |
#category_match?(order) ⇒ Boolean
Indicates whether or not the category rules for this shipping method are satisfied (if applicable)
26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/spree/shipping_method.rb', line 26 def category_match?(order) return true if shipping_category.nil? if match_all order.products.all? { |p| p.shipping_category == shipping_category } elsif match_one order.products.any? { |p| p.shipping_category == shipping_category } elsif match_none order.products.all? { |p| p.shipping_category != shipping_category } end end |