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.27 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.26 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.45 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.25 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.23 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.44 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.22 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.43 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.21 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.42 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.20 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.41 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.19 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.40 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.18 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.39 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.17 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.38 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.5.16 app/models/workarea/pricing/discount/conditions/order_total.rb
workarea-core-3.4.37 app/models/workarea/pricing/discount/conditions/order_total.rb