Class: Spree::Calculator::FlatPercentItemTotal
Class Method Summary
collapse
Instance Method Summary
collapse
#available?, calculators, #description, register, #to_s
Class Method Details
.description ⇒ Object
5
6
7
|
# File 'app/models/spree/calculator/flat_percent_item_total.rb', line 5
def self.description
I18n.t(:flat_percent)
end
|
Instance Method Details
#compute(object) ⇒ Object
9
10
11
12
13
14
|
# File 'app/models/spree/calculator/flat_percent_item_total.rb', line 9
def compute(object)
return unless object.present? and object.line_items.present?
item_total = object.line_items.map(&:amount).sum
value = item_total * BigDecimal(self.preferred_flat_percent.to_s) / 100.0
(value * 100).round.to_f / 100
end
|