Class: Spree::Calculator::Shipping::FlatPercentItemTotal

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

Instance Method Summary collapse

Methods inherited from ShippingCalculator

#available?, #compute_shipment

Methods inherited from Spree::Calculator

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

#compute_from_price(price) ⇒ Object



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

def compute_from_price(price)
  value = price * BigDecimal(preferred_flat_percent.to_s) / 100.0
  value.round(2)
end

#compute_package(package) ⇒ Object



8
9
10
# File 'app/models/spree/calculator/shipping/flat_percent_item_total.rb', line 8

def compute_package(package)
  compute_from_price(total(package.contents))
end