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

Methods inherited from Base

display_includes

Methods included from Spree::Core::Permalinks

#generate_permalink, #save_permalink

Instance Method Details

#compute(object) ⇒ Object



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

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

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