Created
September 24, 2009 20:51
-
-
Save eastmedia/193043 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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