Sha256: e88a64c82000f416a5e15e2a8d4c6a7660cf7881116cdb19130c4378ddf4e14b

Contents?: true

Size: 727 Bytes

Versions: 99

Compression:

Stored size: 727 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), error_code: :limit_once_per_user)
            end
          else
            eligibility_errors.add(:base, eligibility_error_message(:no_user_specified), error_code: :no_user_specified)
          end

          eligibility_errors.empty?
        end
      end
    end
  end
end

Version data entries

99 entries across 99 versions & 2 rubygems

Version Path
solidus_legacy_promotions-4.4.2 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_legacy_promotions-4.4.1 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_legacy_promotions-4.4.0 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-4.3.4 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-4.2.4 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-4.1.5 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-4.3.3 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-4.3.2 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-4.1.4 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-4.3.1 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-4.3.0 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-4.2.3 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-4.1.3 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-4.0.4 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-3.4.6 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-4.0.3 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-4.1.2 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-4.2.2 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-3.4.5 app/models/spree/promotion/rules/one_use_per_user.rb
solidus_core-4.2.1 app/models/spree/promotion/rules/one_use_per_user.rb