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, page, spree_base_scopes

Methods included from Preferences::Preferable

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

Instance Method Details

#display_priceObject Also known as: display_cost



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

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



45
46
47
48
49
50
51
# File 'app/models/spree/shipping_rate.rb', line 45

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

#shipping_methodObject



35
36
37
# File 'app/models/spree/shipping_rate.rb', line 35

def shipping_method
  Spree::ShippingMethod.unscoped { super }
end

#tax_amountObject



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

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

#tax_rateObject



39
40
41
# File 'app/models/spree/shipping_rate.rb', line 39

def tax_rate
  Spree::TaxRate.unscoped { super }
end