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.

Fix review issues: nested arrays in reindex, sanitize locale/currency filters

Damian Legawiecf198df072143
diff --git a/spree/core/app/models/spree/search_provider/meilisearch.rb b/spree/core/app/models/spree/search_provider/meilisearch.rb
index 17e9dcada7..6c89dbd327 100644
--- a/spree/core/app/models/spree/search_provider/meilisearch.rb
+++ b/spree/core/app/models/spree/search_provider/meilisearch.rb
@@ -66,7 +66,7 @@ module Spree
def remove(product)
# Delete all locale/currency variants of this product
- filter = "product_id = '#{product.prefixed_id}'"
+ filter = "product_id = '#{sanitize_prefixed_id(product.prefixed_id)}'"
client.index(index_name).delete_documents(filter: filter)
rescue ::Meilisearch::ApiError => e
raise unless e.http_code == 404
@@ -92,7 +92,7 @@ module Spree
.preload(:taxons, :option_types, :primary_media,
variants_including_master: [:prices, :option_values])
.find_in_batches(batch_size: 500) do |batch|
- documents = batch.map { |product| ProductPresenter.new(product, store).call }
+ documents = batch.flat_map { |product| ProductPresenter.new(product, store).call }
index_batch(documents)
end
end
@@ -150,8 +150,8 @@ module Spree
# This mirrors the AR scope: store.products.active(currency) with locale
conditions << "store_ids = '#{store.id}'"
conditions << "status = 'active'"
- conditions << "locale = '#{locale}'"
- conditions << "currency = '#{currency}'"
+ conditions << "locale = '#{locale.to_s.gsub(/[^a-zA-Z_-]/, '')}'"
+ conditions << "currency = '#{currency.to_s.gsub(/[^A-Z]/, '')}'"
conditions << "(discontinue_on = 0 OR discontinue_on > #{Time.current.to_i})"
filters = filters.to_unsafe_h if filters.respond_to?(:to_unsafe_h)
diff --git a/spree/core/app/presenters/spree/search_provider/product_presenter.rb b/spree/core/app/presenters/spree/search_provider/product_presenter.rb
index 4633a1ccc8..3cff8e6fc0 100644
--- a/spree/core/app/presenters/spree/search_provider/product_presenter.rb
+++ b/spree/core/app/presenters/spree/search_provider/product_presenter.rb
@@ -22,8 +22,8 @@ module Spree
end
end
- # Fallback: if no markets, index with store defaults
- if documents.empty?
+ # Fallback: if no markets, index with store defaults (only if product has a price)
+ if documents.empty? && lowest_price(store.default_currency)
documents << build_document(default_locale, store.default_currency, default_locale)
end