Open lukawski opened 1 year ago
When using the Algolia search plugin, only the products index will use the transformer function. I believe it should not be hardcoded and should work for any index.
transformer
Medusa version (including plugins): 1.16.1, Algolia plugin 0.2.20 Node.js version: 20.8.1 Database: PostgreSQL Operating system: macOS 14.1
{ resolve: `medusa-plugin-algolia`, options: { applicationId: process.env.ALGOLIA_APP_ID, adminApiKey: process.env.ALGOLIA_ADMIN_API_KEY, settings: { products: { indexSettings: { searchableAttributes: ['title', 'description', 'material', 'tags'], attributesToRetrieve: ['id', 'title', 'handle', 'thumbnail', 'subtitle', 'tags'], }, transformer: (item) => ({ objectID: item.id, title: item.title, handle: item.handle, thumbnail: item.thumbnail, subtitle: item.subtitle, tags: item.tags, description: item.description, material: item.material, }), }, categories: { indexSettings: { searchableAttributes: ['name', 'description'], attributesToRetrieve: ['id', 'name', 'handle', 'thumbnail'], }, transformer: (item) => { return { objectID: item.id, name: item.name, handle: item.handle, thumbnail: item.thumbnail, description: item.description, }; }, }, }, }, }
ProductCategorySubscriber
ProductCategoryService.Events.CREATED
this.eventBusService_ .subscribe(ProductCategoryService.Events.CREATED, this.handleCategoryCreation)
handleCategoryCreation = async (data) => { const category = await this.productCategoryService_.retrieve(data.id); await this.searchService_.addDocuments( CATEGORY_INDEX_NAME, [this.transformCategory(category)], 'categories', ); };
Transformer defined in the index settings is used and data is correctly transformed and indexed.
I was able to find the cause for this issue and implement a fix. PR: https://github.com/medusajs/medusa/pull/5558.
Bug report
Describe the bug
When using the Algolia search plugin, only the products index will use the
transformer
function. I believe it should not be hardcoded and should work for any index.System information
Medusa version (including plugins): 1.16.1, Algolia plugin 0.2.20 Node.js version: 20.8.1 Database: PostgreSQL Operating system: macOS 14.1
Steps to reproduce the behavior
ProductCategorySubscriber
and subscribe to entity relevant event e.g.ProductCategoryService.Events.CREATED
Expected behavior
Transformer defined in the index settings is used and data is correctly transformed and indexed.
Screenshots