Sha256: 6034e668faebf1b867710d6539f466d1e12af287c970d144d5a05eed5f277a13
Contents?: true
Size: 671 Bytes
Versions: 6
Compression:
Stored size: 671 Bytes
Contents
class ShippingMethod < ActiveRecord::Base belongs_to :zone has_many :shipping_rates has_calculator 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 def available?(order) zone.include?(order.shipment.address) && calculator end end
Version data entries
6 entries across 6 versions & 2 rubygems