Skip to content

Commit 52ec33f

Browse files
committed
Add statusId prop definition to create-order action and implement getOrderStatuses method in PlentyONE component. Enhanced order creation by parsing order items and related properties for improved data handling.
1 parent 313365e commit 52ec33f

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

components/plentyone/actions/create-order/create-order.mjs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
LOCK_STATUS_OPTIONS,
44
ORDER_TYPE_OPTIONS,
55
} from "../../common/constants.mjs";
6+
import { parseObject } from "../../common/utils.mjs";
67
import plentyone from "../../plentyone.app.mjs";
78

89
export default {
@@ -25,9 +26,10 @@ export default {
2526
description: "The plenty ID of the client that the order belongs to.",
2627
},
2728
statusId: {
28-
type: "integer",
29-
label: "Status ID",
30-
description: "The ID of the order status.",
29+
propDefinition: [
30+
plentyone,
31+
"statusId",
32+
],
3133
optional: true,
3234
},
3335
ownerId: {
@@ -73,19 +75,19 @@ export default {
7375
const response = await this.plentyone.createOrder({
7476
$,
7577
data: {
76-
orderTypeId: this.orderTypeId,
78+
typeId: this.orderTypeId,
7779
plentyId: this.plentyId,
7880
statusId: this.statusId,
7981
ownerId: this.ownerId,
8082
lockStatus: this.lockStatus,
81-
orderItems: this.orderItems,
82-
properties: this.properties,
83-
addressRelations: this.addressRelations,
84-
relations: this.relations,
83+
orderItems: parseObject(this.orderItems),
84+
properties: parseObject(this.properties),
85+
addressRelations: parseObject(this.addressRelations),
86+
relations: parseObject(this.relations),
8587
},
8688
});
8789

88-
$.export("$summary", `Successfully created order: ${response.data?.id || "Unknown"}`);
90+
$.export("$summary", `Successfully created order: ${response.id}`);
8991
return response;
9092
} catch (error) {
9193
$.export("$summary", "Failed to create order");

components/plentyone/plentyone.app.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,25 @@ export default {
9696
}));
9797
},
9898
},
99+
statusId: {
100+
type: "integer",
101+
label: "Status ID",
102+
description: "The ID of the order status.",
103+
async options({ page }) {
104+
const { entries } = await this.getOrderStatuses({
105+
params: {
106+
page: page + 1,
107+
},
108+
});
109+
110+
return entries.map(({
111+
statusId: value, names: { en: label },
112+
}) => ({
113+
label,
114+
value,
115+
}));
116+
},
117+
},
99118
},
100119
methods: {
101120
_headers() {
@@ -143,6 +162,12 @@ export default {
143162
...opts,
144163
});
145164
},
165+
getOrderStatuses(opts = {}) {
166+
return this._makeRequest({
167+
path: "/orders/statuses",
168+
...opts,
169+
});
170+
},
146171
getContacts(opts = {}) {
147172
return this._makeRequest({
148173
path: "/accounts/contacts",

0 commit comments

Comments
 (0)