From c8db51c38a94bb743b14e859d1673a9d2b126ac1 Mon Sep 17 00:00:00 2001 From: VINAY MITTAL Date: Tue, 29 Nov 2016 08:12:49 +0530 Subject: [PATCH] add scope to show only products which are not assemblies --- app/controllers/spree/admin/parts_controller.rb | 2 +- app/models/spree/product_decorator.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) 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