Sha256: 12e35655f14e5479b950d572605fc561154ddf00abc10ba91986fbc7108f100d

Contents?: true

Size: 1.07 KB

Versions: 62

Compression:

Stored size: 1.07 KB

Contents

module Workarea
  module Pricing
    class Discount
      module Conditions
        module ItemQuantity
          extend ActiveSupport::Concern

          included do
            # @!attribute item_quantity
            #   @return [Integer] the number to check against
            #
            field :item_quantity, type: Integer, default: 0
            add_qualifier :items_qualify?
          end

          # Whether this discount uses item quantity
          # as a condition.
          #
          # @return [Boolean]
          #
          def item_quantity?
            item_quantity.present? && item_quantity > 0
          end

          # Whether this discount's item quantity passes
          # for this order.
          #
          # @param [Pricing::Discount::Order] order
          # @return [Boolean]
          #
          def items_qualify?(order)
            order.items.any? { |item| item_qualifies?(item) }
          end

          def item_qualifies?(item)
            !item_quantity? || item.quantity >= item_quantity
          end
        end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.26 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.45 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.25 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.23 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.44 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.22 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.43 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.21 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.42 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.20 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.41 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.19 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.40 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.18 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.39 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.17 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.38 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.16 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.37 app/models/workarea/pricing/discount/conditions/item_quantity.rb