From ff37cd190fa455f4ba4f76cfb4d641b1611cc32e Mon Sep 17 00:00:00 2001 From: patpich <825601+patpich@users.noreply.github.com> Date: Fri, 5 May 2023 07:04:56 -0400 Subject: [PATCH] fix(search): add missing default product relations (#4008) * fix(search): add missing default product relations Add missing default product relations for events calling SearchService.addDocuments For the following events: `ProductService.Events.UPDATED, ProductVariantService.Events.CREATED, ProductVariantService.Events.UPDATED]`, `SearchService.addDocuments` will fail due to `product` missing its `variants` relations. The issue can be observed with the Algolia plugin where `reduce` is being attempted on `product.variants`. https://github.com/medusajs/medusa/blob/develop/packages/medusa-plugin-algolia/src/utils/transformer.ts#L14 Implement the same retrieve pattern as `handleProductCreation` method. * chore(changeset): patch --------- Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> --- .changeset/warm-ways-leave.md | 5 +++++ packages/medusa/src/subscribers/product.ts | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .changeset/warm-ways-leave.md diff --git a/.changeset/warm-ways-leave.md b/.changeset/warm-ways-leave.md new file mode 100644 index 0000000000..52d961b974 --- /dev/null +++ b/.changeset/warm-ways-leave.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +fix(search): add missing default product relations diff --git a/packages/medusa/src/subscribers/product.ts b/packages/medusa/src/subscribers/product.ts index 124697088f..c7fb67ffde 100644 --- a/packages/medusa/src/subscribers/product.ts +++ b/packages/medusa/src/subscribers/product.ts @@ -62,7 +62,9 @@ class ProductSearchSubscriber { } handleProductUpdate = async (data) => { - const product = await this.productService_.retrieve(data.id) + const product = await this.productService_.retrieve(data.id, { + relations: defaultSearchIndexingProductRelations, + }) await this.searchService_.addDocuments( ProductService.IndexName, [product], @@ -75,7 +77,9 @@ class ProductSearchSubscriber { } handleProductVariantChange = async (data) => { - const product = await this.productService_.retrieve(data.product_id) + const product = await this.productService_.retrieve(data.product_id, { + relations: defaultSearchIndexingProductRelations, + }) await this.searchService_.addDocuments( ProductService.IndexName, [product],