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
Use just `id` column for meilisearch and other search providers in se… (#13853)
Damian Legawiec702364a85d3b
diff --git a/docs/developer/upgrades/5.3-to-5.4.mdx b/docs/developer/upgrades/5.3-to-5.4.mdxindex 052ce0845c..2b1b7be6f2 100644--- a/docs/developer/upgrades/5.3-to-5.4.mdx+++ b/docs/developer/upgrades/5.3-to-5.4.mdx@@ -290,7 +290,7 @@ No data migration is needed — the gem uses the same database tables. All exist### (Optional) Install Spree Posts extension-Posts and Post Categories management were extracted from Spree core into a seperate gem `spree_posts`.+Posts and Post Categories management were extracted from Spree core into a separate gem `spree_posts`.If you use these features before run this command to restore them:diff --git a/spree/core/app/models/spree/search_provider/meilisearch.rb b/spree/core/app/models/spree/search_provider/meilisearch.rbindex c4cd370bf5..cc37326bbb 100644--- a/spree/core/app/models/spree/search_provider/meilisearch.rb+++ b/spree/core/app/models/spree/search_provider/meilisearch.rb@@ -124,7 +124,7 @@ module Spreedef index(product)documents = presenter_class.new(product, store).call- client.index(index_name).add_documents(documents, 'prefixed_id')+ client.index(index_name).add_documents(documents, 'id')enddef remove(product)@@ -132,7 +132,7 @@ module Spreeenddef index_batch(documents)- client.index(index_name).add_documents(documents, 'prefixed_id')+ client.index(index_name).add_documents(documents, 'id')end# Remove all documents for a product by its prefixed_id (e.g. 'prod_abc')diff --git a/spree/core/app/presenters/spree/search_provider/product_presenter.rb b/spree/core/app/presenters/spree/search_provider/product_presenter.rbindex 8349fe74d0..ae9f8e3e07 100644--- a/spree/core/app/presenters/spree/search_provider/product_presenter.rb+++ b/spree/core/app/presenters/spree/search_provider/product_presenter.rb@@ -37,8 +37,8 @@ module Spreedef build_document(locale, currency, fallback_locale){- # Composite ID: product + locale + currency- prefixed_id: "#{product.prefixed_id}_#{locale}_#{currency}",+ # Composite ID: product + locale + currency (Meilisearch primary key)+ id: "#{product.prefixed_id}_#{locale}_#{currency}",product_id: product.prefixed_id,locale: locale.to_s,currency: currency,diff --git a/spree/core/spec/models/spree/search_provider/meilisearch_spec.rb b/spree/core/spec/models/spree/search_provider/meilisearch_spec.rbindex bdbfa702f0..f76472f57c 100644--- a/spree/core/spec/models/spree/search_provider/meilisearch_spec.rb+++ b/spree/core/spec/models/spree/search_provider/meilisearch_spec.rb@@ -140,19 +140,19 @@ module Spreeenddescribe '#index' do- it 'adds documents to Meilisearch index with prefixed_id as primary key' do+ it 'adds documents to Meilisearch index with id as primary key' doexpect(mock_index).to receive(:add_documents).with(array_including(hash_including(product_id: product_1.prefixed_id, name: 'Blue Shirt')),- 'prefixed_id'+ 'id')provider.index(product_1)endit 'uses ProductPresenter to serialize' do- docs = [{ prefixed_id: 'prod_abc_en_USD', product_id: 'prod_abc' }]+ docs = [{ id: 'prod_abc_en_USD', product_id: 'prod_abc' }]presenter = instance_double(SearchProvider::ProductPresenter, call: docs)allow(SearchProvider::ProductPresenter).to receive(:new).with(product_1, store).and_return(presenter)- expect(mock_index).to receive(:add_documents).with(docs, 'prefixed_id')+ expect(mock_index).to receive(:add_documents).with(docs, 'id')provider.index(product_1)endenddiff --git a/spree/core/spec/presenters/spree/search_provider/product_presenter_spec.rb b/spree/core/spec/presenters/spree/search_provider/product_presenter_spec.rbindex 2a57bda0c7..c15385445c 100644--- a/spree/core/spec/presenters/spree/search_provider/product_presenter_spec.rb+++ b/spree/core/spec/presenters/spree/search_provider/product_presenter_spec.rb@@ -17,8 +17,8 @@ module Spreecontext 'document structure' dosubject(:doc) { documents.first }- it 'includes composite prefixed_id and product_id' do- expect(doc[:prefixed_id]).to start_with(product.prefixed_id)+ it 'includes composite id and product_id' do+ expect(doc[:id]).to start_with(product.prefixed_id)expect(doc[:product_id]).to eq(product.prefixed_id)end@@ -112,14 +112,14 @@ module Spreeexpect(eur_doc[:locale]).to eq('de')end- it 'each document has a unique composite prefixed_id' do- ids = documents.map { |d| d[:prefixed_id] }+ it 'each document has a unique composite id' do+ ids = documents.map { |d| d[:id] }expect(ids.uniq.size).to eq(ids.size)end- it 'composite prefixed_id includes product_id, locale, and currency' do+ it 'composite id includes product_id, locale, and currency' dodoc = documents.first- expect(doc[:prefixed_id]).to match(/\A#{product.prefixed_id}_\w+_[A-Z]{3}\z/)+ expect(doc[:id]).to match(/\A#{product.prefixed_id}_\w+_[A-Z]{3}\z/)endit 'includes the price for each currency' do