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.15 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.36 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.14 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.35 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.13 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.34 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.12 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.33 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.11 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.10 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.32 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.9 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.31 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.8 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.30 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.7 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.29 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.6 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.4.28 app/models/workarea/pricing/discount/conditions/item_quantity.rb
workarea-core-3.5.5 app/models/workarea/pricing/discount/conditions/item_quantity.rb