Class: Spree::Promotion::Rules::ItemTotal

Inherits:
Spree::PromotionRule show all
Defined in:
app/models/spree/promotion/rules/item_total.rb

Constant Summary collapse

OPERATORS =
['gt', 'gte']

Instance Method Summary collapse

Methods inherited from Spree::PromotionRule

for

Instance Method Details

#applicable?(promotable) ⇒ Boolean

Returns:

  • (Boolean)

12
13
14
# File 'app/models/spree/promotion/rules/item_total.rb', line 12

def applicable?(promotable)
  promotable.is_a?(Spree::Order)
end

#eligible?(order, options = {}) ⇒ Boolean

Returns:

  • (Boolean)

16
17
18
19
# File 'app/models/spree/promotion/rules/item_total.rb', line 16

def eligible?(order, options = {})
  item_total = order.item_total
  item_total.send(preferred_operator == 'gte' ? :>= : :>, BigDecimal.new(preferred_amount.to_s))
end