Sha256: a0e70d61bf4f2649f8771f56463306d245f64540b4c614a0bf9a600f142add56

Contents?: true

Size: 871 Bytes

Versions: 5

Compression:

Stored size: 871 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 { |element| element.respond_to?(:amount) ? element.amount : BigDecimal(element.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

5 entries across 5 versions & 1 rubygems

Version Path
solidus_core-2.10.5 app/models/spree/calculator/price_sack.rb
solidus_core-2.10.3 app/models/spree/calculator/price_sack.rb
solidus_core-2.10.2 app/models/spree/calculator/price_sack.rb
solidus_core-2.10.1 app/models/spree/calculator/price_sack.rb
solidus_core-2.10.0 app/models/spree/calculator/price_sack.rb