Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scope to show only products which are not assemblies #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/spree/admin/parts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
2 changes: 2 additions & 0 deletions app/models/spree/product_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down