Sha256: db4df8b4203ac5e010283bb6dbf89d5585b2388d74ba0104d328e6fdd6efb2f3

Contents?: true

Size: 710 Bytes

Versions: 1

Compression:

Stored size: 710 Bytes

Contents

class PaymentCalculator::PriceSack < Calculator
  preference :minimal_amount, :decimal, :default => 0
  preference :normal_amount, :decimal, :default => 0
  preference :discount_amount, :decimal, :default => 0

  def self.description
    I18n.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 : o.to_d }.sum
    else
      base = object.respond_to?(:amount) ? object.amount : object.to_d
    end

    if base >= self.preferred_minimal_amount
      self.preferred_normal_amount
    else
      self.preferred_discount_amount
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spree_payment_calculator-0.70.1 app/model/payment_calculator/price_sack.rb