Class: Spree::Calculator::FlatPercentItemTotal

Inherits:
Spree::Calculator show all
Defined in:
app/models/spree/calculator/flat_percent_item_total.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



7
8
9
10
11
12
13
14
15
16
# File 'app/models/spree/calculator/flat_percent_item_total.rb', line 7

def compute(object)
  computed_amount = (object.amount * preferred_flat_percent / 100).round(2)

  # We don't want to cause the promotion adjustments to push the order into a negative total.
  if computed_amount > object.amount
    object.amount
  else
    computed_amount
  end
end