Class: SpreeCmCommissioner::Promotion::Rules::Date
- Inherits:
-
Spree::PromotionRule
- Object
- Spree::PromotionRule
- SpreeCmCommissioner::Promotion::Rules::Date
- Defined in:
- app/models/spree_cm_commissioner/promotion/rules/date.rb
Direct Known Subclasses
Constant Summary collapse
- MATCH_POLICIES =
%w[any all].freeze
Instance Method Summary collapse
-
#actionable?(line_item) ⇒ Boolean
override.
-
#applicable?(promotable) ⇒ Boolean
override.
- #date_eligible?(_date) ⇒ Boolean
-
#eligible?(order, _options = {}) ⇒ Boolean
override use to check whether promotion is eligible to this rule.
-
#line_item_eligible?(line_item) ⇒ Boolean
line items is considered eligible when any of date range is eligible.
Instance Method Details
#actionable?(line_item) ⇒ Boolean
override
38 39 40 |
# File 'app/models/spree_cm_commissioner/promotion/rules/date.rb', line 38 def actionable?(line_item) line_item_eligible?(line_item) end |
#applicable?(promotable) ⇒ Boolean
override
14 15 16 |
# File 'app/models/spree_cm_commissioner/promotion/rules/date.rb', line 14 def applicable?(promotable) promotable.is_a?(Spree::Order) && promotable.line_items.any?(&:date_present?) end |
#date_eligible?(_date) ⇒ Boolean
42 43 44 |
# File 'app/models/spree_cm_commissioner/promotion/rules/date.rb', line 42 def date_eligible?(_date) raise 'date_eligible? should be implemented in a sub-class of SpreeCmCommissioner::Promotion::Rules::Date' end |
#eligible?(order, _options = {}) ⇒ Boolean
override use to check whether promotion is eligible to this rule
20 21 22 23 24 25 26 27 |
# File 'app/models/spree_cm_commissioner/promotion/rules/date.rb', line 20 def eligible?(order, = {}) case preferred_match_policy when 'any' order.line_items.any? { |item| line_item_eligible?(item) } when 'all' order.line_items.all? { |item| line_item_eligible?(item) } end end |
#line_item_eligible?(line_item) ⇒ Boolean
line items is considered eligible when any of date range is eligible. then, we use action to apply promotion only on eligible dates.
31 32 33 34 35 |
# File 'app/models/spree_cm_commissioner/promotion/rules/date.rb', line 31 def line_item_eligible?(line_item) return false unless line_item.date_present? line_item.date_range.any? { |date| date_eligible?(date) } end |