Sha256: cdb544d1abf057986337779e7f2c0f466416bed190122dc111a09c758b0a6b8f

Contents?: true

Size: 659 Bytes

Versions: 19

Compression:

Stored size: 659 Bytes

Contents

module Spree
  class Promotion
    module Rules
      class FirstOrder < PromotionRule
        attr_reader :user, :email

        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

        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

19 entries across 19 versions & 2 rubygems

Version Path
spree_core-2.0.13 app/models/spree/promotion/rules/first_order.rb
spree_core-2.0.12 app/models/spree/promotion/rules/first_order.rb
spree_core-2.0.11 app/models/spree/promotion/rules/first_order.rb
spree_core-2.0.10 app/models/spree/promotion/rules/first_order.rb
spree_core-2.0.9 app/models/spree/promotion/rules/first_order.rb
spree_promo-1.3.5 app/models/spree/promotion/rules/first_order.rb
spree_core-2.0.8 app/models/spree/promotion/rules/first_order.rb
spree_core-2.0.7 app/models/spree/promotion/rules/first_order.rb
spree_core-2.0.6 app/models/spree/promotion/rules/first_order.rb
spree_promo-1.3.4 app/models/spree/promotion/rules/first_order.rb
spree_core-2.0.5 app/models/spree/promotion/rules/first_order.rb
spree_core-2.0.4 app/models/spree/promotion/rules/first_order.rb
spree_promo-1.2.5 app/models/spree/promotion/rules/first_order.rb
spree_promo-1.3.3 app/models/spree/promotion/rules/first_order.rb
spree_core-2.0.3 app/models/spree/promotion/rules/first_order.rb
spree_core-2.0.2 app/models/spree/promotion/rules/first_order.rb
spree_core-2.0.1 app/models/spree/promotion/rules/first_order.rb
spree_core-2.0.0 app/models/spree/promotion/rules/first_order.rb
spree_core-2.0.0.rc1 app/models/spree/promotion/rules/first_order.rb