Sha256: 86470139ebfa4f280196bd86125d650660c6cb176780d84105cd495ce7bd215c

Contents?: true

Size: 831 Bytes

Versions: 30

Compression:

Stored size: 831 Bytes

Contents

class Calculator::PriceBucket < 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_bucket")
  end

  def self.register
    super
    #Promotion.register_calculator(self)
    ShippingMethod.register_calculator(self)
  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

30 entries across 30 versions & 6 rubygems

Version Path
apispree_core-0.0.0 app/models/calculator/price_bucket.rb
My-Commerce_core-1.1.0 app/models/calculator/price_bucket.rb
My-Commerce_core-1.0.0 app/models/calculator/price_bucket.rb
MyCommerceapi-1.0.0 core/app/models/calculator/price_bucket.rb
MyCommerce-0.0.3 core/app/models/calculator/price_bucket.rb
rfcommerce_core-0.0.3 app/models/calculator/price_bucket.rb
spree_core-0.60.6 app/models/calculator/price_bucket.rb
spree_core-0.60.5 app/models/calculator/price_bucket.rb
spree_core-0.30.2 app/models/calculator/price_bucket.rb
spree_core-0.40.4 app/models/calculator/price_bucket.rb
spree_core-0.50.4 app/models/calculator/price_bucket.rb
spree_core-0.60.4 app/models/calculator/price_bucket.rb
spree_core-0.50.3 app/models/calculator/price_bucket.rb
spree_core-0.60.3 app/models/calculator/price_bucket.rb
spree_core-0.60.2 app/models/calculator/price_bucket.rb
spree_core-0.70.0.rc2 app/models/calculator/price_bucket.rb
spree_core-0.70.RC1 app/models/calculator/price_bucket.rb
spree_core-0.60.1 app/models/calculator/price_bucket.rb
spree_core-0.60.0 app/models/calculator/price_bucket.rb
spree_core-0.60.0.RC1 app/models/calculator/price_bucket.rb