From 8409a47ab8e22dd824733bba44f1de1ccd19209d Mon Sep 17 00:00:00 2001 From: Martijn Date: Mon, 7 Aug 2023 12:17:07 +0200 Subject: [PATCH] fix(picqer): dont publish events if no variants are updated --- packages/vendure-plugin-picqer/package.json | 2 +- .../src/api/picqer.service.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/vendure-plugin-picqer/package.json b/packages/vendure-plugin-picqer/package.json index c40b1fce..4191277c 100644 --- a/packages/vendure-plugin-picqer/package.json +++ b/packages/vendure-plugin-picqer/package.json @@ -1,6 +1,6 @@ { "name": "@pinelab/vendure-plugin-picqer", - "version": "1.0.1", + "version": "1.0.2", "description": "Vendure plugin syncing to orders and stock with Picqer", "author": "Martijn van de Brug ", "homepage": "https://pinelab-plugins.com/", diff --git a/packages/vendure-plugin-picqer/src/api/picqer.service.ts b/packages/vendure-plugin-picqer/src/api/picqer.service.ts index 0ea3f054..f6326776 100644 --- a/packages/vendure-plugin-picqer/src/api/picqer.service.ts +++ b/packages/vendure-plugin-picqer/src/api/picqer.service.ts @@ -511,7 +511,6 @@ export class PicqerService implements OnApplicationBootstrap { picqerProducts.map((p) => p.productcode) ); const stockAdjustments: StockAdjustment[] = []; - let updateCount = 0; // Nr of variants that were updated // Loop over variants to determine new stock level per variant and update in DB await Promise.all( vendureVariants.map(async (variant) => { @@ -567,13 +566,22 @@ export class PicqerService implements OnApplicationBootstrap { productVariant: { id: variant.id }, }) ); - updateCount++; } }) ); + if (!stockAdjustments.length) { + Logger.warn( + `No stock levels updated. This means none of the products in Picqer exist in Vendure yet.`, + loggerCtx + ); + return; + } await this.removeNonPicqerStockLocations(ctx); await this.eventBus.publish(new StockMovementEvent(ctx, stockAdjustments)); - Logger.info(`Updated stock levels of ${updateCount} variants`, loggerCtx); + Logger.info( + `Updated stock levels of ${stockAdjustments.length} variants`, + loggerCtx + ); } /**