Sha256: 4ed0343f9ecd98dfb3f44293931018107bbbd8757ececd02cf1f05e5df5bbd41

Contents?: true

Size: 899 Bytes

Versions: 96

Compression:

Stored size: 899 Bytes

Contents

require_dependency 'spree/calculator'

module Spree
  class Calculator::PriceSack < Calculator
    preference :minimal_amount, :decimal, default: 0
    preference :normal_amount, :decimal, default: 0
    preference :discount_amount, :decimal, default: 0
    preference :currency, :string, default: -> { Spree::Config[:currency] }

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

    # as object we always get line items, as calculable we have Coupon, ShippingMethod
    def compute(object)
      base = if object.is_a?(Array)
               object.map { |o| o.respond_to?(:amount) ? o.amount : BigDecimal(o.to_s) }.sum
             else
               object.respond_to?(:amount) ? object.amount : BigDecimal(object.to_s)
             end

      if base < preferred_minimal_amount
        preferred_normal_amount
      else
        preferred_discount_amount
      end
    end
  end
end

Version data entries

96 entries across 96 versions & 1 rubygems

Version Path
spree_core-4.0.9 app/models/spree/calculator/price_sack.rb
spree_core-4.1.15 app/models/spree/calculator/price_sack.rb
spree_core-4.2.7 app/models/spree/calculator/price_sack.rb
spree_core-4.3.3 app/models/spree/calculator/price_sack.rb
spree_core-4.2.6 app/models/spree/calculator/price_sack.rb
spree_core-4.3.2 app/models/spree/calculator/price_sack.rb
spree_core-4.3.1 app/models/spree/calculator/price_sack.rb
spree_core-4.3.0 app/models/spree/calculator/price_sack.rb
spree_core-4.3.0.rc3 app/models/spree/calculator/price_sack.rb
spree_core-4.3.0.rc2 app/models/spree/calculator/price_sack.rb
spree_core-4.3.0.rc1 app/models/spree/calculator/price_sack.rb
spree_core-4.2.5 app/models/spree/calculator/price_sack.rb
spree_core-4.1.14 app/models/spree/calculator/price_sack.rb
spree_core-4.0.8 app/models/spree/calculator/price_sack.rb
spree_core-4.2.4 app/models/spree/calculator/price_sack.rb
spree_core-3.7.14.1 app/models/spree/calculator/price_sack.rb
spree_core-4.2.3.1 app/models/spree/calculator/price_sack.rb
spree_core-4.1.13.1 app/models/spree/calculator/price_sack.rb
spree_core-4.0.7.1 app/models/spree/calculator/price_sack.rb
spree_core-4.2.3 app/models/spree/calculator/price_sack.rb