@haus-tech/product-import-export-plugin 3.0.1 → 3.0.3
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.
|
@@ -43,6 +43,6 @@ export declare class ProductImporter {
|
|
|
43
43
|
*/
|
|
44
44
|
private getMatchingTaxCategoryId;
|
|
45
45
|
private getTranslationByCodeOrFirst;
|
|
46
|
-
getProduct(ctx: RequestContext, id: ID): Promise<Product>;
|
|
47
46
|
createFacetAndValue(facet: ParsedFacet, facetCode: string, valueCode: string): Promise<ID>;
|
|
47
|
+
getProductByIdWithRelations(ctx: RequestContext, id?: ID): Promise<Product | undefined>;
|
|
48
48
|
}
|
|
@@ -207,6 +207,7 @@ let ProductImporter = class ProductImporter {
|
|
|
207
207
|
};
|
|
208
208
|
}
|
|
209
209
|
catch (err) {
|
|
210
|
+
core_1.Logger.error('Error while importing products:', 'ProductImporter', err?.stack);
|
|
210
211
|
return {
|
|
211
212
|
errors: [err.message],
|
|
212
213
|
imported: 0,
|
|
@@ -282,9 +283,7 @@ let ProductImporter = class ProductImporter {
|
|
|
282
283
|
checkExistingProduct = { id: foundVariants[0].productId };
|
|
283
284
|
}
|
|
284
285
|
}
|
|
285
|
-
const existingProduct = checkExistingProduct?.id
|
|
286
|
-
? (await this.getProduct(ctx, checkExistingProduct.id))
|
|
287
|
-
: undefined;
|
|
286
|
+
const existingProduct = await this.getProductByIdWithRelations(ctx, checkExistingProduct?.id);
|
|
288
287
|
try {
|
|
289
288
|
if (existingProduct?.deletedAt) {
|
|
290
289
|
existingProduct.deletedAt = null;
|
|
@@ -293,13 +292,13 @@ let ProductImporter = class ProductImporter {
|
|
|
293
292
|
}
|
|
294
293
|
catch (error) {
|
|
295
294
|
errors.push(`Error while restoring the product: ${error}`);
|
|
296
|
-
|
|
295
|
+
core_1.Logger.error('Error while restoring the product:', 'ProductImporter', error?.stack);
|
|
297
296
|
}
|
|
298
297
|
}
|
|
299
298
|
}
|
|
300
299
|
catch (error) {
|
|
301
300
|
errors.push(`Error while restoring the product: ${error}`);
|
|
302
|
-
|
|
301
|
+
core_1.Logger.error('Error while restoring the product:', 'ProductImporter', error?.stack);
|
|
303
302
|
}
|
|
304
303
|
const existingProductName = existingProduct?.translations.find((t) => t.languageCode === languageCode)?.name;
|
|
305
304
|
const productNameHasChanged = existingProduct && existingProductName !== productMainTranslation.name
|
|
@@ -434,7 +433,7 @@ let ProductImporter = class ProductImporter {
|
|
|
434
433
|
}
|
|
435
434
|
catch (error) {
|
|
436
435
|
errors.push(`Error while restoring the variant: ${error}`);
|
|
437
|
-
|
|
436
|
+
core_1.Logger.error('Error while restoring the variant:', 'ProductImporter', error?.stack);
|
|
438
437
|
}
|
|
439
438
|
}
|
|
440
439
|
if (existingVariant && updatingStrategy === 'replace') {
|
|
@@ -481,7 +480,7 @@ let ProductImporter = class ProductImporter {
|
|
|
481
480
|
}
|
|
482
481
|
}
|
|
483
482
|
if (existingProduct) {
|
|
484
|
-
const productAfterUpdate = (await this.
|
|
483
|
+
const productAfterUpdate = (await this.getProductByIdWithRelations(ctx, createdProductId)); // We know that the product exists, so we can safely cast it to Product
|
|
485
484
|
const existingProductHash = (0, crypto_1.createHash)('md5')
|
|
486
485
|
.update(JSON.stringify((0, remove_update_at_fields_1.removeUpdatedAtFields)(existingProduct)))
|
|
487
486
|
.digest('hex');
|
|
@@ -678,22 +677,6 @@ let ProductImporter = class ProductImporter {
|
|
|
678
677
|
}
|
|
679
678
|
return translation;
|
|
680
679
|
}
|
|
681
|
-
async getProduct(ctx, id) {
|
|
682
|
-
const product = (await this.connection.getRepository(ctx, core_1.Product).findOne({
|
|
683
|
-
where: { id: id },
|
|
684
|
-
relations: [
|
|
685
|
-
'facetValues',
|
|
686
|
-
'facetValues.facet',
|
|
687
|
-
'optionGroups',
|
|
688
|
-
'optionGroups.options',
|
|
689
|
-
'variants',
|
|
690
|
-
'variants.facetValues',
|
|
691
|
-
'assets',
|
|
692
|
-
'featuredAsset',
|
|
693
|
-
],
|
|
694
|
-
}));
|
|
695
|
-
return product;
|
|
696
|
-
}
|
|
697
680
|
async createFacetAndValue(facet, facetCode, valueCode) {
|
|
698
681
|
const facetId = await this.fastImporter.createFacet({
|
|
699
682
|
code: facetCode,
|
|
@@ -718,6 +701,38 @@ let ProductImporter = class ProductImporter {
|
|
|
718
701
|
});
|
|
719
702
|
return facetValueId;
|
|
720
703
|
}
|
|
704
|
+
async getProductByIdWithRelations(ctx, id) {
|
|
705
|
+
if (!id) {
|
|
706
|
+
return undefined;
|
|
707
|
+
}
|
|
708
|
+
const product = (await this.connection.getRepository(ctx, core_1.Product).findOne({
|
|
709
|
+
where: { id },
|
|
710
|
+
withDeleted: true,
|
|
711
|
+
})) ?? undefined;
|
|
712
|
+
if (product) {
|
|
713
|
+
const [facetValues, optionGroups, variants, assets, featuredAsset] = await Promise.all([
|
|
714
|
+
this.connection
|
|
715
|
+
.getRepository(ctx, core_1.FacetValue)
|
|
716
|
+
.find({ where: { products: { id: product.id } }, relations: ['facet'] }),
|
|
717
|
+
this.connection
|
|
718
|
+
.getRepository(ctx, core_1.ProductOptionGroup)
|
|
719
|
+
.find({ where: { product: { id: product.id } }, relations: ['options'] }),
|
|
720
|
+
this.connection
|
|
721
|
+
.getRepository(ctx, core_1.ProductVariant)
|
|
722
|
+
.find({ where: { product: { id: product.id } }, relations: ['facetValues'] }),
|
|
723
|
+
this.connection.getRepository(ctx, core_1.ProductAsset).find({ where: { productId: product.id } }),
|
|
724
|
+
this.connection
|
|
725
|
+
.getRepository(ctx, core_1.Asset)
|
|
726
|
+
.findOne({ where: { id: product.featuredAssetId } }),
|
|
727
|
+
]);
|
|
728
|
+
product.facetValues = facetValues;
|
|
729
|
+
product.optionGroups = optionGroups;
|
|
730
|
+
product.variants = variants;
|
|
731
|
+
product.assets = assets;
|
|
732
|
+
featuredAsset && (product.featuredAsset = featuredAsset);
|
|
733
|
+
}
|
|
734
|
+
return product;
|
|
735
|
+
}
|
|
721
736
|
};
|
|
722
737
|
ProductImporter = __decorate([
|
|
723
738
|
(0, common_1.Injectable)(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haus-tech/product-import-export-plugin",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "A Vendure plugin for importing and exporting products using a CSV file",
|
|
5
5
|
"author": "Haus Tech",
|
|
6
6
|
"repository": {
|
|
@@ -32,4 +32,4 @@
|
|
|
32
32
|
"csv-stringify": "^6.5.1",
|
|
33
33
|
"slug": "^9.1.0"
|
|
34
34
|
}
|
|
35
|
-
}
|
|
35
|
+
}
|