Sha256: a1819aed1ed5a1e58b0c1bae76120ead9e6522b434f429e0fd63561a3f9e8e47

Contents?: true

Size: 1.01 KB

Versions: 26

Compression:

Stored size: 1.01 KB

Contents

require_dependency 'spree/shipping_calculator'

module Spree
  module Calculator::Shipping
    class FlexiRate < ShippingCalculator
      preference :first_item,      :decimal, default: 0.0
      preference :additional_item, :decimal, default: 0.0
      preference :max_items,       :integer, default: 0
      preference :currency,        :string,  default: -> { Spree::Store.default.default_currency }

      def self.description
        Spree.t(:shipping_flexible_rate)
      end

      def compute_package(package)
        quantity = package.contents.sum(&:quantity)

        compute_from_quantity(quantity)
      end

      delegate :compute_from_quantity, to: :flexi_rate_calculator

      private

      def flexi_rate_calculator
        ::Spree::Calculator::FlexiRate.new(
          preferred_additional_item: preferred_additional_item,
          preferred_first_item: preferred_first_item,
          preferred_max_items: preferred_max_items,
          preferred_currency: preferred_currency
        )
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
spree_core-4.10.1 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.10.0 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.9.0 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.8.3 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.8.2 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.7.3 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.6.6 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.5.5 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.4.1 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.5.4 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.6.5 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.7.2 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.7.1 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.6.4 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.7.0 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.6.3 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.6.2 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.6.1 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.6.0 app/models/spree/calculator/shipping/flexi_rate.rb
spree_core-4.5.3 app/models/spree/calculator/shipping/flexi_rate.rb