Class: Spree::ShippingRate

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

Instance Method Summary collapse

Methods inherited from Base

page

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

#calculate_tax_amountObject



14
15
16
# File 'app/models/spree/shipping_rate.rb', line 14

def calculate_tax_amount
  tax_rate.calculator.compute_shipping_rate(self)
end

#display_base_priceObject



10
11
12
# File 'app/models/spree/shipping_rate.rb', line 10

def display_base_price
  Spree::Money.new(cost, currency: currency)
end

#display_priceObject Also known as: display_cost



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/spree/shipping_rate.rb', line 18

def display_price
  price = display_base_price.to_s
  if tax_rate
    tax_amount = calculate_tax_amount
    if tax_amount != 0
      if tax_rate.included_in_price?
        if tax_amount > 0
          amount = "#{display_tax_amount(tax_amount)} #{tax_rate.name}"
          price += " (#{Spree.t(:incl)} #{amount})"
        else
          amount = "#{display_tax_amount(tax_amount*-1)} #{tax_rate.name}"
          price += " (#{Spree.t(:excl)} #{amount})"
        end
      else
        amount = "#{display_tax_amount(tax_amount)} #{tax_rate.name}"
        price += " (+ #{amount})"
      end
    end
  end
  price
end

#display_tax_amount(tax_amount) ⇒ Object



41
42
43
# File 'app/models/spree/shipping_rate.rb', line 41

def display_tax_amount(tax_amount)
  Spree::Money.new(tax_amount, currency: currency)
end

#shipping_methodObject



45
46
47
# File 'app/models/spree/shipping_rate.rb', line 45

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

#shipping_method_codeObject



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

def shipping_method_code
  shipping_method.code
end

#tax_rateObject



53
54
55
# File 'app/models/spree/shipping_rate.rb', line 53

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