Class: Spree::Promotion::Rules::FirstOrder
- Inherits:
-
Spree::PromotionRule
- Object
- Base
- Spree::PromotionRule
- Spree::Promotion::Rules::FirstOrder
- Defined in:
- app/models/spree/promotion/rules/first_order.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
Methods inherited from Spree::PromotionRule
#actionable?, #eligibility_errors, #preload_relations, #to_partial_path
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
7 8 9 |
# File 'app/models/spree/promotion/rules/first_order.rb', line 7 def email @email end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
7 8 9 |
# File 'app/models/spree/promotion/rules/first_order.rb', line 7 def user @user end |
Instance Method Details
#applicable?(promotable) ⇒ Boolean
9 10 11 |
# File 'app/models/spree/promotion/rules/first_order.rb', line 9 def applicable?(promotable) promotable.is_a?(Spree::Order) end |
#eligible?(order, options = {}) ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/spree/promotion/rules/first_order.rb', line 13 def eligible?(order, = {}) @user = order.try(:user) || [:user] @email = order.email if (user || email) && (completed_orders.present? && completed_orders.first != order) eligibility_errors.add(:base, (:not_first_order), error_code: :not_first_order) end eligibility_errors.empty? end |