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

for

Instance Attribute Details

#emailObject (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

#userObject (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

#applicable?(promotable) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'app/models/spree/promotion/rules/first_order.rb', line 7

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

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

Returns:

  • (Boolean)


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

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

  if user || email
    completed_orders.blank? || (completed_orders.first == order)
  else
    false
  end
end