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>
This commit is contained in:
co-authored by
Oliver Windall Juhl
parent
bd53adb238
commit
ff37cd190f
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(search): add missing default product relations
|
||||||
@@ -62,7 +62,9 @@ class ProductSearchSubscriber {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleProductUpdate = async (data) => {
|
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(
|
await this.searchService_.addDocuments(
|
||||||
ProductService.IndexName,
|
ProductService.IndexName,
|
||||||
[product],
|
[product],
|
||||||
@@ -75,7 +77,9 @@ class ProductSearchSubscriber {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleProductVariantChange = async (data) => {
|
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(
|
await this.searchService_.addDocuments(
|
||||||
ProductService.IndexName,
|
ProductService.IndexName,
|
||||||
[product],
|
[product],
|
||||||
|
|||||||
Reference in New Issue
Block a user