Skip to content

Instantly share code, notes, and snippets.

@firebelly
Created November 1, 2011 20:48
Show Gist options
  • Save firebelly/1331856 to your computer and use it in GitHub Desktop.
Save firebelly/1331856 to your computer and use it in GitHub Desktop.
from the annals of bad old code...
def self.gift_card_total(cart)
amount = 0
date = DateTime.new(2010)
LineItem.find(:all, :include => [:order], :conditions => ["orders.created_at BETWEEN ? AND ?
AND line_items.title = ?", date.beginning_of_year, date.end_of_year, 'Gift Card']).collect{
|item| item.total_price }.each{ |price| amount += price
}
cart.items.each{|item|
if item[:item].name == 'Gift Card'
amount += item[:amount].to_f
end
}
#if amount > 2750
# amount = 2750
#end
amount
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment