Class: Spree::Promotion::Rules::NthOrder

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

Instance Method Summary collapse

Methods inherited from Spree::PromotionRule

#actionable?, #eligibility_errors, #preload_relations, #to_partial_path

Instance Method Details

#applicable?(promotable) ⇒ Boolean

This promotion is applicable to orders only.

Returns:

  • (Boolean)


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

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

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

This is never eligible if the order does not have a user, and that user does not have any previous completed orders.

Use the first order rule if you want a promotion to be applied to the first order for a user.

Parameters:

  • order (Spree::Order)

Returns:

  • (Boolean)


21
22
23
24
25
# File 'app/models/spree/promotion/rules/nth_order.rb', line 21

def eligible?(order, _options = {})
  return false unless order.user

  nth_order?(order)
end