app/models/order.rb
# get shipment cost based on store_product_shipping_rates table
get shipment cost based on store_product_shipping_rates table
get shipment cost based on store_product_shipping_rates table
def calculate_shipping_cost
    rates = {} 
    cost = 0.00
    items.each do |i|
      code = i.product.shipping_code
      raise "Shipping code not set for #{i.product.item_number}" if code.blank?
      rates[code] = 0 if rates[code].nil?
      rates[code] += i.quantity
    end
    rates.each do |code, quantity|
      sr = ProductShippingRate.find_by!(code: code, destination_country_code: 'US', ship_method: :standard)
      cost += sr.get_cost(quantity)
    end
    cost
  end
def calculate_shipping_cost rates = { } cost = 0.00 items . each do | i | code = i . product . shipping_code raise "Shipping code not set for #{i.product.item_number}" if code . blank? rates [ code ] = 0 if rates [ code ] . nil? rates [ code ] += i . quantity end rates . each do | code , quantity | sr = ProductShippingRate . find_by! ( code : code , destination_country_code : 'US' , ship_method : :standard ) cost += sr . get_cost ( quantity ) end cost end
get shipment cost based on store_product_shipping_rates table
get shipment cost based on store_product_shipping_rates table
# hash of shipping_code : number_of_items