Sha256: 4629e86868a2e3edf0612719bb0d3468ecd4ddb210a6da61e591c2e7365ce2a9

Contents?: true

Size: 825 Bytes

Versions: 20

Compression:

Stored size: 825 Bytes

Contents

require_dependency 'spree/calculator'

module Spree
  class Calculator::FlexiRate < Calculator
    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::Config[:currency] }

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

    def self.available?(_object)
      true
    end

    def compute(object)
      sum = 0
      max = preferred_max_items.to_i
      items_count = object.quantity
      items_count.times do |i|
        if i == 0
          sum += preferred_first_item.to_f
        elsif ((max > 0) && (i <= (max - 1))) || (max == 0)
          sum += preferred_additional_item.to_f
        end
      end

      sum
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
spree_core-3.4.6 app/models/spree/calculator/flexi_rate.rb
spree_core-3.6.6 app/models/spree/calculator/flexi_rate.rb
spree_core-3.6.5 app/models/spree/calculator/flexi_rate.rb
spree_core-3.6.4 app/models/spree/calculator/flexi_rate.rb
spree_core-3.6.3 app/models/spree/calculator/flexi_rate.rb
spree_core-3.6.2 app/models/spree/calculator/flexi_rate.rb
spree_core-3.6.1 app/models/spree/calculator/flexi_rate.rb
spree_core-3.6.0 app/models/spree/calculator/flexi_rate.rb
spree_core-3.5.0 app/models/spree/calculator/flexi_rate.rb
spree_core-3.6.0.rc1 app/models/spree/calculator/flexi_rate.rb
spree_core-3.5.0.rc2 app/models/spree/calculator/flexi_rate.rb
spree_core-3.5.0.rc1 app/models/spree/calculator/flexi_rate.rb
spree_core-3.4.5 app/models/spree/calculator/flexi_rate.rb
spree_core-3.4.4 app/models/spree/calculator/flexi_rate.rb
spree_core-3.4.3 app/models/spree/calculator/flexi_rate.rb
spree_core-3.4.2 app/models/spree/calculator/flexi_rate.rb
spree_core-3.4.1 app/models/spree/calculator/flexi_rate.rb
spree_core-3.4.0 app/models/spree/calculator/flexi_rate.rb
spree_core-3.4.0.rc2 app/models/spree/calculator/flexi_rate.rb
spree_core-3.4.0.rc1 app/models/spree/calculator/flexi_rate.rb