Sabo
04/19/2023, 1:22 PMmodule 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 itkennyadsl
Spree::Kit
, what is that?Sabo
04/19/2023, 1:39 PMSpree::Product
kennyadsl
display_includes
and available
scopes?Sabo
04/19/2023, 1:42 PMSpree::Kit::Scopes
like for Spree::Product
https://github.com/solidusio/solidus/blob/04a4d68ef9c6957a88e6d66618397754e58367c0/core/app/models/spree/product/scopes.rb#L185Sabo
04/19/2023, 1:48 PMSpree::Kit.display_includes.available
it's working,
>> 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 errorkennyadsl
Spree::Kit
inheriting from Spree::Product
?Sabo
04/19/2023, 2:07 PMSpree:: Base
it's more a kind of clone that a fork I guesskennyadsl
Spree::Kit::Scopes
included in your model?kennyadsl
Sabo
04/19/2023, 2:11 PMmodule 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
Sabo
04/19/2023, 2:19 PM