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.

TODO Should be deprecated now that we have adjustments at the line item level in spree core

Instance Method Summary (collapse)

Methods inherited from Spree::Calculator

#available?, calculators, description, #description, register, #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

Instance Method Details

- (Object) compute(object = nil)



13
14
15
16
17
18
# File 'app/models/spree/calculator/percent_per_item.rb', line 13

def compute(object = nil)
  return 0 if object.nil?
  object.line_items.map { |line_item|
    value_for_line_item(line_item)
  }.sum
end