Sha256: 29e80fef6128b2c6c3dd2ccb89544a07f9387315d5aa4ffa0acb272359b3fc6e

Contents?: true

Size: 1.45 KB

Versions: 62

Compression:

Stored size: 1.45 KB

Contents

module Workarea
  module Pricing
    class Discount
      module Conditions
        module OrderTotal
          extend ActiveSupport::Concern
          OPERATORS = %i(greater_than less_than)

          included do
            # @!attribute order_total_operator
            #   @return [Symbol] the operator (from {OPERATORS}).
            #
            field :order_total_operator, type: Symbol, default: OPERATORS.first

            # @!attribute order_total
            #   @return [Money] the amount to compare against
            #
            field :order_total, type: Money

            add_qualifier :order_total_qualifies?
          end

          # Whether this discount has an order total
          # condition.
          #
          # @return [Boolean]
          #
          def order_total?
            order_total.present? && order_total > 0
          end

          # Whether this discount passes its order total
          # conditions.
          #
          # @param [Pricing::Discount::Order] order
          # @return [Boolean]
          #
          def order_total_qualifies?(order)
            return true unless order_total?

            if order_total_operator == :less_than
              order.subtotal_price < order_total
            elsif order_total_operator == :greater_than
              order.subtotal_price > order_total
            else
              false # This shouldn't happen
            end
          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/order_total.rb
workarea-core-3.4.36 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.14 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.35 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.13 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.34 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.12 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.33 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.11 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.10 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.32 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.9 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.31 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.8 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.30 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.7 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.29 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.6 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.28 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.5 app/models/workarea/pricing/discount/conditions/order_total.rb