Class: Spree::Calculator::FlexiRate

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

Instance Method Summary collapse

Methods inherited from Spree::Calculator

#available?, #description, description, #to_s

Methods inherited from Base

display_includes

Methods included from Spree::Core::Permalinks

#generate_permalink, #save_permalink

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