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