diff --git a/app/controllers/spree/admin/parts_controller.rb b/app/controllers/spree/admin/parts_controller.rb index 100feb49..1c6ee7c9 100644 --- a/app/controllers/spree/admin/parts_controller.rb +++ b/app/controllers/spree/admin/parts_controller.rb @@ -20,7 +20,7 @@ def available @available_products = [] else query = "%#{params[:q]}%" - @available_products = Spree::Product.search_can_be_part(query) + @available_products = Spree::Product.without_parts.search_can_be_part(query) @available_products.uniq! end respond_to do |format| diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index f683686d..b551c450 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -11,6 +11,8 @@ .limit(30) } + scope :without_parts, -> { eager_load(:assemblies_parts).where("spree_assemblies_parts.assembly_id IS NULL") } + validate :assembly_cannot_be_part, if: :assembly? def variants_or_master