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 + ); } /**