From 5df46bf78f936ba8d1d314a11591b3df8ed0bfc2 Mon Sep 17 00:00:00 2001 From: Rainer Dema Date: Wed, 20 Sep 2023 14:08:12 +0200 Subject: [PATCH] Introduce new filters for the products index --- .../solidus_admin/products/index/component.rb | 19 +++++++++++++------ core/app/models/spree/product.rb | 10 +++++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/admin/app/components/solidus_admin/products/index/component.rb b/admin/app/components/solidus_admin/products/index/component.rb index 9afc8540922..8a7fd03d15a 100644 --- a/admin/app/components/solidus_admin/products/index/component.rb +++ b/admin/app/components/solidus_admin/products/index/component.rb @@ -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 diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index dffd1b69715..c32a8c81dea 100644 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -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