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?

Methods inherited from Spree::Calculator

#available?, #compute, description, #description, #to_s

Methods inherited from Base

display_includes

Methods included from Spree::Core::Permalinks

#generate_permalink, #save_permalink

Instance Method Details

#compute_from_price(price) ⇒ Object



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

def compute_from_price(price)
  price * BigDecimal(preferred_flat_percent.to_s) / 100.0
end

#compute_package(package) ⇒ Object



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

def compute_package(package)
  value = compute_from_price(total(package.contents))
  preferred_currency = package.order.currency
  currency_exponent = ::Money::Currency.find(preferred_currency).exponent
  value.round(currency_exponent)
end