Created
April 18, 2011 11:01
-
-
Save karlentwistle/925139 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
class Calculator::PriceBucket < Calculator | |
preference :minimal_amount, :decimal, :default => 0 | |
preference :normal_amount, :decimal, :default => 0 | |
preference :discount_amount, :decimal, :default => 0 | |
def self.description | |
I18n.t("price_bucket") | |
end | |
def self.register | |
super | |
#Promotion.register_calculator(self) | |
ShippingMethod.register_calculator(self) | |
end | |
# as object we always get line items, as calculable we have Coupon, ShippingMethod | |
def compute(object) | |
base = object.line_items.inject(0) {|sum, li| sum += li.amount } | |
if base < self.preferred_minimal_amount | |
self.preferred_normal_amount | |
else | |
self.preferred_discount_amount | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment