Hellow, I have a missing scope error ``undefined m...
# support
s
Hellow, I have a missing scope error ``undefined method `available' for #<ActiveRecord::Relation`` app/lib/spree/core/search/kit.rb25in `get_base_scope'
Copy code
module Spree::Core::Search
  class Kit
...        
      def get_base_scope
          base_scope = Spree::Kit.display_includes.available
          base_scope = get_kits_conditions_for(base_scope, @properties[:keywords])
          base_scope = add_search_scopes(base_scope)
          base_scope = add_eagerload_scopes(base_scope)
...
  end
end
From the web console the available method (Spree:Kit:Scopes) is working, but Spree:CoreSearch:Kit doesn't seem to find it
āœ… 1
k
Hey @Sabo, I’m not familiar with
Spree::Kit
, what is that?
s
Ah yes I did not specify, it is a personal model, kind of fork of
Spree::Product
k
and does it have the
display_includes
and
available
scopes?
In the web console I tested
Spree::Kit.display_includes.available
it's working,
Copy code
>> Spree::Kit.display_includes.available
=> #<ActiveRecord::Relation [#<Spree::Kit id: 8, name: "Test 2", count: 0, created_at: "2023-04-11 08:47:52.554441000 +0000", updated_at: "2023-04-12 09:19:21.519562000 +0000", description: "Test 3 4 Test 3 4 ", slug: "test-2", meta_title: "", meta_keywords: [FILTERED], deleted_at: nil, available_on: "2023-04-10 00:00:00.000000000 +0000", discontinue_on: nil, meta_description: "">]>
>> Spree::Kit::Scopes
=> Spree::Kit::Scopes
but from Spree:CoreSearch:Kit (another personal fork of Spree:CoreSearch:Base) there is an undefined method error
k
is
Spree::Kit
inheriting from
Spree::Product
?
s
From
Spree:: Base
it's more a kind of clone that a fork I guess
k
just to be sure, is
Spree::Kit::Scopes
included in your model?
s
Copy code
module Spree
  class Kit < Spree::Base 
	extend FriendlyId
    friendly_id :slug_candidates, use: :history

    include Spree::SoftDeletable
	has_and_belongs_to_many :products
	# have_many_attached :images
	has_many :images, -> { order(:position) }, as: :viewable, dependent: :destroy, class_name: 'Spree::Image'
	
	after_discard do
	  images.destroy_all
	end
	
    after_destroy :punch_slug
    after_discard :punch_slug
		
	validates :name, presence: true, uniqueness: true
	validates :slug, presence: true, uniqueness: { allow_blank: true, case_sensitive: true }
	validates :meta_keywords, length: { maximum: 255 }
    validates :meta_title, length: { maximum: 255 }
	
	#self.whitelisted_ransackable_associations = %w[stores variants_including_master master variants]
    self.whitelisted_ransackable_attributes = %w[name slug]

    def self.ransackable_scopes(_auth_object = nil)
      %i(with_discarded)
    end
    
    def duplicate
      duplicator = KitDuplicator.new(self)
      duplicator.duplicate
    end
    
    def deleted?
      !!deleted_at
    end
    
    # @return [Boolean] true if this idee is discontinued
    def discontinued?
      !!discontinue_on&.past?
    end
    
    # @return [Boolean] true if this idee is available
    def available?
      !deleted? && available_on&.past? && !discontinued?
    end
    
    # @return [Spree::Gallery] the media for a variant
    def gallery
      @gallery ||= Spree::Config.kit_gallery_class.new(self)
    end
    
    private
    
    def slug_candidates
      [
        :name
      ]
    end
    
    def normalize_slug
      self.slug = normalize_friendly_id(slug)
    end

    def punch_slug
      # punch slug with date prefix to allow reuse of original
      update_column :slug, "#{Time.current.to_i}_#{slug}" unless frozen?
    end
  end
end