Sha256: 00bbaffaadaa80d39b04ba11628f3c6f22a2a759a7a0e92f4ba22b1b81044114

Contents?: true

Size: 1.16 KB

Versions: 43

Compression:

Stored size: 1.16 KB

Contents

module Spree
  class ShippingRate < Spree::Base
    belongs_to :shipment, class_name: 'Spree::Shipment'
    belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', inverse_of: :shipping_rates
    belongs_to :tax_rate, class_name: 'Spree::TaxRate'

    delegate :order, :currency, to: :shipment
    delegate :name, to: :shipping_method
    delegate :code, to: :shipping_method, prefix: true

    extend Spree::DisplayMoney

    money_methods :base_price, :tax_amount

    def base_price
      cost
    end

    def display_price
      price = display_base_price.to_s

      return price if tax_rate.nil? || tax_amount == 0

      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
    alias_method :display_cost, :display_price

    def tax_amount
      @_tax_amount ||= tax_rate.calculator.compute_shipping_rate(self)
    end

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

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

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
spree_core-3.2.9 app/models/spree/shipping_rate.rb
spree_core-3.1.14 app/models/spree/shipping_rate.rb
spree_core-3.3.6 app/models/spree/shipping_rate.rb
spree_core-3.2.8 app/models/spree/shipping_rate.rb
spree_core-3.1.13 app/models/spree/shipping_rate.rb
spree_core-3.3.5 app/models/spree/shipping_rate.rb
spree_core-3.3.4 app/models/spree/shipping_rate.rb
spree_core-3.2.7 app/models/spree/shipping_rate.rb
spree_core-3.1.12 app/models/spree/shipping_rate.rb
spree_core-3.3.3 app/models/spree/shipping_rate.rb
spree_core-3.2.6 app/models/spree/shipping_rate.rb
spree_core-3.1.11 app/models/spree/shipping_rate.rb
spree_core-3.1.10 app/models/spree/shipping_rate.rb
spree_core-3.3.2 app/models/spree/shipping_rate.rb
spree_core-3.2.5 app/models/spree/shipping_rate.rb
spree_core-3.1.9 app/models/spree/shipping_rate.rb
spree_core-3.3.1 app/models/spree/shipping_rate.rb
spree_core-3.2.4 app/models/spree/shipping_rate.rb
spree_core-3.1.8 app/models/spree/shipping_rate.rb
spree_core-3.3.0 app/models/spree/shipping_rate.rb