|
|
@@ -435,66 +435,75 @@ export class IndexerController {
|
|
|
channelIds = unique(channelIds);
|
|
|
|
|
|
for (const channel of variant.channels) {
|
|
|
- ctx.setChannel(channel);
|
|
|
- await this.productPriceApplicator.applyChannelPriceAndTax(variant, ctx);
|
|
|
- const item = new SearchIndexItem({
|
|
|
- channelId: ctx.channelId,
|
|
|
- languageCode,
|
|
|
- productVariantId: variant.id,
|
|
|
- price: variant.price,
|
|
|
- priceWithTax: variant.priceWithTax,
|
|
|
- sku: variant.sku,
|
|
|
- enabled: product.enabled === false ? false : variant.enabled,
|
|
|
- slug: productTranslation?.slug ?? '',
|
|
|
- productId: product.id,
|
|
|
- productName: productTranslation?.name ?? '',
|
|
|
- description: this.constrainDescription(productTranslation?.description ?? ''),
|
|
|
- productVariantName: variantTranslation?.name ?? '',
|
|
|
- productAssetId: product.featuredAsset ? product.featuredAsset.id : null,
|
|
|
- productPreviewFocalPoint: product.featuredAsset
|
|
|
- ? product.featuredAsset.focalPoint
|
|
|
- : null,
|
|
|
- productVariantPreviewFocalPoint: variant.featuredAsset
|
|
|
- ? variant.featuredAsset.focalPoint
|
|
|
- : null,
|
|
|
- productVariantAssetId: variant.featuredAsset ? variant.featuredAsset.id : null,
|
|
|
- productPreview: product.featuredAsset ? product.featuredAsset.preview : '',
|
|
|
- productVariantPreview: variant.featuredAsset ? variant.featuredAsset.preview : '',
|
|
|
- channelIds: channelIds.map(x => x.toString()),
|
|
|
- facetIds: this.getFacetIds(variant, product),
|
|
|
- facetValueIds: this.getFacetValueIds(variant, product),
|
|
|
- collectionIds: variant.collections.map(c => c.id.toString()),
|
|
|
- collectionSlugs:
|
|
|
- collectionTranslations.map(c => c?.slug).filter(notNullOrUndefined) ?? [],
|
|
|
- });
|
|
|
- if (this.options.indexStockStatus) {
|
|
|
- item.inStock =
|
|
|
- 0 < (await this.productVariantService.getSaleableStockLevel(ctx, variant));
|
|
|
- const productInStock = await this.requestContextCache.get(
|
|
|
- ctx,
|
|
|
- `productVariantsStock-${variant.productId}`,
|
|
|
- () =>
|
|
|
- this.connection
|
|
|
- .getRepository(ctx, ProductVariant)
|
|
|
- .find({
|
|
|
- loadEagerRelations: false,
|
|
|
- where: {
|
|
|
- productId: variant.productId,
|
|
|
- deletedAt: IsNull(),
|
|
|
- },
|
|
|
- })
|
|
|
- .then(_variants =>
|
|
|
- Promise.all(
|
|
|
- _variants.map(v =>
|
|
|
- this.productVariantService.getSaleableStockLevel(ctx, v),
|
|
|
+ const availableCurrencyCodes = this.options.indexCurrencyCode
|
|
|
+ ? unique(channel.availableCurrencyCodes)
|
|
|
+ : [channel.defaultCurrencyCode];
|
|
|
+
|
|
|
+ for (const currencyCode of availableCurrencyCodes) {
|
|
|
+ const ch = new Channel({ ...channel, defaultCurrencyCode: currencyCode });
|
|
|
+ ctx.setChannel(ch);
|
|
|
+
|
|
|
+ await this.productPriceApplicator.applyChannelPriceAndTax(variant, ctx);
|
|
|
+ const item = new SearchIndexItem({
|
|
|
+ channelId: ctx.channelId,
|
|
|
+ languageCode,
|
|
|
+ currencyCode,
|
|
|
+ productVariantId: variant.id,
|
|
|
+ price: variant.price,
|
|
|
+ priceWithTax: variant.priceWithTax,
|
|
|
+ sku: variant.sku,
|
|
|
+ enabled: product.enabled === false ? false : variant.enabled,
|
|
|
+ slug: productTranslation?.slug ?? '',
|
|
|
+ productId: product.id,
|
|
|
+ productName: productTranslation?.name ?? '',
|
|
|
+ description: this.constrainDescription(productTranslation?.description ?? ''),
|
|
|
+ productVariantName: variantTranslation?.name ?? '',
|
|
|
+ productAssetId: product.featuredAsset ? product.featuredAsset.id : null,
|
|
|
+ productPreviewFocalPoint: product.featuredAsset
|
|
|
+ ? product.featuredAsset.focalPoint
|
|
|
+ : null,
|
|
|
+ productVariantPreviewFocalPoint: variant.featuredAsset
|
|
|
+ ? variant.featuredAsset.focalPoint
|
|
|
+ : null,
|
|
|
+ productVariantAssetId: variant.featuredAsset ? variant.featuredAsset.id : null,
|
|
|
+ productPreview: product.featuredAsset ? product.featuredAsset.preview : '',
|
|
|
+ productVariantPreview: variant.featuredAsset ? variant.featuredAsset.preview : '',
|
|
|
+ channelIds: channelIds.map(x => x.toString()),
|
|
|
+ facetIds: this.getFacetIds(variant, product),
|
|
|
+ facetValueIds: this.getFacetValueIds(variant, product),
|
|
|
+ collectionIds: variant.collections.map(c => c.id.toString()),
|
|
|
+ collectionSlugs:
|
|
|
+ collectionTranslations.map(c => c?.slug).filter(notNullOrUndefined) ?? [],
|
|
|
+ });
|
|
|
+ if (this.options.indexStockStatus) {
|
|
|
+ item.inStock =
|
|
|
+ 0 < (await this.productVariantService.getSaleableStockLevel(ctx, variant));
|
|
|
+ const productInStock = await this.requestContextCache.get(
|
|
|
+ ctx,
|
|
|
+ `productVariantsStock-${variant.productId}-${ctx.channelId}`,
|
|
|
+ () =>
|
|
|
+ this.connection
|
|
|
+ .getRepository(ctx, ProductVariant)
|
|
|
+ .find({
|
|
|
+ loadEagerRelations: false,
|
|
|
+ where: {
|
|
|
+ productId: variant.productId,
|
|
|
+ deletedAt: IsNull(),
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .then(_variants =>
|
|
|
+ Promise.all(
|
|
|
+ _variants.map(v =>
|
|
|
+ this.productVariantService.getSaleableStockLevel(ctx, v),
|
|
|
+ ),
|
|
|
),
|
|
|
- ),
|
|
|
- )
|
|
|
- .then(stockLevels => stockLevels.some(stockLevel => 0 < stockLevel)),
|
|
|
- );
|
|
|
- item.productInStock = productInStock;
|
|
|
+ )
|
|
|
+ .then(stockLevels => stockLevels.some(stockLevel => 0 < stockLevel)),
|
|
|
+ );
|
|
|
+ item.productInStock = productInStock;
|
|
|
+ }
|
|
|
+ items.push(item);
|
|
|
}
|
|
|
- items.push(item);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -513,6 +522,7 @@ export class IndexerController {
|
|
|
const productTranslation = this.getTranslation(product, ctx.languageCode);
|
|
|
const item = new SearchIndexItem({
|
|
|
channelId: ctx.channelId,
|
|
|
+ currencyCode: ctx.currencyCode,
|
|
|
languageCode: ctx.languageCode,
|
|
|
productVariantId: 0,
|
|
|
price: 0,
|