Skip to content

Commit f798cce

Browse files
committed
feat: implement, prototype, tests, resources
1 parent 6080d51 commit f798cce

File tree

7 files changed

+99
-0
lines changed

7 files changed

+99
-0
lines changed

resources/fulfillment-order.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,19 @@ FulfillmentOrder.prototype.fulfillments = function fulfillments(id) {
127127
return this.shopify.request(url, 'GET', 'fulfillments');
128128
};
129129

130+
/**
131+
* Halts all fulfillment work on a fulfillment order with
132+
* status OPEN and changes the status of the fulfillment order to ON_HOLD.
133+
*
134+
* @param {Number} id Order ID
135+
* @return {Promise} Promise that resolves with the result
136+
* @public
137+
*/
138+
FulfillmentOrder.prototype.hold = function hold(id, params) {
139+
const url = this.buildUrl(`${id}/hold`);
140+
return this.shopify
141+
.request(url, 'POST', undefined, params)
142+
.then((body) => body[this.key]);
143+
};
144+
130145
module.exports = FulfillmentOrder;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"fulfillment_hold": {
3+
"reason": "inventory_out_of_stock",
4+
"reason_notes": "Not enough inventory to complete this work.",
5+
"fulfillment_order_line_items": [{ "id": 1058737493, "quantity": 1 }]
6+
}
7+
}

test/fixtures/fulfillment-order/req/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ exports.cancel = require('./cancel');
44
exports.close = require('./close');
55
exports.move = require('./move');
66
exports.setFulfillmentOrdersDeadline = require('./set-fulfillment-orders-deadline');
7+
exports.hold = require('./hold');
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"fulfillment_order": {
3+
"id": 1046000789,
4+
"shop_id": 548380009,
5+
"order_id": 450789469,
6+
"assigned_location_id": 24826418,
7+
"request_status": "unsubmitted",
8+
"status": "on_hold",
9+
"fulfill_at": null,
10+
"supported_actions": ["release_hold"],
11+
"destination": {
12+
"id": 1046000789,
13+
"address1": "Chestnut Street 92",
14+
"address2": "",
15+
"city": "Louisville",
16+
"company": null,
17+
"country": "United States",
18+
"email": "bob.norman@mail.example.com",
19+
"first_name": "Bob",
20+
"last_name": "Norman",
21+
"phone": "+1(502)-459-2181",
22+
"province": "Kentucky",
23+
"zip": "40202"
24+
},
25+
"line_items": [
26+
{
27+
"id": 1058737493,
28+
"shop_id": 548380009,
29+
"fulfillment_order_id": 1046000789,
30+
"quantity": 1,
31+
"line_item_id": 518995019,
32+
"inventory_item_id": 49148385,
33+
"fulfillable_quantity": 1,
34+
"variant_id": 49148385
35+
}
36+
],
37+
"international_duties": null,
38+
"fulfillment_holds": [
39+
{
40+
"reason": "inventory_out_of_stock",
41+
"reason_notes": "Not enough inventory to complete this work."
42+
}
43+
],
44+
"fulfill_by": null,
45+
"created_at": "2024-07-24T06:26:32-04:00",
46+
"updated_at": "2024-07-24T06:26:33-04:00",
47+
"delivery_method": null,
48+
"assigned_location": {
49+
"address1": null,
50+
"address2": null,
51+
"city": null,
52+
"country_code": "DE",
53+
"location_id": 24826418,
54+
"name": "Apple Api Shipwire",
55+
"phone": null,
56+
"province": null,
57+
"zip": null
58+
},
59+
"merchant_requests": []
60+
}
61+
}

test/fixtures/fulfillment-order/res/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ exports.close = require('./close');
77
exports.list = require('./list');
88
exports.move = require('./move');
99
exports.get = require('./get');
10+
exports.hold = require('./hold');

test/fulfillment-order.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,17 @@ describe('Shopify#fulfillmentOrder', () => {
134134
.fulfillments(1046000823)
135135
.then((data) => expect(data).to.deep.equal(output.fulfillments));
136136
});
137+
138+
it('applies a fulfillment hold on an open fulfillment order', () => {
139+
const input = fixtures.req.hold;
140+
const output = fixtures.res.hold;
141+
142+
scope
143+
.post('/admin/fulfillment_orders/1046000789/hold.json', input)
144+
.reply(200, output);
145+
146+
return shopify.fulfillmentOrder.hold(1046000789).then((data) => {
147+
expect(data).to.deep.equal(output.fulfillment_order);
148+
});
149+
});
137150
});

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ declare class Shopify {
389389
fulfillments: (
390390
id: number
391391
) => Promise<Shopify.IPaginatedResult<Shopify.IFulfillment>>;
392+
hold: (id: number, params: any) => Promise<Shopify.IFulfillmentOrder>;
392393
};
393394
fulfillmentRequest: {
394395
accept: (

0 commit comments

Comments
 (0)