diff --git a/packages/vendure-plugin-picqer/CHANGELOG.md b/packages/vendure-plugin-picqer/CHANGELOG.md index 375704b7..2f977b89 100644 --- a/packages/vendure-plugin-picqer/CHANGELOG.md +++ b/packages/vendure-plugin-picqer/CHANGELOG.md @@ -1,3 +1,7 @@ +# 3.6.0 (2025-01-08) + +- Allow configuring the plugin to not cancel Vendure orders when a Picqer order is cancelled + # 3.5.0 (2024-12-19) - Update Vendure to 3.1.1 diff --git a/packages/vendure-plugin-picqer/package.json b/packages/vendure-plugin-picqer/package.json index b9049aac..a82613f9 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": "3.5.0", + "version": "3.6.1", "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 2ff1e785..78983014 100644 --- a/packages/vendure-plugin-picqer/src/api/picqer.service.ts +++ b/packages/vendure-plugin-picqer/src/api/picqer.service.ts @@ -373,7 +373,11 @@ export class PicqerService implements OnApplicationBootstrap { ); return; } - if (data.status === 'cancelled' && order.state !== 'Cancelled') { + if ( + data.status === 'cancelled' && + order.state !== 'Cancelled' && + this.options.cancelOrdersOnPicqerCancellation + ) { const result = await this.orderService.cancelOrder(ctx, { orderId: order.id, reason: 'Cancelled in Picqer', diff --git a/packages/vendure-plugin-picqer/src/picqer.plugin.ts b/packages/vendure-plugin-picqer/src/picqer.plugin.ts index 641f6bbd..1a359987 100644 --- a/packages/vendure-plugin-picqer/src/picqer.plugin.ts +++ b/packages/vendure-plugin-picqer/src/picqer.plugin.ts @@ -76,6 +76,13 @@ export interface PicqerOptions { * Default is `true` */ fallBackToProductFeaturedAsset?: boolean; + /** + * Define wether to cancel orders in Vendure when they are cancelled in Picqer. + * Default is `true` + * + * When, for example, orders in Picqer are cancelled solely because they need to be edited, you might want to disable this feature. + */ + cancelOrdersOnPicqerCancellation?: boolean; } @VendurePlugin({ @@ -111,6 +118,7 @@ export class PicqerPlugin { static init(options: PicqerOptions) { this.options = { fallBackToProductFeaturedAsset: true, + cancelOrdersOnPicqerCancellation: true, ...options, }; return PicqerPlugin; diff --git a/packages/vendure-plugin-picqer/test/picqer.spec.ts b/packages/vendure-plugin-picqer/test/picqer.spec.ts index 884ded3b..34e96c40 100644 --- a/packages/vendure-plugin-picqer/test/picqer.spec.ts +++ b/packages/vendure-plugin-picqer/test/picqer.spec.ts @@ -332,7 +332,34 @@ describe('Order placement', function () { expect(order!.state).toBe('Delivered'); }); - it('Should update to "Canceled" on incoming order status "cancelled"', async () => { + it('Should not update to "Canceled" when "cancelOrdersOnPicqerCancellation = false"', async () => { + PicqerPlugin.options.cancelOrdersOnPicqerCancellation = false; + const mockIncomingWebhook = { + event: 'orders.status_changed', + data: { + reference: createdOrder?.code, + status: 'cancelled', + }, + } as Partial; + await adminClient.fetch( + `http://localhost:3050/picqer/hooks/${E2E_DEFAULT_CHANNEL_TOKEN}`, + { + method: 'POST', + body: JSON.stringify(mockIncomingWebhook), + headers: { + 'X-Picqer-Signature': createSignature( + mockIncomingWebhook, + 'test-api-key' + ), + }, + } + ); + const order = await getOrder(adminClient, createdOrder?.id as string); + expect(order!.state).toBe('Delivered'); + }); + + it('Should update to "Canceled" on incoming order status "cancelled" and "cancelOrdersOnPicqerCancellation = true"', async () => { + PicqerPlugin.options.cancelOrdersOnPicqerCancellation = true; const mockIncomingWebhook = { event: 'orders.status_changed', data: {