Sha256: 14ab4e23be7c06cfbd6903112c205d84d9ccada76ee1684541681898caf0fea2

Contents?: true

Size: 1.11 KB

Versions: 15

Compression:

Stored size: 1.11 KB

Contents

require_dependency 'spree/calculator'
# For #to_d method on Ruby 1.8
require 'bigdecimal/util'

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]

    attr_accessible :preferred_minimal_amount,
                    :preferred_normal_amount,
                    :preferred_discount_amount,
                    :preferred_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)
      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 < self.preferred_minimal_amount
        self.preferred_normal_amount
      else
        self.preferred_discount_amount
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
spree_core-2.0.13 app/models/spree/calculator/price_sack.rb
spree_core-2.0.12 app/models/spree/calculator/price_sack.rb
spree_core-2.0.11 app/models/spree/calculator/price_sack.rb
spree_core-2.0.10 app/models/spree/calculator/price_sack.rb
spree_core-2.0.9 app/models/spree/calculator/price_sack.rb
spree_core-2.0.8 app/models/spree/calculator/price_sack.rb
spree_core-2.0.7 app/models/spree/calculator/price_sack.rb
spree_core-2.0.6 app/models/spree/calculator/price_sack.rb
spree_core-2.0.5 app/models/spree/calculator/price_sack.rb
spree_core-2.0.4 app/models/spree/calculator/price_sack.rb
spree_core-2.0.3 app/models/spree/calculator/price_sack.rb
spree_core-2.0.2 app/models/spree/calculator/price_sack.rb
spree_core-2.0.1 app/models/spree/calculator/price_sack.rb
spree_core-2.0.0 app/models/spree/calculator/price_sack.rb
spree_core-2.0.0.rc1 app/models/spree/calculator/price_sack.rb