Class: Spree::Calculator::PriceSack

Inherits:
Spree::Calculator show all
Defined in:
core/app/models/spree/calculator/price_sack.rb

Instance Method Summary collapse

Methods inherited from Spree::Calculator

#available?, calculators, description, #description, #to_s

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Instance Method Details

#compute(object) ⇒ Object

as object we always get line items, as calculable we have Coupon, ShippingMethod



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'core/app/models/spree/calculator/price_sack.rb', line 13

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 < preferred_minimal_amount
    preferred_normal_amount
  else
    preferred_discount_amount
  end
end