Sha256: 988ca3bdf74ee9daca1b4032175fcf1ebea18550c5b036aa33a0aa18d695250f

Contents?: true

Size: 816 Bytes

Versions: 26

Compression:

Stored size: 816 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] }

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

26 entries across 26 versions & 1 rubygems

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