Skip to content

armgit / spree

Public Imported from GitHub
0

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.

CR remarks, change find query

piotrpanko7a9672a5c17b
diff --git a/core/app/finders/spree/products/find.rb b/core/app/finders/spree/products/find.rb
index ae0e124942..dd38c1ee63 100644
--- a/core/app/finders/spree/products/find.rb
+++ b/core/app/finders/spree/products/find.rb
@@ -170,16 +170,15 @@ module Spree
end
def by_properties(products)
- return products unless properties?
+ return products unless properties? && properties.values.reject(&:empty?).present?
- products.
- joins(:product_properties).
- where(spree_product_properties: { value: product_properties_values, property_id: properties.keys }).
- distinct
- end
-
- def product_properties_values
- Spree::ProductProperty.where(id: properties.values.join(',').split(',')).pluck(:value)
+ 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
+ )
end
def option_types_count(option_value_ids)
diff --git a/core/lib/spree/core/search/base.rb b/core/lib/spree/core/search/base.rb
index e256cd30f9..7a9ba70da1 100644
--- a/core/lib/spree/core/search/base.rb
+++ b/core/lib/spree/core/search/base.rb
@@ -137,7 +137,7 @@ module Spree
else
1
end
- @properties[:product_properties] = params[:properties]
+ @properties[:product_properties] = params[:properties].try(:to_unsafe_hash)
end
end
end
diff --git a/frontend/app/helpers/spree/frontend_helper.rb b/frontend/app/helpers/spree/frontend_helper.rb
index ef1bd661e3..669613c228 100644
--- a/frontend/app/helpers/spree/frontend_helper.rb
+++ b/frontend/app/helpers/spree/frontend_helper.rb
@@ -267,7 +267,7 @@ module Spree
end
def available_properties_cache_key
- @available_properties_cache_key ||= Spree::Property.filterable.maximum(:updated_at).utc.to_i
+ @available_properties_cache_key ||= Spree::Property.filterable.maximum(:updated_at)&.utc&.to_i
end
def available_properties