Class: Spree::Calculator::FlexiRate

Inherits:
Spree::Calculator show all
Defined in:
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

Methods included from Preferences::Preferable

#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Class Method Details

.available?(_object) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'app/models/spree/calculator/flexi_rate.rb', line 10

def self.available?(_object)
  true
end

Instance Method Details

#compute(object) ⇒ Object



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

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

  return BigDecimal.new(0) if items_count == 0

  additional_items_count = items_count - 1
  preferred_first_item + preferred_additional_item * additional_items_count
end