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

Methods inherited from Spree::Calculator

#available?, calculators, #compute, #description, register, #to_s

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_package(package) ⇒ Object


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

def compute_package(package)
  content_items = package.contents
  item_total = total(content_items)
  value = item_total * BigDecimal(self.preferred_flat_percent.to_s) / 100.0
  (value * 100).round.to_f / 100
end