Class: Calculator::TieredPercent
- Inherits:
-
Calculator
- Object
- Calculator
- Calculator::TieredPercent
- Defined in:
- app/models/spree/calculator/tiered_percent.rb
Instance Method Summary collapse
Instance Method Details
#compute(object) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/spree/calculator/tiered_percent.rb', line 26 def compute(object) order = object.is_a?(Order) ? object : object.order _base, percent = preferred_tiers.sort.reverse.detect do |value, _| order.item_total >= value end if preferred_currency.casecmp(order.currency).zero? currency_exponent = ::Money::Currency.find(preferred_currency).exponent (object.amount * (percent || preferred_base_percent) / 100).round(currency_exponent) else 0 end end |