Class: SolidusFriendlyPromotions::Conditions::FirstOrder

Inherits:
SolidusFriendlyPromotions::Condition show all
Includes:
OrderLevelCondition
Defined in:
app/models/solidus_friendly_promotions/conditions/first_order.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OrderLevelCondition

#applicable?, #level

Methods inherited from SolidusFriendlyPromotions::Condition

#applicable?, #eligibility_errors, #level, #preload_relations, #to_partial_path, #updateable?

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



7
8
9
# File 'app/models/solidus_friendly_promotions/conditions/first_order.rb', line 7

def email
  @email
end

#userObject (readonly)

Returns the value of attribute user.



7
8
9
# File 'app/models/solidus_friendly_promotions/conditions/first_order.rb', line 7

def user
  @user
end

Instance Method Details

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

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
# File 'app/models/solidus_friendly_promotions/conditions/first_order.rb', line 9

def eligible?(order, options = {})
  @user = order.try(:user) || options[:user]
  @email = order.email

  if (user || email) && (completed_orders.present? && completed_orders.first != order)
    eligibility_errors.add(:base, eligibility_error_message(:not_first_order), error_code: :not_first_order)
  end

  eligibility_errors.empty?
end