Skip to content

Instantly share code, notes, and snippets.

@eastmedia
Created September 24, 2009 20:51
Show Gist options
  • Save eastmedia/193043 to your computer and use it in GitHub Desktop.
Save eastmedia/193043 to your computer and use it in GitHub Desktop.
# price
# quantity
class LineItem < ActiveRecord::Base
belongs_to :product
belongs_to :order
def calculate_cost
price * quantity * discount_multiplier
end
def discount_multiplier
# note: I have no idea how the region is set in the app
discount = Discount.find_by_product_id_and_quantity_and_region(product.id, quantity, order.user.region)
discount ? discount.multiplier : 1 # hack, but you get the idea.
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment