Class: ShippingMethod

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/shipping_method.rb

Constant Summary collapse

DISPLAY =
[:both, :front_end, :back_end]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_available(order, display_on = nil) ⇒ Object



21
22
23
# File 'app/models/shipping_method.rb', line 21

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

Returns:

  • (Boolean)


9
10
11
12
13
# File 'app/models/shipping_method.rb', line 9

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

Returns:

  • (Boolean)


15
16
17
18
19
# File 'app/models/shipping_method.rb', line 15

def available_to_order?(order, display_on=nil)
  availability_check = available?(order,display_on)
  zone_check = zone && zone.include?(order.ship_address)
  availability_check && zone_check
end