Class: Calculator::PriceBucket

Inherits:
Calculator show all
Defined in:
app/models/calculator/price_bucket.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Calculator

#available?, calculators, #description, #to_s

Class Method Details

.descriptionObject



6
7
8
# File 'app/models/calculator/price_bucket.rb', line 6

def self.description
  I18n.t("price_bucket")
end

.registerObject



10
11
12
13
14
15
# File 'app/models/calculator/price_bucket.rb', line 10

def self.register
  super                                
  Coupon.register_calculator(self)
  ShippingMethod.register_calculator(self)
  ShippingRate.register_calculator(self)
end

Instance Method Details

#compute(object) ⇒ Object

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



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/calculator/price_bucket.rb', line 18

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