@haus-tech/product-import-export-plugin 3.0.14 → 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.
- package/dist/providers/import-providers/asset-importer.js +1 -1
- package/dist/providers/import-providers/import-parser.d.ts +1 -1
- package/dist/providers/import-providers/import-parser.js +1 -1
- package/dist/providers/import-providers/product-importer.js +13 -11
- package/dist/services/extended-fast-importer.service.js +5 -5
- package/package.json +1 -1
|
@@ -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
|
}
|
|
@@ -374,7 +374,7 @@ let ImportParser = class ImportParser {
|
|
|
374
374
|
const jsonAssets = parseAssetsIfJson(r.variantAssets);
|
|
375
375
|
const parsedVariant = {
|
|
376
376
|
sku: parseString(r.sku),
|
|
377
|
-
price: parseNumber(r.price),
|
|
377
|
+
price: r.price ? parseNumber(r.price) : undefined,
|
|
378
378
|
taxCategory: parseString(r.taxCategory),
|
|
379
379
|
stockOnHand: parseNumber(r.stockOnHand),
|
|
380
380
|
trackInventory: r.trackInventory == null || r.trackInventory === ''
|
|
@@ -475,7 +475,7 @@ let ProductImporter = class ProductImporter {
|
|
|
475
475
|
customFields: await this.processCustomFieldValues(translation.customFields, this.configService.customFields.ProductVariant, ctx),
|
|
476
476
|
};
|
|
477
477
|
})),
|
|
478
|
-
price: Math.round(variant.price * 100),
|
|
478
|
+
price: (0, lodash_1.isUndefined)(variant.price) ? undefined : Math.round(variant.price * 100),
|
|
479
479
|
customFields: variantCustomFields,
|
|
480
480
|
};
|
|
481
481
|
const createdVariantId = existingVariant
|
|
@@ -603,7 +603,13 @@ 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];
|
|
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
|
-
|
|
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
|
}
|
|
@@ -349,9 +349,6 @@ let ExtendedFastImporterService = class ExtendedFastImporterService {
|
|
|
349
349
|
if (!input.optionIds) {
|
|
350
350
|
input.optionIds = [];
|
|
351
351
|
}
|
|
352
|
-
if (input.price == null) {
|
|
353
|
-
input.price = 0;
|
|
354
|
-
}
|
|
355
352
|
const inputWithoutPrice = {
|
|
356
353
|
...input,
|
|
357
354
|
};
|
|
@@ -409,7 +406,7 @@ let ExtendedFastImporterService = class ExtendedFastImporterService {
|
|
|
409
406
|
p.currencyCode === this.importCtx.channel.defaultCurrencyCode);
|
|
410
407
|
if (!existingVariantPrice) {
|
|
411
408
|
const variantPrice = new core_1.ProductVariantPrice({
|
|
412
|
-
price: input.price,
|
|
409
|
+
price: (0, lodash_1.isNumber)(input.price) ? input.price : 0,
|
|
413
410
|
channelId,
|
|
414
411
|
currencyCode: this.importCtx.channel.defaultCurrencyCode,
|
|
415
412
|
});
|
|
@@ -419,6 +416,9 @@ let ExtendedFastImporterService = class ExtendedFastImporterService {
|
|
|
419
416
|
.save(variantPrice, { reload: false });
|
|
420
417
|
}
|
|
421
418
|
else {
|
|
419
|
+
if ((0, lodash_1.isUndefined)(input.price)) {
|
|
420
|
+
input.price = existingVariantPrice.price;
|
|
421
|
+
}
|
|
422
422
|
existingVariantPrice.price = input.price;
|
|
423
423
|
await this.connection.rawConnection
|
|
424
424
|
.getRepository(core_1.ProductVariantPrice)
|
|
@@ -474,7 +474,7 @@ let ExtendedFastImporterService = class ExtendedFastImporterService {
|
|
|
474
474
|
const assignedChannelIds = (0, unique_1.unique)([this.defaultChannel, this.importCtx.channel], 'id').map((c) => c.id);
|
|
475
475
|
for (const channelId of assignedChannelIds) {
|
|
476
476
|
const variantPrice = new core_1.ProductVariantPrice({
|
|
477
|
-
price: input.price,
|
|
477
|
+
price: (0, lodash_1.isNumber)(input.price) ? input.price : 0,
|
|
478
478
|
channelId,
|
|
479
479
|
currencyCode: this.importCtx.channel.defaultCurrencyCode,
|
|
480
480
|
});
|