Browse Source

fix(core): Fix search indexing issue when working with multiple channels (#3041)

Relates to #3012.
Hsen Sh 1 year ago
parent
commit
75ed6e12d3

+ 3 - 0
packages/core/src/plugin/default-search-plugin/indexer/indexer.controller.ts

@@ -405,7 +405,9 @@ export class IndexerController {
         await this.removeSyntheticVariants(ctx, variants);
         const productMap = new Map<ID, Product>();
 
+        const originalChannel = ctx.channel;
         for (const variant of variants) {
+            ctx.setChannel(originalChannel);
             let product = productMap.get(variant.productId);
             if (!product) {
                 product = await this.getProductInChannelQueryBuilder(ctx, variant.productId, ctx.channel);
@@ -496,6 +498,7 @@ export class IndexerController {
                 }
             }
         }
+        ctx.setChannel(originalChannel);
 
         await this.queue.push(() =>
             this.connection.getRepository(ctx, SearchIndexItem).save(items, { chunk: 2500 }),