Class: Spree::Calculator::FlatPercentItemTotal
- Inherits:
-
Spree::Calculator
- Object
- ActiveRecord::Base
- Base
- Spree::Calculator
- Spree::Calculator::FlatPercentItemTotal
- Defined in:
- app/models/spree/calculator/flat_percent_item_total.rb
Instance Method Summary collapse
Methods inherited from Spree::Calculator
#available?, #description, description, #to_s
Methods inherited from Base
Methods included from Spree::Core::Permalinks
#generate_permalink, #save_permalink
Instance Method Details
#compute(object) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/models/spree/calculator/flat_percent_item_total.rb', line 9 def compute(object) order = object.is_a?(Order) ? object : object.order preferred_currency = order.currency currency_exponent = ::Money::Currency.find(preferred_currency).exponent computed_amount = (object.amount * preferred_flat_percent / 100).round(currency_exponent) # We don't want to cause the promotion adjustments to push the order into a negative total. if computed_amount > object.amount object.amount else computed_amount end end |