@haus-tech/product-import-export-plugin 3.0.9 → 3.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,6 +13,7 @@ exports.ProductImporter = void 0;
13
13
  const common_1 = require("@nestjs/common");
14
14
  const core_1 = require("@vendure/core");
15
15
  const rxjs_1 = require("rxjs");
16
+ const generated_types_1 = require("@vendure/common/lib/generated-types");
16
17
  const extended_fast_importer_service_1 = require("../../services/extended-fast-importer.service");
17
18
  const lodash_1 = require("lodash");
18
19
  const normalize_string_1 = require("../../helpers/normalize-string");
@@ -312,12 +313,16 @@ let ProductImporter = class ProductImporter {
312
313
  if (existingProduct && updatingStrategy === 'replace') {
313
314
  await this.fastImporter.removeAllAssetsFromProduct(existingProduct);
314
315
  }
316
+ const getFeaturedAssetId = (product) => {
317
+ if (product?.featuredAsset) {
318
+ const assetIsImage = product.featuredAsset.type === generated_types_1.AssetType.IMAGE;
319
+ return assetIsImage ? product.featuredAsset.id : undefined;
320
+ }
321
+ const firstAsset = productAssets.find((a) => a.type === generated_types_1.AssetType.IMAGE);
322
+ return firstAsset ? firstAsset.id : undefined;
323
+ };
315
324
  const productData = {
316
- featuredAssetId: existingProduct?.featuredAsset
317
- ? undefined
318
- : productAssets.length
319
- ? productAssets[0].id
320
- : undefined,
325
+ featuredAssetId: getFeaturedAssetId(existingProduct),
321
326
  assetIds: productAssets.map((a) => a.id),
322
327
  facetValueIds: updatingStrategy === 'replace' ? [] : undefined,
323
328
  translations: await Promise.all(product.translations.map(async (translation) => {
@@ -440,14 +445,18 @@ let ProductImporter = class ProductImporter {
440
445
  // Remove all assets from the product
441
446
  await this.fastImporter.removeAllAssetsFromVariant(existingVariant);
442
447
  }
448
+ const getFeaturedAssetId = (variant) => {
449
+ if (variant?.featuredAsset) {
450
+ const assetIsImage = variant.featuredAsset.type === generated_types_1.AssetType.IMAGE;
451
+ return assetIsImage ? variant.featuredAsset.id : undefined;
452
+ }
453
+ const firstAsset = variantAssets.find((a) => a.type === generated_types_1.AssetType.IMAGE);
454
+ return firstAsset ? firstAsset.id : undefined;
455
+ };
443
456
  const variantData = {
444
457
  productId: createdProductId,
445
458
  facetValueIds: updatingStrategy === 'replace' ? [] : undefined,
446
- featuredAssetId: existingVariant?.featuredAsset
447
- ? undefined
448
- : variantAssets.length
449
- ? variantAssets[0].id
450
- : undefined,
459
+ featuredAssetId: getFeaturedAssetId(existingVariant),
451
460
  assetIds: variantAssets.map((a) => a.id),
452
461
  sku: variant.sku,
453
462
  taxCategoryId: this.getMatchingTaxCategoryId(variant.taxCategory, taxCategories.items),
@@ -69,6 +69,9 @@ let ExtendedFastImporterService = class ExtendedFastImporterService {
69
69
  if (input.featuredAssetId) {
70
70
  p.featuredAsset = { id: input.featuredAssetId };
71
71
  }
72
+ else {
73
+ (0, lodash_1.set)(p, 'featuredAssetId', null);
74
+ }
72
75
  },
73
76
  });
74
77
  if (input.assetIds) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haus-tech/product-import-export-plugin",
3
- "version": "3.0.9",
3
+ "version": "3.0.10",
4
4
  "description": "A Vendure plugin for importing and exporting products using a CSV file",
5
5
  "author": "Haus Tech",
6
6
  "repository": {