Sha256: a285f9287df987745895bf31a7851ab630e247d42b344c96c0c887868e812a0b

Contents?: true

Size: 549 Bytes

Versions: 24

Compression:

Stored size: 549 Bytes

Contents

require_dependency 'spree/calculator'

module Spree
  class Calculator::FlatPercentItemTotal < Calculator
    preference :flat_percent, :decimal, :default => 0

    attr_accessible :preferred_flat_percent

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

    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
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
spree_core-1.3.5 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.3.4 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.3.3 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.2.5 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.1.6 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.1.5 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.2.4 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.3.2 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.0.7 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.2.3 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.3.1 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.3.0 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.3.0.rc2 app/models/spree/calculator/flat_percent_item_total.rb
dup_spree_core-1.3.0.rc1 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.3.0.rc1 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.2.2 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.1.4 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.2.0 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.2.0.rc2 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-1.2.0.rc1 app/models/spree/calculator/flat_percent_item_total.rb