Skip to content

Commit

Permalink
Merge pull request #238 from Pinelab-studio/fix/picqer-stock-event-pu…
Browse files Browse the repository at this point in the history
…blishing

fix(picqer): Dont publish events if no variants are updated
  • Loading branch information
martijnvdbrug authored Aug 7, 2023
2 parents 1da10d5 + 8409a47 commit 3546220
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 3546220

Please sign in to comment.