Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fixed filtering by properties with option types and other filters
Damian Legawiec831ee08eba58
diff --git a/core/app/finders/spree/products/find.rb b/core/app/finders/spree/products/find.rbindex dd38c1ee63..39f58b458d 100644--- a/core/app/finders/spree/products/find.rb+++ b/core/app/finders/spree/products/find.rb@@ -172,13 +172,15 @@ module Spreedef by_properties(products)return products unless properties? && properties.values.reject(&:empty?).present?- products.where(- id: properties.map do |property_id, product_properties_ids|- products.- joins(:product_properties).- where(spree_product_properties: { property_id: property_id, id: product_properties_ids.split(',') }).ids- end.flatten.compact.uniq- )+ product_ids = properties.map do |property_id, product_properties_ids|+ next if product_properties_ids.empty?++ products.+ joins(:product_properties).+ where(spree_product_properties: { property_id: property_id, id: product_properties_ids.split(',') }).ids+ end.flatten.compact.uniq++ products.where(id: product_ids)enddef option_types_count(option_value_ids)diff --git a/frontend/app/helpers/spree/frontend_helper.rb b/frontend/app/helpers/spree/frontend_helper.rbindex 669613c228..78c41b92f8 100644--- a/frontend/app/helpers/spree/frontend_helper.rb+++ b/frontend/app/helpers/spree/frontend_helper.rb@@ -246,13 +246,15 @@ module Spreeenddef filtering_params- @filtering_params ||= available_option_types.map(&:filter_param).- concat(available_properties.map { |property| property.name.split.join('-') }).- concat(static_filters)+ @filtering_params ||= available_option_types.map(&:filter_param).concat(static_filters)enddef filtering_params_cache_key@filtering_params_cache_key ||= params.permit(*filtering_params)&.reject { |_, v| v.blank? }&.to_param+ def permitted_products_params+ @permitted_products_params ||= begin+ params.permit(*filtering_params, properties: available_properties.map(&:id).map(&:to_s))+ endenddef available_option_types_cache_keydiff --git a/frontend/app/views/spree/products/index.html.erb b/frontend/app/views/spree/products/index.html.erbindex 241a48b27a..7aad3f6b4f 100644--- a/frontend/app/views/spree/products/index.html.erb+++ b/frontend/app/views/spree/products/index.html.erb@@ -1,4 +1,4 @@-<% permitted_params = params.permit(*filtering_params) %>+<% permitted_params = permitted_products_params %><% products_empty = @products.empty? %><div data-hook="search_results">