Class: Spree::Calculator::TieredPercent

Inherits:
Spree::Calculator show all
Defined in:
app/models/spree/calculator/tiered_percent.rb

Instance Method Summary collapse

Methods inherited from Spree::Calculator

#available?, calculators, description, #description, register, #to_s

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Methods included from Preferences::Preferable

#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Instance Method Details

#compute(object) ⇒ Object



23
24
25
26
27
# File 'app/models/spree/calculator/tiered_percent.rb', line 23

def compute(object)
  order = object.is_a?(Order) ? object : object.order
  _base, percent = preferred_tiers.sort.reverse.detect{ |b, _| order.item_total >= b }
  (object.amount * (percent || preferred_base_percent) / 100).round(2)
end