Sha256: cad8096516b2d1584e3bc31a6d8a47f7d97831485c44b65c7824f449ce7c6c70

Contents?: true

Size: 778 Bytes

Versions: 4

Compression:

Stored size: 778 Bytes

Contents

# frozen_string_literal: true

module SolidusFriendlyPromotions
  module Conditions
    class User < Condition
      include OrderLevelCondition

      has_many :condition_users,
        class_name: "SolidusFriendlyPromotions::ConditionUser",
        foreign_key: :condition_id,
        dependent: :destroy
      has_many :users, through: :condition_users, class_name: Spree::UserClassHandle.new

      def preload_relations
        [:users]
      end

      def eligible?(order, _options = {})
        users.include?(order.user)
      end

      def user_ids_string
        user_ids.join(",")
      end

      def user_ids_string=(user_ids)
        self.user_ids = user_ids.to_s.split(",").map(&:strip)
      end

      def updateable?
        true
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
solidus_friendly_promotions-1.9.3 app/models/solidus_friendly_promotions/conditions/user.rb
solidus_friendly_promotions-1.9.2 app/models/solidus_friendly_promotions/conditions/user.rb
solidus_friendly_promotions-1.9.1 app/models/solidus_friendly_promotions/conditions/user.rb
solidus_friendly_promotions-1.9.0 app/models/solidus_friendly_promotions/conditions/user.rb