@haus-tech/product-import-export-plugin 3.0.15 → 3.0.17
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,8 +603,17 @@ let ProductImporter = class ProductImporter {
|
|
|
603
603
|
}
|
|
604
604
|
const processed = {};
|
|
605
605
|
for (const fieldDef of config) {
|
|
606
|
-
|
|
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];
|
|
614
|
+
if (!value || value === '') {
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
608
617
|
if (fieldDef.list === true) {
|
|
609
618
|
processed[fieldDef.name] = value?.split('|').filter((val) => val.trim() !== '');
|
|
610
619
|
}
|
|
@@ -613,23 +622,22 @@ let ProductImporter = class ProductImporter {
|
|
|
613
622
|
}
|
|
614
623
|
else if (fieldDef.type === 'relation') {
|
|
615
624
|
if (foundCustomFieldType === 'asset') {
|
|
616
|
-
// Asset if of type json
|
|
617
625
|
if ((0, lodash_1.startsWith)(value, '{') || (0, lodash_1.startsWith)(value, '[')) {
|
|
618
626
|
if (typeof value === 'string') {
|
|
619
627
|
const assetValue = JSON.parse(value.replace(/'/g, '"').replace(/\s+/g, ' ').replace(/,\s*'/g, ", '"));
|
|
620
628
|
if (Array.isArray(assetValue)) {
|
|
621
|
-
|
|
629
|
+
for (const asset of assetValue) {
|
|
622
630
|
if (asset.url.startsWith('http://') || asset.url.startsWith('https://')) {
|
|
623
|
-
const createdAssets = await this.assetImporter.getAssets([], ctx);
|
|
631
|
+
const createdAssets = await this.assetImporter.getAssets([asset], ctx);
|
|
624
632
|
processed[fieldDef.name] = createdAssets.assets[0]?.id;
|
|
625
633
|
}
|
|
626
634
|
const foundAsset = this.allAssets.find((a) => a.id === asset.id);
|
|
627
635
|
if (foundAsset && foundAsset.name !== asset.name) {
|
|
628
|
-
this.connection.getRepository(ctx, core_1.Asset).update(foundAsset.id, {
|
|
636
|
+
await this.connection.getRepository(ctx, core_1.Asset).update(foundAsset.id, {
|
|
629
637
|
name: asset.name,
|
|
630
638
|
});
|
|
631
639
|
}
|
|
632
|
-
}
|
|
640
|
+
}
|
|
633
641
|
}
|
|
634
642
|
else {
|
|
635
643
|
if (assetValue.url.startsWith('http://') || assetValue.url.startsWith('https://')) {
|
|
@@ -638,17 +646,15 @@ let ProductImporter = class ProductImporter {
|
|
|
638
646
|
}
|
|
639
647
|
const foundAsset = this.allAssets.find((a) => a.id === assetValue.id);
|
|
640
648
|
if (foundAsset && foundAsset.name !== assetValue.name) {
|
|
641
|
-
this.connection.getRepository(ctx, core_1.Asset).update(foundAsset.id, {
|
|
649
|
+
await this.connection.getRepository(ctx, core_1.Asset).update(foundAsset.id, {
|
|
642
650
|
name: assetValue.name,
|
|
643
651
|
});
|
|
644
652
|
}
|
|
645
653
|
}
|
|
646
654
|
}
|
|
647
|
-
// Asset if of type string
|
|
648
655
|
}
|
|
649
656
|
else {
|
|
650
657
|
if (value.startsWith('http://') || value.startsWith('https://')) {
|
|
651
|
-
// If value is an external URL, we need to import the asset
|
|
652
658
|
const createdAssets = await this.assetImporter.getAssets([{ url: value }], ctx);
|
|
653
659
|
processed[fieldDef.name] = createdAssets.assets[0]?.id;
|
|
654
660
|
}
|
|
@@ -671,7 +677,6 @@ let ProductImporter = class ProductImporter {
|
|
|
671
677
|
}
|
|
672
678
|
}
|
|
673
679
|
else {
|
|
674
|
-
// Default to string
|
|
675
680
|
processed[fieldDef.name] = value ? value : undefined;
|
|
676
681
|
}
|
|
677
682
|
}
|