Class: Spree::Promotion::Rules::FirstOrder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Spree::PromotionRule

#actionable?, #applicable?, #eligibility_errors, for, #key

Methods included from TypeLabels

#human_description, #human_name

Instance Attribute Details

#email ⇒ Object (readonly)

Returns the value of attribute email.



5
6
7
# File 'app/models/spree/promotion/rules/first_order.rb', line 5

def email
  @email
end

#store ⇒ Object (readonly)

Returns the value of attribute store.



5
6
7
# File 'app/models/spree/promotion/rules/first_order.rb', line 5

def store
  @store
end

#user ⇒ Object (readonly)

Returns the value of attribute user.



5
6
7
# File 'app/models/spree/promotion/rules/first_order.rb', line 5

def user
  @user
end

Instance Method Details

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

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/spree/promotion/rules/first_order.rb', line 7

def eligible?(order, options = {})
  @user = order.try(:customer) || options[:user]
  @email = if options[:email].present?
             order.email = options[:email]
             order.email
           elsif order.email.present?
             order.email
           end
  @store = order.store

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

  eligibility_errors.empty?
end