Sha256: c36f84e5d04b32ce5d9806f4e8649abba649dbe6134536f58a745b5c8b5cd24f

Contents?: true

Size: 661 Bytes

Versions: 34

Compression:

Stored size: 661 Bytes

Contents

# frozen_string_literal: true

module Spree
  class Promotion < Spree::Base
    module Rules
      class OneUsePerUser < PromotionRule
        def applicable?(promotable)
          promotable.is_a?(Spree::Order)
        end

        def eligible?(order, _options = {})
          if order.user.present?
            if promotion.used_by?(order.user, [order])
              eligibility_errors.add(:base, eligibility_error_message(:limit_once_per_user))
            end
          else
            eligibility_errors.add(:base, eligibility_error_message(:no_user_specified))
          end

          eligibility_errors.empty?
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
solidus_core-2.8.6 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-2.6.6 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-2.7.4 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-2.8.5 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-2.7.3 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-2.6.5 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-2.8.4 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-2.8.3 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-2.7.2 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-2.6.4 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-2.8.2 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-2.8.1 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-2.6.3 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-2.8.0 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-2.7.1 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-2.6.2 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core_devise_token_auth-2.8.0.alpha.14 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core_devise_token_auth-2.8.0.alpha.13 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core_devise_token_auth-2.8.0.alpha.12 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core_devise_token_auth-2.8.0.alpha.11 app/models/spree/promotion/rules/one_use_per_user.rb