Sha256: eacafe6ec414a561296e2c39f9e87e1e73e4c7fea61a164b01286b075da52938

Contents?: true

Size: 990 Bytes

Versions: 26

Compression:

Stored size: 990 Bytes

Contents

module Spree
  module Tax
    # Used to build shipping rate taxes
    class ShippingRateTaxer
      include TaxHelpers

      # Build shipping rate taxes for a shipping rate
      # Modifies the passed-in shipping rate with associated shipping rate taxes.
      # @param [Spree::ShippingRate] shipping_rate The shipping rate to add taxes to.
      #   This parameter will be modified.
      # @return [Spree::ShippingRate] The shipping rate with associated tax objects
      def tax(shipping_rate)
        tax_rates_for_shipping_rate(shipping_rate).each do |tax_rate|
          shipping_rate.taxes.build(
            amount: tax_rate.compute_amount(shipping_rate),
            tax_rate: tax_rate
          )
        end
        shipping_rate
      end

      private

      def tax_rates_for_shipping_rate(shipping_rate)
        applicable_rates(shipping_rate.order).select do |tax_rate|
          tax_rate.tax_category == shipping_rate.tax_category
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
solidus_core-2.2.2 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-2.1.1 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-2.0.3 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-1.4.2 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-1.3.2 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-2.0.2 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-1.4.1 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-2.2.1 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-2.2.0 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-2.2.0.rc1 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-2.2.0.beta1 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-2.1.0 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-2.1.0.rc1 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-2.0.1 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-2.1.0.beta1 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-2.0.0 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-1.4.0 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-2.0.0.rc1 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-1.4.0.rc1 app/models/spree/tax/shipping_rate_taxer.rb
solidus_core-2.0.0.beta1 app/models/spree/tax/shipping_rate_taxer.rb