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
- #adjustment_label ⇒ Object
- #available?(order, display_on = nil) ⇒ Boolean
- #available_to_order?(order, display_on = nil) ⇒ Boolean
- #calculator_currency ⇒ Object
-
#category_match?(order) ⇒ Boolean
Indicates whether or not the category rules for this shipping method are satisfied (if applicable).
- #currency_match?(order) ⇒ Boolean
- #displayable?(display_on) ⇒ Boolean
- #within_zone?(order) ⇒ Boolean
Class Method Details
.all_available(order, display_on = nil) ⇒ Object
63 64 65 |
# File 'app/models/spree/shipping_method.rb', line 63 def self.all_available(order, display_on = nil) all.select { |method| method.available_to_order?(order,display_on) } end |
Instance Method Details
#adjustment_label ⇒ Object
18 19 20 |
# File 'app/models/spree/shipping_method.rb', line 18 def adjustment_label I18n.t(:shipping) end |
#available?(order, display_on = nil) ⇒ Boolean
22 23 24 |
# File 'app/models/spree/shipping_method.rb', line 22 def available?(order, display_on = nil) displayable?(display_on) && calculator.available?(order) end |
#available_to_order?(order, display_on = nil) ⇒ Boolean
34 35 36 37 38 39 |
# File 'app/models/spree/shipping_method.rb', line 34 def available_to_order?(order, display_on= nil) available?(order, display_on) && within_zone?(order) && category_match?(order) && currency_match?(order) end |
#calculator_currency ⇒ Object
59 60 61 |
# File 'app/models/spree/shipping_method.rb', line 59 def calculator_currency calculator.preferences[:currency] end |
#category_match?(order) ⇒ Boolean
Indicates whether or not the category rules for this shipping method are satisfied (if applicable)
43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/models/spree/shipping_method.rb', line 43 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 |
#currency_match?(order) ⇒ Boolean
55 56 57 |
# File 'app/models/spree/shipping_method.rb', line 55 def currency_match?(order) calculator_currency.nil? || calculator_currency == order.currency end |
#displayable?(display_on) ⇒ Boolean
26 27 28 |
# File 'app/models/spree/shipping_method.rb', line 26 def displayable?(display_on) (self.display_on == display_on.to_s || self.display_on.blank?) end |
#within_zone?(order) ⇒ Boolean
30 31 32 |
# File 'app/models/spree/shipping_method.rb', line 30 def within_zone?(order) zone && zone.include?(order.ship_address) end |