Sha256: 6003525522356388db5a1721d0e51530c8cef0979ddd07ec6b80fdbd4257b6d9

Contents?: true

Size: 749 Bytes

Versions: 3

Compression:

Stored size: 749 Bytes

Contents

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

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

      def compute(object)
        return 0 if preferred_apply_only_on_full_priced_items && object.variant.compare_at_amount_in(object.currency).present?

        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

3 entries across 3 versions & 1 rubygems

Version Path
spree_core-4.10.1 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.10.0 app/models/spree/calculator/percent_on_line_item.rb
spree_core-4.9.0 app/models/spree/calculator/percent_on_line_item.rb