@haus-tech/product-import-export-plugin 3.0.15 → 3.0.16

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.
@@ -118,7 +118,7 @@ let ExtendedAssetImporter = class ExtendedAssetImporter {
118
118
  };
119
119
  await this.connection.getRepository(ctx, core_1.Asset).save(assetToUpdate);
120
120
  if (shouldDeleteCreatedAsset) {
121
- this.connection.getRepository(ctx, core_1.Asset).delete(createdAsset.id);
121
+ await this.connection.getRepository(ctx, core_1.Asset).delete(createdAsset.id);
122
122
  }
123
123
  }
124
124
  }
@@ -603,7 +603,13 @@ let ProductImporter = class ProductImporter {
603
603
  }
604
604
  const processed = {};
605
605
  for (const fieldDef of config) {
606
- const foundCustomFieldType = (0, lodash_1.find)(this.customFieldTypes, (_type, key) => key.split(':')[1] === fieldDef.name);
606
+ let foundCustomFieldType = (0, lodash_1.find)(this.customFieldTypes, (_type, key) => key.split(':')[1] === fieldDef.name);
607
+ if (!foundCustomFieldType) {
608
+ // Check if the custom field is an asset
609
+ if (fieldDef.entity === core_1.Asset) {
610
+ foundCustomFieldType = 'asset';
611
+ }
612
+ }
607
613
  const value = customFields[fieldDef.name];
608
614
  if (fieldDef.list === true) {
609
615
  processed[fieldDef.name] = value?.split('|').filter((val) => val.trim() !== '');
@@ -613,23 +619,22 @@ let ProductImporter = class ProductImporter {
613
619
  }
614
620
  else if (fieldDef.type === 'relation') {
615
621
  if (foundCustomFieldType === 'asset') {
616
- // Asset if of type json
617
622
  if ((0, lodash_1.startsWith)(value, '{') || (0, lodash_1.startsWith)(value, '[')) {
618
623
  if (typeof value === 'string') {
619
624
  const assetValue = JSON.parse(value.replace(/'/g, '"').replace(/\s+/g, ' ').replace(/,\s*'/g, ", '"));
620
625
  if (Array.isArray(assetValue)) {
621
- assetValue.forEach(async (asset) => {
626
+ for (const asset of assetValue) {
622
627
  if (asset.url.startsWith('http://') || asset.url.startsWith('https://')) {
623
- const createdAssets = await this.assetImporter.getAssets([], ctx);
628
+ const createdAssets = await this.assetImporter.getAssets([asset], ctx);
624
629
  processed[fieldDef.name] = createdAssets.assets[0]?.id;
625
630
  }
626
631
  const foundAsset = this.allAssets.find((a) => a.id === asset.id);
627
632
  if (foundAsset && foundAsset.name !== asset.name) {
628
- this.connection.getRepository(ctx, core_1.Asset).update(foundAsset.id, {
633
+ await this.connection.getRepository(ctx, core_1.Asset).update(foundAsset.id, {
629
634
  name: asset.name,
630
635
  });
631
636
  }
632
- });
637
+ }
633
638
  }
634
639
  else {
635
640
  if (assetValue.url.startsWith('http://') || assetValue.url.startsWith('https://')) {
@@ -638,17 +643,15 @@ let ProductImporter = class ProductImporter {
638
643
  }
639
644
  const foundAsset = this.allAssets.find((a) => a.id === assetValue.id);
640
645
  if (foundAsset && foundAsset.name !== assetValue.name) {
641
- this.connection.getRepository(ctx, core_1.Asset).update(foundAsset.id, {
646
+ await this.connection.getRepository(ctx, core_1.Asset).update(foundAsset.id, {
642
647
  name: assetValue.name,
643
648
  });
644
649
  }
645
650
  }
646
651
  }
647
- // Asset if of type string
648
652
  }
649
653
  else {
650
654
  if (value.startsWith('http://') || value.startsWith('https://')) {
651
- // If value is an external URL, we need to import the asset
652
655
  const createdAssets = await this.assetImporter.getAssets([{ url: value }], ctx);
653
656
  processed[fieldDef.name] = createdAssets.assets[0]?.id;
654
657
  }
@@ -671,7 +674,6 @@ let ProductImporter = class ProductImporter {
671
674
  }
672
675
  }
673
676
  else {
674
- // Default to string
675
677
  processed[fieldDef.name] = value ? value : undefined;
676
678
  }
677
679
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haus-tech/product-import-export-plugin",
3
- "version": "3.0.15",
3
+ "version": "3.0.16",
4
4
  "description": "A Vendure plugin for importing and exporting products using a CSV file",
5
5
  "author": "Haus Tech",
6
6
  "repository": {