Skip to content

Commit

Permalink
Introduce new filters for the products index
Browse files Browse the repository at this point in the history
  • Loading branch information
rainerdema committed Sep 21, 2023
1 parent 8991b30 commit 5df46bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
19 changes: 13 additions & 6 deletions admin/app/components/solidus_admin/products/index/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,20 @@ def batch_actions
end

def filters
[
Spree::OptionType.all.map do |option_type|
{
name: 'q[with_discarded]',
value: true,
label: t('.filters.with_deleted'),
},
]
presentation: option_type.presentation,
combinator: 'or',
attribute: "variants_option_values",
predicate: "in",
options: option_type.option_values.map do |option_value|
[
option_value.name,
option_value.id
]
end
}
end
end

def columns
Expand Down
10 changes: 9 additions & 1 deletion core/app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,16 @@ def find_or_build_master

alias :options :product_option_types

ransacker :variants_option_values, formatter: proc { |v|
joins(variants_including_master: :option_values)
.where(spree_option_values: { id: v })
.pluck(:id)
} do |parent|
parent.table[:id]
end

self.allowed_ransackable_associations = %w[stores variants_including_master master variants]
self.allowed_ransackable_attributes = %w[name slug]
self.allowed_ransackable_attributes = %w[name slug variants_option_values]
self.allowed_ransackable_scopes = %i[available with_discarded with_all_variant_sku_cont with_kept_variant_sku_cont]

# @return [Boolean] true if there are any variants
Expand Down

0 comments on commit 5df46bf

Please sign in to comment.