Created
June 15, 2011 23:00
-
-
Save dabit/1028335 to your computer and use it in GitHub Desktop.
This file contains 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 self.use_certificate(code, cart) | |
return false if cart.nil? | |
return cart.set_gift(0, nil) if code.blank? | |
return false if cart.gift_code == code | |
certificate = self.certificate(code).first | |
unless certificate.blank? || certificate.state == 'in_cart' | |
unless certificate.state == 'empty' | |
total = cart.total + cart.gift_discount | |
if certificate.amount < total | |
cart.set_gift(certificate.amount, certificate.gift_code) | |
else | |
cart.set_gift(total, certificate.gift_code) | |
end | |
else | |
cart.set_gift(0, nil) | |
end | |
else | |
cart.set_gift(0, nil) | |
return false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment