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
Add Product#with_property_values
Damian Legawiec9717e095ad3a
diff --git a/core/app/finders/spree/products/find.rb b/core/app/finders/spree/products/find.rbindex bae1bf476f..496d5a8c16 100644--- a/core/app/finders/spree/products/find.rb+++ b/core/app/finders/spree/products/find.rb@@ -172,20 +172,12 @@ module Spreeproperties.to_unsafe_hash.each do |property_filter_param, product_properties_values|next if property_filter_param.blank? || product_properties_values.empty?- values = product_properties_values.split(',').map(&:parameterize)+ values = product_properties_values.split(',').reject(&:empty?).uniq.map(&:parameterize)next if values.empty?- ids = products.- joins(product_properties: :property).- where(spree_properties: { filter_param: property_filter_param.parameterize }).- where(spree_product_properties: { filter_param: values }).distinct.ids-- if index == 0- product_ids = ids- else- product_ids &= ids- end+ ids = products.with_property_values(property_filter_param, values).ids+ product_ids = index == 0 ? ids : product_ids & idsindex += 1enddiff --git a/core/app/models/concerns/spree/product_scopes.rb b/core/app/models/concerns/spree/product_scopes.rbindex 0b0152033c..510db85940 100644--- a/core/app/models/concerns/spree/product_scopes.rb+++ b/core/app/models/concerns/spree/product_scopes.rb@@ -107,6 +107,12 @@ module Spreewhere(property_conditions(property))end+ add_search_scope :with_property_values do |property_filter_param, property_values|+ joins(product_properties: :property).+ where(Property.table_name => { filter_param: property_filter_param }).+ where(ProductProperty.table_name => { filter_param: property_values })+ end+add_search_scope :with_option do |option|option_types = OptionType.table_nameconditions = case option