Class: SolidusPromotions::Conditions::FirstOrder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OrderLevelCondition

included, #level

Methods inherited from SolidusPromotions::Condition

#applicable?, applicable_to, #eligibility_errors, #eligible?, eligible_method_for, inherited, #level, #preload_relations, #to_partial_path, #updateable?

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



9
10
11
# File 'app/models/solidus_promotions/conditions/first_order.rb', line 9

def email
  @email
end

#userObject (readonly)

Returns the value of attribute user.



9
10
11
# File 'app/models/solidus_promotions/conditions/first_order.rb', line 9

def user
  @user
end

Instance Method Details

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

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
# File 'app/models/solidus_promotions/conditions/first_order.rb', line 11

def order_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