Sha256: cb01170b37a0151151098d906645da2e58f1297eb2c2df0b9a37fd2b55fef574
Contents?: true
Size: 970 Bytes
Versions: 104
Compression:
Stored size: 970 Bytes
Contents
module Spree class Promotion module Rules class FirstOrder < PromotionRule attr_reader :user, :email def applicable?(promotable) promotable.is_a?(Spree::Order) end def eligible?(order, options = {}) @user = order.try(:user) || options[:user] @email = order.email 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 private def completed_orders user ? user.orders.complete : orders_by_email end def orders_by_email Spree::Order.where(email: email).complete end end end end end
Version data entries
104 entries across 104 versions & 3 rubygems