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

Inherits:
ShippingCalculator show all
Defined in:
app/models/spree/calculator/shipping/flat_percent_item_total.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, register, #to_s

Methods inherited from Base

page

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


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

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

Instance Method Details

#compute_from_price(price) ⇒ Object


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

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

#compute_package(package) ⇒ Object


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

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