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
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.rbindex 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 Spreedef 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 => eraise 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)endend@@ -150,8 +150,8 @@ module Spree# This mirrors the AR scope: store.products.active(currency) with localeconditions << "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.rbindex 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 Spreeendend- # 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