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

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

Overview

A rule to apply to an order greater than (or greater than or equal to) a specific amount

Constant Summary collapse

OPERATORS =
['gt', 'gte']

Instance Method Summary collapse

Methods inherited from Spree::PromotionRule

#actionable?, #eligibility_errors, for, #to_partial_path

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Instance Method Details

#applicable?(promotable) ⇒ Boolean

Returns:

  • (Boolean)


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

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

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

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
# File 'core/app/models/spree/promotion/rules/item_total.rb', line 19

def eligible?(order, _options = {})
  return false unless order.currency == preferred_currency
  item_total = order.item_total
  unless item_total.send(preferred_operator == 'gte' ? :>= : :>, BigDecimal(preferred_amount.to_s))
    eligibility_errors.add(:base, ineligible_message, error_code: ineligible_error_code)
  end

  eligibility_errors.empty?
end