Class: Spree::Calculator::FlexiRate

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

Class Method Summary collapse

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

Class Method Details

.available?(_object) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'core/app/models/spree/calculator/flexi_rate.rb', line 12

def self.available?(_object)
  Spree::Deprecation.warn('Spree::Calculator::FlexiRate::available is DEPRECATED. Use the instance method instead.')
  true
end

Instance Method Details

#compute(object) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'core/app/models/spree/calculator/flexi_rate.rb', line 17

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