Sha256: 4c7e766330e4abee742bbd35cf76a15cee7795f88029eb9474bc3b36893b31c3

Contents?: true

Size: 847 Bytes

Versions: 43

Compression:

Stored size: 847 Bytes

Contents

# frozen_string_literal: true

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

43 entries across 43 versions & 2 rubygems

Version Path
solidus_core-2.9.6 app/models/spree/calculator/price_sack.rb
solidus_core-2.8.6 app/models/spree/calculator/price_sack.rb
solidus_core-2.9.5 app/models/spree/calculator/price_sack.rb
solidus_core-2.9.4 app/models/spree/calculator/price_sack.rb
solidus_core-2.6.6 app/models/spree/calculator/price_sack.rb
solidus_core-2.7.4 app/models/spree/calculator/price_sack.rb
solidus_core-2.8.5 app/models/spree/calculator/price_sack.rb
solidus_core-2.9.3 app/models/spree/calculator/price_sack.rb
solidus_core-2.9.2 app/models/spree/calculator/price_sack.rb
solidus_core-2.10.0.beta1 app/models/spree/calculator/price_sack.rb
solidus_core-2.7.3 app/models/spree/calculator/price_sack.rb
solidus_core-2.6.5 app/models/spree/calculator/price_sack.rb
solidus_core-2.9.1 app/models/spree/calculator/price_sack.rb
solidus_core-2.9.0 app/models/spree/calculator/price_sack.rb
solidus_core-2.9.0.rc.1 app/models/spree/calculator/price_sack.rb
solidus_core-2.8.4 app/models/spree/calculator/price_sack.rb
solidus_core-2.8.3 app/models/spree/calculator/price_sack.rb
solidus_core-2.7.2 app/models/spree/calculator/price_sack.rb
solidus_core-2.6.4 app/models/spree/calculator/price_sack.rb
solidus_core-2.8.2 app/models/spree/calculator/price_sack.rb