Skip to content

Commit

Permalink
fix(picqer): dont publish events if no variants are updated
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnvdbrug committed Aug 7, 2023
1 parent 1da10d5 commit 8409a47
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/vendure-plugin-picqer/package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"homepage": "https://pinelab-plugins.com/",
Expand Down
14 changes: 11 additions & 3 deletions packages/vendure-plugin-picqer/src/api/picqer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
);
}

/**
Expand Down

0 comments on commit 8409a47

Please sign in to comment.