Class: Spree::Calculator::FlexiRate
Class Method Summary
collapse
Instance Method Summary
collapse
#available?, calculators, #description, #to_s
Methods inherited from Base
page, spree_base_scopes
#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Class Method Details
.available?(object) ⇒ Boolean
14
15
16
|
# File 'app/models/spree/calculator/flexi_rate.rb', line 14
def self.available?(object)
true
end
|
.description ⇒ Object
10
11
12
|
# File 'app/models/spree/calculator/flexi_rate.rb', line 10
def self.description
Spree.t(:flexible_rate)
end
|
Instance Method Details
#compute(object) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/models/spree/calculator/flexi_rate.rb', line 18
def compute(object)
sum = 0
max = self.preferred_max_items.to_i
items_count = object.quantity
items_count.times do |i|
if i == 0
sum += self.preferred_first_item.to_f
elsif ((max > 0) && (i <= (max - 1))) || (max == 0)
sum += self.preferred_additional_item.to_f
end
end
sum
end
|