Sha256: 9fe3e025600cfd32a6061c62d8f318bd345824cd4d9ce94f9c4307d8800a9c9c

Contents?: true

Size: 487 Bytes

Versions: 26

Compression:

Stored size: 487 Bytes

Contents

require_dependency 'spree/calculator'

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

    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

26 entries across 26 versions & 1 rubygems

Version Path
solidus_core-2.5.2 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.5.1 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.5.0 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.5.0.rc1 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.5.0.beta2 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.5.0.beta1 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.4.2 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.3.1 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.4.1 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.2.2 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.1.1 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.4.0 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.4.0.rc1 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.4.0.beta1 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.3.0 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.3.0.rc3 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.3.0.rc2 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.3.0.rc1 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.3.0.beta1 app/models/spree/calculator/flat_percent_item_total.rb
solidus_core-2.2.1 app/models/spree/calculator/flat_percent_item_total.rb