Sha256: 95db128100c9ebdb4e968783c569a1c54204819e14e1af3d53a3262f2ea734da

Contents?: true

Size: 550 Bytes

Versions: 139

Compression:

Stored size: 550 Bytes

Contents

require_dependency 'spree/calculator'

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

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

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

Version data entries

139 entries across 139 versions & 2 rubygems

Version Path
spree_core-3.7.0.rc3 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-3.7.0.rc2 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-3.7.0.rc1 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-3.6.6 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-3.6.5 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-3.6.4 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-3.6.3 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-3.6.2 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-3.6.1 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-3.6.0 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-3.5.0 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-3.6.0.rc1 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-3.5.0.rc2 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-3.5.0.rc1 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-3.4.5 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-3.4.4 app/models/spree/calculator/flat_percent_item_total.rb
spree_core-3.4.3 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.0.3 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-1.4.2 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-1.3.2 app/models/spree/calculator/flat_percent_item_total.rb