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

Inherits:
Spree::PromotionRule show all
Defined in:
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

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

Methods included from Spree::Preferences::Preferable

#admin_form_preference_names, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Instance Method Details

#applicable?(promotable) ⇒ Boolean

Returns:

  • (Boolean)


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

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

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

Returns:

  • (Boolean)


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

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

  eligibility_errors.empty?
end