Class: Spree::ShippingRate

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

Instance Method Summary collapse

Methods included from DisplayMoney

money_methods

Instance Method Details

#delivery_rangeString

Returns the delivery range for the shipping method

Returns:

  • (String)


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

def delivery_range
  return unless shipping_method.delivery_range

  shipping_method.delivery_range
end

#display_delivery_rangeString

Returns the display delivery range for the shipping method

Returns:

  • (String)


56
57
58
59
60
# File 'app/models/spree/shipping_rate.rb', line 56

def display_delivery_range
  return unless delivery_range

  Spree.t(:display_delivery_range, delivery_range: delivery_range)
end

#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? || !tax_rate.show_rate_in_label

  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 with_free_shipping_promotion? || 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