Class: Calculator::FlexiRate

Inherits:
Calculator
  • Object
show all
Defined in:
app/models/spree/calculator/flexi_rate.rb

Instance Method Summary collapse

Instance Method Details

#compute(object) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'app/models/spree/calculator/flexi_rate.rb', line 12

def compute(object)
  items_count = object.quantity
  items_count = [items_count, preferred_max_items].min unless preferred_max_items.zero?

  return BigDecimal(0) if items_count == 0

  additional_items_count = items_count - 1
  preferred_first_item + preferred_additional_item * additional_items_count
end