Sha256: b82facd4f2452a8bee5274a4433c70bbf686ef4c7269975441d3e508a70a7e62

Contents?: true

Size: 912 Bytes

Versions: 26

Compression:

Stored size: 912 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::Store.default.default_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

26 entries across 26 versions & 1 rubygems

Version Path
spree_core-4.10.1 app/models/spree/calculator/price_sack.rb
spree_core-4.10.0 app/models/spree/calculator/price_sack.rb
spree_core-4.9.0 app/models/spree/calculator/price_sack.rb
spree_core-4.8.3 app/models/spree/calculator/price_sack.rb
spree_core-4.8.2 app/models/spree/calculator/price_sack.rb
spree_core-4.7.3 app/models/spree/calculator/price_sack.rb
spree_core-4.6.6 app/models/spree/calculator/price_sack.rb
spree_core-4.5.5 app/models/spree/calculator/price_sack.rb
spree_core-4.4.1 app/models/spree/calculator/price_sack.rb
spree_core-4.5.4 app/models/spree/calculator/price_sack.rb
spree_core-4.6.5 app/models/spree/calculator/price_sack.rb
spree_core-4.7.2 app/models/spree/calculator/price_sack.rb
spree_core-4.7.1 app/models/spree/calculator/price_sack.rb
spree_core-4.6.4 app/models/spree/calculator/price_sack.rb
spree_core-4.7.0 app/models/spree/calculator/price_sack.rb
spree_core-4.6.3 app/models/spree/calculator/price_sack.rb
spree_core-4.6.2 app/models/spree/calculator/price_sack.rb
spree_core-4.6.1 app/models/spree/calculator/price_sack.rb
spree_core-4.6.0 app/models/spree/calculator/price_sack.rb
spree_core-4.5.3 app/models/spree/calculator/price_sack.rb