Class: ShippingMethod

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

Instance Method Summary collapse

Instance Method Details

#available?(order) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'app/models/shipping_method.rb', line 23

def available?(order)
  zone.include?(order.shipment.address) &&
    calculator
end

#calculate_cost(shipment) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/shipping_method.rb', line 7

def calculate_cost(shipment)
  rate_calculators = {}
  shipping_rates.each do |sr|
    rate_calculators[sr.shipping_category_id] = sr.calculator
  end
 
  calculated_costs = shipment.order.line_items.group_by{|li|
    li.product.shipping_category_id
  }.map{ |shipping_category_id, line_items|
    calc = rate_calculators[shipping_category_id] || self.calculator
    calc.compute(line_items)
  }.sum
 
  return(calculated_costs)
end