Class: Spree::Calculator::FlatPercentItemTotal

Inherits:
Spree::Calculator
  • Object
show all
Defined in:
app/models/spree/calculator/flat_percent_item_total.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Spree::Calculator

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

Class Method Details

.descriptionObject



9
10
11
# File 'app/models/spree/calculator/flat_percent_item_total.rb', line 9

def self.description
  Spree.t(:flat_percent)
end

Instance Method Details

#compute(object) ⇒ Object



13
14
15
16
17
18
# File 'app/models/spree/calculator/flat_percent_item_total.rb', line 13

def compute(object)
  return unless object.present? and object.respond_to?(:item_total)
  item_total = object.item_total
  value = item_total * BigDecimal(self.preferred_flat_percent.to_s) / 100.0
  (value * 100).round.to_f / 100
end