Class: Spree::ShippingRate

Inherits:
Base
  • Object
show all
Extended by:
DisplayMoney
Defined in:
app/models/spree/shipping_rate.rb

Instance Method Summary collapse

Methods included from DisplayMoney

money_methods

Methods inherited from Base

belongs_to_required_by_default, for_store, has_many_inversing, json_api_columns, json_api_permitted_attributes, json_api_type, page, spree_base_scopes, spree_base_uniqueness_scope

Methods included from Preferences::Preferable

#clear_preferences, #default_preferences, #defined_preferences, #deprecated_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_deprecated, #preference_type, #set_preference

Instance Method Details

#display_priceObject Also known as: display_cost



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/spree/shipping_rate.rb', line 14

def display_price
  price = display_base_price.to_s

  return price if tax_rate.nil? || tax_amount.zero?

  Spree.t(
    tax_rate.included_in_price? ? :including_tax : :excluding_tax,
    scope: 'shipping_rates.display_price',
    price: price,
    tax_amount: display_tax_amount,
    tax_rate_name: tax_rate.name
  )
end

#final_priceObject

returns base price - any available discounts for this Shipment useful when you want to present a list of available shipping rates



36
37
38
39
40
41
42
# File 'app/models/spree/shipping_rate.rb', line 36

def final_price
  if free? || cost < -discount_amount
    BigDecimal(0)
  else
    cost + discount_amount
  end
end

#tax_amountObject



30
31
32
# File 'app/models/spree/shipping_rate.rb', line 30

def tax_amount
  @tax_amount ||= tax_rate&.calculator&.compute_shipping_rate(self) || BigDecimal(0)
end