Class: Spree::Calculator::TieredPercent
- Inherits:
-
Spree::Calculator
- Object
- ActiveRecord::Base
- Base
- Spree::Calculator
- Spree::Calculator::TieredPercent
- Defined in:
- app/models/spree/calculator/tiered_percent.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
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 |