Module: Workarea::Pricing::Discount::Conditions::OrderTotal

Extended by:
ActiveSupport::Concern
Included in:
BuySomeGetSome, Workarea::Pricing::Discount::Category, FreeGift, OrderTotal, Product, ProductAttribute, QuantityFixedPrice, Shipping
Defined in:
app/models/workarea/pricing/discount/conditions/order_total.rb

Constant Summary collapse

OPERATORS =
%i(greater_than less_than)

Instance Method Summary collapse

Instance Method Details

#order_total?Boolean

Whether this discount has an order total condition.

Returns:

  • (Boolean)


28
29
30
# File 'app/models/workarea/pricing/discount/conditions/order_total.rb', line 28

def order_total?
  order_total.present? && order_total > 0
end

#order_total_qualifies?(order) ⇒ Boolean

Whether this discount passes its order total conditions.

Parameters:

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/workarea/pricing/discount/conditions/order_total.rb', line 38

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