From 881ad6d058e8573eba736fcc5918f602efac9c91 Mon Sep 17 00:00:00 2001 From: casperiv <53900565+casperiv0@users.noreply.github.com> Date: Tue, 10 Dec 2024 20:01:13 +0100 Subject: [PATCH] fix: Loop inside channels loop --- .../indexer/indexer.controller.ts | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/core/src/plugin/default-search-plugin/indexer/indexer.controller.ts b/packages/core/src/plugin/default-search-plugin/indexer/indexer.controller.ts index b301156a7b..b31445e9bd 100644 --- a/packages/core/src/plugin/default-search-plugin/indexer/indexer.controller.ts +++ b/packages/core/src/plugin/default-search-plugin/indexer/indexer.controller.ts @@ -417,30 +417,30 @@ export class IndexerController { productMap.set(variant.productId, product); } const availableLanguageCodes = unique(ctx.channel.availableLanguageCodes); - const availableCurrencyCodes = this.options.indexCurrencyCode - ? unique(ctx.channel.availableCurrencyCodes) - : [ctx.channel.defaultCurrencyCode]; - - for (const currencyCode of availableCurrencyCodes) { - for (const languageCode of availableLanguageCodes) { - const productTranslation = this.getTranslation(product, languageCode); - const variantTranslation = this.getTranslation(variant, languageCode); - const collectionTranslations = variant.collections.map(c => - this.getTranslation(c, languageCode), - ); - let channelIds = variant.channels.map(x => x.id); - const clone = new ProductVariant({ id: variant.id }); - await this.entityHydrator.hydrate(ctx, clone, { - relations: ['channels', 'channels.defaultTaxZone'], - }); - channelIds.push( - ...clone.channels - .filter(x => x.availableLanguageCodes.includes(languageCode)) - .map(x => x.id), - ); - channelIds = unique(channelIds); - - for (const channel of variant.channels) { + for (const languageCode of availableLanguageCodes) { + const productTranslation = this.getTranslation(product, languageCode); + const variantTranslation = this.getTranslation(variant, languageCode); + const collectionTranslations = variant.collections.map(c => + this.getTranslation(c, languageCode), + ); + let channelIds = variant.channels.map(x => x.id); + const clone = new ProductVariant({ id: variant.id }); + await this.entityHydrator.hydrate(ctx, clone, { + relations: ['channels', 'channels.defaultTaxZone'], + }); + channelIds.push( + ...clone.channels + .filter(x => x.availableLanguageCodes.includes(languageCode)) + .map(x => x.id), + ); + channelIds = unique(channelIds); + + for (const channel of variant.channels) { + const availableCurrencyCodes = this.options.indexCurrencyCode + ? unique(channel.availableCurrencyCodes) + : [ctx.channel.defaultCurrencyCode]; + + for (const currencyCode of availableCurrencyCodes) { const ch = new Channel({ ...channel, defaultCurrencyCode: currencyCode }); ctx.setChannel(ch);