Class: Spree::Calculator::Shipping::PerItem

Inherits:
ShippingCalculator show all
Defined in:
app/models/spree/calculator/shipping/per_item.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ShippingCalculator

#available?, #compute_shipment

Methods inherited from Spree::Calculator

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



9
10
11
# File 'app/models/spree/calculator/shipping/per_item.rb', line 9

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

Instance Method Details

#compute_from_quantity(quantity) ⇒ Object



17
18
19
# File 'app/models/spree/calculator/shipping/per_item.rb', line 17

def compute_from_quantity(quantity)
  self.preferred_amount * quantity
end

#compute_package(package) ⇒ Object



13
14
15
# File 'app/models/spree/calculator/shipping/per_item.rb', line 13

def compute_package(package)
  compute_from_quantity(package.contents.sum(&:quantity))
end