Created
March 18, 2010 04:29
-
-
Save lightandshadow68/336042 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
def create_discount(order) | |
return if order.coupon_credits.reload.detect { |credit| credit.adjustment_source_id == self.id } | |
if eligible?(order) and amount = calculator.compute(order.line_items) | |
amount = order.item_total if amount > order.item_total | |
order.coupon_credits.reload.clear unless combine? and order.coupon_credits.all? { |credit| credit.adjustment_source.combine? } | |
order.save | |
coupon_credits.create({ | |
:order => order, | |
#:amount => amount, #exclude this key / value to force recalculation | |
:description => "#{I18n.t(:coupon)} (#{code})" | |
}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment