فهرست منبع

fix(elasticsearch-plugin): Fix search multichannel indexing issue

Relates to #3012
Michael Bromley 1 سال پیش
والد
کامیت
9d6f9cfc09
1فایلهای تغییر یافته به همراه9 افزوده شده و 2 حذف شده
  1. 9 2
      packages/elasticsearch-plugin/src/indexing/indexer.controller.ts

+ 9 - 2
packages/elasticsearch-plugin/src/indexing/indexer.controller.ts

@@ -511,7 +511,6 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
         if (!product) {
             return;
         }
-
         let updatedProductVariants: ProductVariant[] = [];
         try {
             updatedProductVariants = await this.connection.rawConnection.getRepository(ProductVariant).find({
@@ -541,6 +540,7 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
             languageVariants.push(...variant.translations.map(t => t.languageCode));
 
         const uniqueLanguageVariants = unique(languageVariants);
+        const originalChannel = ctx.channel;
         for (const channel of product.channels) {
             ctx.setChannel(channel);
             const variantsInChannel = updatedProductVariants.filter(v =>
@@ -623,6 +623,7 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
                 }
             }
         }
+        ctx.setChannel(originalChannel);
 
         // Because we can have a huge amount of variant for 1 product, we also chunk update operations
         await this.executeBulkOperationsByChunks(
@@ -944,7 +945,13 @@ 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(v.product, variants, languageCode, this.injector, ctx);
+                item[`product-${name}`] = await def.valueFn(
+                    v.product,
+                    variants,
+                    languageCode,
+                    this.injector,
+                    ctx,
+                );
             }
             return item;
         } catch (err: any) {