Class: Spree::Calculator::PercentPerItem
- Inherits:
-
Spree::Calculator
- Object
- ActiveRecord::Base
- Spree::Calculator
- Spree::Calculator::PercentPerItem
- Defined in:
- app/models/spree/calculator/percent_per_item.rb
Overview
A calculator for promotions that calculates a percent-off discount for all matching products in an order. This should not be used as a shipping calculator since it would be the same thing as a flat percent off the entire order.
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Spree::Calculator
#available?, calculators, #description, register, #to_s
Class Method Details
.description ⇒ Object
13 14 15 |
# File 'app/models/spree/calculator/percent_per_item.rb', line 13 def self.description Spree.t(:percent_per_item) end |
Instance Method Details
#compute(object = nil) ⇒ Object
17 18 19 20 21 22 |
# File 'app/models/spree/calculator/percent_per_item.rb', line 17 def compute(object=nil) return 0 if object.nil? object.line_items.reduce(0) do |sum, line_item| sum += value_for_line_item(line_item) end end |