Skip to content

Commit

Permalink
feat(elasticsearch-plugin): Provide the ctx for custom mappings (#2547)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfedr authored Nov 27, 2023
1 parent 1330d68 commit c5d0ea2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -892,12 +892,12 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
};
const variantCustomMappings = Object.entries(this.options.customProductVariantMappings);
for (const [name, def] of variantCustomMappings) {
item[`variant-${name}`] = await def.valueFn(v, languageCode, this.injector);
item[`variant-${name}`] = await def.valueFn(v, languageCode, this.injector, ctx);
}

const productCustomMappings = Object.entries(this.options.customProductMappings);
for (const [name, def] of productCustomMappings) {
item[`product-${name}`] = await def.valueFn(v.product, variants, languageCode, this.injector);
item[`product-${name}`] = await def.valueFn(v.product, variants, languageCode, this.injector, ctx);
}
return item;
} catch (err: any) {
Expand Down Expand Up @@ -971,7 +971,7 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
};
const productCustomMappings = Object.entries(this.options.customProductMappings);
for (const [name, def] of productCustomMappings) {
item[`product-${name}`] = await def.valueFn(product, [], languageCode, this.injector);
item[`product-${name}`] = await def.valueFn(product, [], languageCode, this.injector, ctx);
}
return item;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/elasticsearch-plugin/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
LanguageCode,
Product,
ProductVariant,
RequestContext
} from '@vendure/core';
import deepmerge from 'deepmerge';

Expand Down Expand Up @@ -230,7 +231,7 @@ export interface ElasticsearchOptions {
* ```
*/
customProductMappings?: {
[fieldName: string]: CustomMapping<[Product, ProductVariant[], LanguageCode, Injector]>;
[fieldName: string]: CustomMapping<[Product, ProductVariant[], LanguageCode, Injector, RequestContext]>;
};
/**
* @description
Expand Down Expand Up @@ -260,7 +261,7 @@ export interface ElasticsearchOptions {
* ```
*/
customProductVariantMappings?: {
[fieldName: string]: CustomMapping<[ProductVariant, LanguageCode, Injector]>;
[fieldName: string]: CustomMapping<[ProductVariant, LanguageCode, Injector, RequestContext]>;
};
/**
* @description
Expand Down

0 comments on commit c5d0ea2

Please sign in to comment.