Skip to content

Commit

Permalink
fix: Loop inside channels loop
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Dec 10, 2024
1 parent 5f9afa1 commit 881ad6d
Showing 1 changed file with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 881ad6d

Please sign in to comment.