Sha256: 59902524629ad7fb5c75196311de2a7851fbf8bbfbf973c0c222c3bbf63a8aee

Contents?: true

Size: 744 Bytes

Versions: 18

Compression:

Stored size: 744 Bytes

Contents

require_dependency 'spree/calculator'

module Spree
  class Calculator::FlexiRate < Calculator
    preference :first_item,      :decimal, default: 0
    preference :additional_item, :decimal, default: 0
    preference :max_items,       :integer, default: 0
    preference :currency,        :string,  default: ->{ Spree::Config[:currency] }

    def self.available?(_object)
      true
    end

    def compute(object)
      items_count = object.quantity
      items_count = [items_count, preferred_max_items].min unless preferred_max_items.zero?

      return BigDecimal.new(0) if items_count == 0

      additional_items_count = items_count - 1
      preferred_first_item + preferred_additional_item * additional_items_count
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
solidus_core-2.3.1 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.4.1 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.2.2 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.1.1 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.4.0 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.4.0.rc1 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.4.0.beta1 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.3.0 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.3.0.rc3 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.3.0.rc2 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.3.0.rc1 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.3.0.beta1 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.2.1 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.2.0 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.2.0.rc1 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.2.0.beta1 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.1.0 app/models/spree/calculator/flexi_rate.rb
solidus_core-2.1.0.rc1 app/models/spree/calculator/flexi_rate.rb