Class: Spree::Calculator::PercentPerItem

Inherits:
Spree::Calculator show all
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, #to_s

Methods inherited from Base

page, spree_base_scopes

Methods included from Preferences::Preferable

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

Class Method Details

.descriptionObject



11
12
13
# File 'app/models/spree/calculator/percent_per_item.rb', line 11

def self.description
  Spree.t(:percent_per_item)
end

Instance Method Details

#compute(object = nil) ⇒ Object



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

def compute(object=nil)
  ActiveSupport::Deprecation.warn(<<-EOS, caller)
    Spree::Calculator::PercentPerItem will be removed in Spree 3.4
    There is now a Promotion Action which deals with these types of promotions instead
  EOS
  return 0 if object.nil?
  object.line_items.reduce(0) do |sum, line_item|
    sum += value_for_line_item(line_item)
  end
end