Sha256: fe56fe58d198b68abde3da1554532b7762637a43594eb87b586646df961fec22

Contents?: true

Size: 545 Bytes

Versions: 79

Compression:

Stored size: 545 Bytes

Contents

module Spree
  class Calculator
    class PercentOnLineItem < Calculator
      preference :percent, :decimal, default: 0

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

      def compute(object)
        computed_amount = (object.amount * preferred_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
end

Version data entries

79 entries across 79 versions & 1 rubygems

Version Path
spree_core-4.8.3 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.8.2 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.7.3 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.6.6 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.5.5 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.0.9 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.1.15 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.2.7 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.3.3 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.4.1 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.5.4 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.6.5 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.7.2 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.7.1 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.6.4 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.7.0 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.6.3 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.6.2 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.6.1 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.6.0 app/models/spree/calculator/percent_on_line_item.rb