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



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/spree/calculator/tiered_percent.rb', line 24

def compute(object)
  order = object.is_a?(Order) ? object : object.order

  _base, percent = preferred_tiers.sort.reverse.detect do |b, _|
    order.item_total >= b
  end

  if preferred_currency.casecmp(order.currency).zero?
    (object.amount * (percent || preferred_base_percent) / 100).round(2)
  else
    0
  end
end