Skip to content

Commit

Permalink
Merge pull request #558 from Pinelab-studio/feat/picqer-cancellation
Browse files Browse the repository at this point in the history
feat(picqer): allow disabling cancellation of Vendure orders
  • Loading branch information
martijnvdbrug authored Jan 8, 2025
2 parents f7a45f7 + bdc9d10 commit a5f8ce8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/vendure-plugin-picqer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
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": "3.5.0",
"version": "3.6.1",
"description": "Vendure plugin syncing to orders and stock with Picqer",
"author": "Martijn van de Brug <[email protected]>",
"homepage": "https://pinelab-plugins.com/",
Expand Down
6 changes: 5 additions & 1 deletion packages/vendure-plugin-picqer/src/api/picqer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions packages/vendure-plugin-picqer/src/picqer.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -111,6 +118,7 @@ export class PicqerPlugin {
static init(options: PicqerOptions) {
this.options = {
fallBackToProductFeaturedAsset: true,
cancelOrdersOnPicqerCancellation: true,
...options,
};
return PicqerPlugin;
Expand Down
29 changes: 28 additions & 1 deletion packages/vendure-plugin-picqer/test/picqer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IncomingOrderStatusWebhook>;
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: {
Expand Down

0 comments on commit a5f8ce8

Please sign in to comment.