Skip to content

Commit 36a8917

Browse files
Add Shopware actions for order management (#18874)
* Add Shopware actions for order management - Implemented actions to create, retrieve, list, update orders, and manage payment and shipping methods. - Introduced utility functions for parsing objects and constants for pagination limits. - Enhanced prop definitions in the Shopware app for better integration and usability. * Bump Shopware component version to 0.1.0 and add dependency on @pipedream/platform * pnpm update * Fix currency factor parsing in create-order action and update description and variable names in update-order action for clarity. * Update components/shopware/actions/update-order/update-order.mjs Co-authored-by: michelle0927 <[email protected]> * Update descriptions for item and total rounding in create-order action to include examples for better clarity. --------- Co-authored-by: michelle0927 <[email protected]>
1 parent b3cd11c commit 36a8917

File tree

11 files changed

+792
-24
lines changed

11 files changed

+792
-24
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { parseObject } from "../../common/utils.mjs";
2+
import shopware from "../../shopware.app.mjs";
3+
4+
export default {
5+
key: "shopware-create-order",
6+
name: "Create Order",
7+
description: "Create a new order. [See the documentation](https://shopware.stoplight.io/docs/admin-api/52ce9936f6ea4-create-a-new-order-resources)",
8+
version: "0.0.1",
9+
type: "action",
10+
annotations: {
11+
destructiveHint: false,
12+
openWorldHint: true,
13+
readOnlyHint: true,
14+
},
15+
props: {
16+
shopware,
17+
billingAddressId: {
18+
propDefinition: [
19+
shopware,
20+
"customerAddressId",
21+
],
22+
label: "Billing Address ID",
23+
description: "The ID of the billing address to use for the order",
24+
},
25+
currencyId: {
26+
propDefinition: [
27+
shopware,
28+
"currencyId",
29+
],
30+
},
31+
salesChannelId: {
32+
propDefinition: [
33+
shopware,
34+
"salesChannelId",
35+
],
36+
},
37+
stateId: {
38+
propDefinition: [
39+
shopware,
40+
"stateId",
41+
() => ({
42+
type: "order.state",
43+
}),
44+
],
45+
},
46+
orderDateTime: {
47+
type: "string",
48+
label: "Order Date Time",
49+
description: "The date and time the order was created",
50+
},
51+
priceObject: {
52+
type: "object",
53+
label: "Price Object",
54+
description: "Price object to use for the order. Example: `{ \"netPrice\": 1.00, \"totalPrice\": 1.00, \"positionPrice\": 1.00, \"rawTotal\": 1.00, \"taxStatus\": \"Free\", \"calculatedTaxes\": {}, \"taxRules\": {} }` [See the documentation](https://shopware.stoplight.io/docs/admin-api/52ce9936f6ea4-create-a-new-order-resources) for more information.",
55+
},
56+
shippingCostsObject: {
57+
type: "object",
58+
label: "Shipping Costs Object",
59+
description: "Shipping costs object to use for the order. Example: `{ \"unitPrice\": 1.00, \"totalPrice\": 1.00, \"quantity\": 1, \"calculatedTaxes\": {}, \"taxRules\": {} }` [See the documentation](https://shopware.stoplight.io/docs/admin-api/52ce9936f6ea4-create-a-new-order-resources) for more information.",
60+
},
61+
currencyObject: {
62+
type: "object",
63+
label: "Currency Object",
64+
description: "Currency object to use for the order. Example: `{ \"factor\": 1.0, \"symbol\": \"€\", \"isoCode\": \"EUR\", \"itemRounding\": { \"decimals\": 2, \"interval\": 1.0, \"roundForNet\": true }, \"totalRounding\": { \"decimals\": 2, \"interval\": 1.0, \"roundForNet\": true } }` [See the documentation](https://shopware.stoplight.io/docs/admin-api/52ce9936f6ea4-create-a-new-order-resources) for more information.",
65+
},
66+
currencyFactor: {
67+
type: "string",
68+
label: "Currency Factor",
69+
description: "Rate at which currency is exchanged",
70+
},
71+
itemRounding: {
72+
type: "object",
73+
label: "Item Rounding",
74+
description: "The rounding method to use for the order items. Example: {\"extensions\":[],\"decimals\":2,\"interval\":0.01,\"roundForNet\":true}",
75+
},
76+
totalRounding: {
77+
type: "object",
78+
label: "Total Rounding",
79+
description: "The rounding method to use for the order total. Example: {\"extensions\":[],\"decimals\":2,\"interval\":0.01,\"roundForNet\":true}",
80+
},
81+
},
82+
async run({ $ }) {
83+
const { data } = await this.shopware.createOrder({
84+
$,
85+
params: {
86+
_response: "json",
87+
},
88+
data: {
89+
billingAddressId: this.billingAddressId,
90+
currencyId: this.currencyId,
91+
salesChannelId: this.salesChannelId,
92+
stateId: this.stateId,
93+
orderDateTime: this.orderDateTime,
94+
price: parseObject(this.priceObject),
95+
shippingCosts: parseObject(this.shippingCostsObject),
96+
currencyFactor: this.currencyFactor && parseFloat(this.currencyFactor),
97+
currency: parseObject(this.currency),
98+
itemRounding: parseObject(this.itemRounding),
99+
totalRounding: parseObject(this.totalRounding),
100+
},
101+
});
102+
103+
$.export("$summary", `Successfully created order with ID: ${data.id}`);
104+
return data;
105+
},
106+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import shopware from "../../shopware.app.mjs";
2+
3+
export default {
4+
key: "shopware-get-order",
5+
name: "Get Order",
6+
description: "Get an order by ID. [See the documentation](https://shopware.stoplight.io/docs/admin-api/0b7d9d489b841-search-for-the-order-resources)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
shopware,
16+
orderId: {
17+
propDefinition: [
18+
shopware,
19+
"orderId",
20+
],
21+
},
22+
},
23+
async run({ $ }) {
24+
const { data } = await this.shopware.getOrder({
25+
$,
26+
orderId: this.orderId,
27+
});
28+
29+
$.export("$summary", `Successfully retrieved order with ID: ${data.id}`);
30+
return data;
31+
},
32+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import shopware from "../../shopware.app.mjs";
2+
3+
export default {
4+
key: "shopware-list-orders",
5+
name: "List Orders",
6+
description: "List all orders. [See the documentation](https://shopware.stoplight.io/docs/admin-api/f95b395c5ae73-list-with-basic-information-of-order-resources)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
shopware,
16+
maxResults: {
17+
type: "integer",
18+
label: "Max Results",
19+
description: "The maximum number of orders to return",
20+
default: 100,
21+
optional: true,
22+
},
23+
},
24+
async run({ $ }) {
25+
const orders = this.shopware.paginate({
26+
$,
27+
fn: this.shopware.listOrders,
28+
maxResults: this.maxResults,
29+
});
30+
31+
const data = [];
32+
for await (const order of orders) {
33+
data.push(order);
34+
}
35+
$.export("$summary", `Successfully retrieved ${data.length} orders`);
36+
return data;
37+
},
38+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import shopware from "../../shopware.app.mjs";
2+
3+
export default {
4+
key: "shopware-list-payment-methods",
5+
name: "List Payment Methods",
6+
description: "List all payment methods. [See the documentation](https://shopware.stoplight.io/docs/admin-api/0ffc5a34d40e4-list-with-basic-information-of-payment-method-resources)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
shopware,
16+
maxResults: {
17+
type: "integer",
18+
label: "Max Results",
19+
description: "The maximum number of payment methods to return",
20+
default: 100,
21+
optional: true,
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = this.shopware.paginate({
26+
$,
27+
fn: this.shopware.listPaymentMethods,
28+
maxResults: this.maxResults,
29+
});
30+
31+
const data = [];
32+
for await (const paymentMethod of response) {
33+
data.push(paymentMethod);
34+
}
35+
36+
$.export("$summary", `Successfully retrieved ${data.length} payment methods`);
37+
return data;
38+
},
39+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import shopware from "../../shopware.app.mjs";
2+
3+
export default {
4+
key: "shopware-list-shipping-methods",
5+
name: "List Shipping Methods",
6+
description: "List all shipping methods. [See the documentation](https://shopware.stoplight.io/docs/admin-api/7d33c6b3c151d-list-with-basic-information-of-shipping-method-resources)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
shopware,
16+
maxResults: {
17+
type: "integer",
18+
label: "Max Results",
19+
description: "The maximum number of shipping methods to return",
20+
default: 100,
21+
optional: true,
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = this.shopware.paginate({
26+
$,
27+
fn: this.shopware.listShippingMethods,
28+
maxResults: this.maxResults,
29+
});
30+
31+
const data = [];
32+
for await (const shippingMethod of response) {
33+
data.push(shippingMethod);
34+
}
35+
36+
$.export("$summary", `Successfully retrieved ${data.length} shipping methods`);
37+
return data;
38+
},
39+
};
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { parseObject } from "../../common/utils.mjs";
2+
import shopware from "../../shopware.app.mjs";
3+
4+
export default {
5+
key: "shopware-update-order",
6+
name: "Update Order",
7+
description: "Partially update information about an order resource. [See the documentation](https://shopware.stoplight.io/docs/admin-api/3cc867261ff28-partially-update-information-about-a-order-resource)",
8+
version: "0.0.1",
9+
type: "action",
10+
annotations: {
11+
destructiveHint: false,
12+
openWorldHint: true,
13+
readOnlyHint: true,
14+
},
15+
props: {
16+
shopware,
17+
orderId: {
18+
propDefinition: [
19+
shopware,
20+
"orderId",
21+
],
22+
},
23+
tagIds: {
24+
propDefinition: [
25+
shopware,
26+
"tagIds",
27+
],
28+
withLabel: true,
29+
optional: true,
30+
},
31+
ruleIds: {
32+
propDefinition: [
33+
shopware,
34+
"ruleIds",
35+
],
36+
optional: true,
37+
},
38+
orderNumber: {
39+
type: "string",
40+
label: "Order Number",
41+
description: "Unique number associated with every order",
42+
optional: true,
43+
},
44+
affiliateCode: {
45+
type: "string",
46+
label: "Affiliate Code",
47+
description: "An affiliate code is an identification option with which website operators can mark outgoing links",
48+
optional: true,
49+
},
50+
campaignCode: {
51+
type: "string",
52+
label: "Campaign Code",
53+
description: "A campaign code is the globally unique identifier for a campaign",
54+
optional: true,
55+
},
56+
customerComment: {
57+
type: "string",
58+
label: "Customer Comment",
59+
description: "Comments given by the customer",
60+
optional: true,
61+
},
62+
internalComment: {
63+
type: "string",
64+
label: "Internal Comment",
65+
description: "Comments given by the internal user",
66+
optional: true,
67+
},
68+
},
69+
async run({ $ }) {
70+
const { data } = await this.shopware.updateOrder({
71+
$,
72+
orderId: this.orderId,
73+
params: {
74+
_response: "json",
75+
},
76+
data: {
77+
tags: parseObject(this.tagIds)?.map(({
78+
value, label,
79+
}) => ({
80+
id: value,
81+
name: label,
82+
})),
83+
ruleIds: parseObject(this.ruleIds),
84+
orderNumber: this.orderNumber,
85+
affiliateCode: this.affiliateCode,
86+
campaignCode: this.campaignCode,
87+
customerComment: this.customerComment,
88+
internalComment: this.internalComment,
89+
},
90+
});
91+
92+
$.export("$summary", `Successfully updated order with ID: ${this.orderId}`);
93+
return data;
94+
},
95+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const LIMIT = 100;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

0 commit comments

Comments
 (0)