Class: Spree::Calculator::FlexiRate
Class Method Summary
collapse
Instance Method Summary
collapse
#available?, calculators, #description, register, #to_s
Class Method Details
.available?(object) ⇒ Boolean
16
17
18
|
# File 'app/models/spree/calculator/flexi_rate.rb', line 16
def self.available?(object)
true
end
|
.description ⇒ Object
12
13
14
|
# File 'app/models/spree/calculator/flexi_rate.rb', line 12
def self.description
I18n.t(:flexible_rate)
end
|
Instance Method Details
#compute(object) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/models/spree/calculator/flexi_rate.rb', line 20
def compute(object)
sum = 0
max = self.preferred_max_items.to_i
items_count = object.line_items.map(&:quantity).sum
items_count.times do |i|
if (max == 0 && i == 0) || (max > 0) && (i % max == 0)
sum += self.preferred_first_item.to_f
else
sum += self.preferred_additional_item.to_f
end
end
sum
end
|