Class: Spree::Calculator::TieredFlatRate

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

Instance Method Summary collapse

Methods inherited from Spree::Calculator

#available?, calculators, description, #description, #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



20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/spree/calculator/tiered_flat_rate.rb', line 20

def compute(object)
  _base, amount = preferred_tiers.sort.reverse.detect do |b, _|
    object.amount >= b
  end

  if preferred_currency.casecmp(object.currency).zero?
    amount || preferred_base_amount
  else
    0
  end
end