Sha256: aa2fa45ca3456e45b66d3b2891673bad529fc31d68be7f0a450081f11ed28bea

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

require_dependency 'spree/shipping_calculator'

module Spree
  module Calculator::Shipping
    class FlatRate < ShippingCalculator
      preference :amount, :decimal, default: 0
      preference :currency, :string, default: -> { Spree::Store.default.default_currency }

      preference :minimum_item_total, :decimal, default: nil, nullable: true
      preference :maximum_item_total, :decimal, default: nil, nullable: true

      preference :minimum_weight, :decimal, default: nil, nullable: true
      preference :maximum_weight, :decimal, default: nil, nullable: true

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

      def compute_package(package)
        return nil if preferred_minimum_weight.present? && preferred_minimum_weight >= package.weight
        return nil if preferred_maximum_weight.present? && preferred_maximum_weight < package.weight

        return nil if preferred_minimum_item_total.present? && preferred_minimum_item_total >= package.item_total
        return nil if preferred_maximum_item_total.present? && preferred_maximum_item_total < package.item_total

        preferred_amount
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spree_core-4.10.1 app/models/spree/calculator/shipping/flat_rate.rb
spree_core-4.10.0 app/models/spree/calculator/shipping/flat_rate.rb
spree_core-4.9.0 app/models/spree/calculator/shipping/flat_rate.rb