Skip to content

Commit

Permalink
[api] Add reschedule action to FulfillmentOrder resource
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Aug 20, 2024
1 parent 101cc52 commit 189cbb1
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ default.
- `list(orderId, fulfillmentId[, params])`
- `update(orderId, fulfillmentId, id, params)`
- fulfillmentOrder
- `cancel(id, params)`
- `cancel(id)`
- `close(id[, message])`
- `fulfillments(id)`
- `get(id)`
Expand All @@ -489,6 +489,7 @@ default.
- `locationsForMove(id)`
- `move(id, locationId)`
- `releaseHold(id)`
- `reschedule(id, deadline)`
- `setFulfillmentOrdersDeadline(params)`
- fulfillmentRequest
- `accept(fulfillmentOrderId[, message])`
Expand Down
18 changes: 18 additions & 0 deletions resources/fulfillment-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,22 @@ FulfillmentOrder.prototype.releaseHold = function releaseHold(id) {
.then((body) => body[this.key]);
};

/**
* Reschedules a scheduled fulfillment order. Updates the value of the
* `fulfill_at field` on a scheduled fulfillment order. The fulfillment order
* will be marked as ready for fulfillment at this date and time.
*
* @param {Number} id Fulfillment Order ID
* @param {String} deadline The new fulfillment deadline of the fulfillment
* order
* @return {Promise} Promise that resolves with the result
* @public
*/
FulfillmentOrder.prototype.reschedule = function reschedule(id, deadline) {
const url = this.buildUrl(`${id}/reschedule`);
return this.shopify.request(url, 'POST', this.key, {
new_fulfill_at: deadline
});
};

module.exports = FulfillmentOrder;
1 change: 1 addition & 0 deletions test/fixtures/fulfillment-order/req/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ exports.cancel = require('./cancel');
exports.close = require('./close');
exports.hold = require('./hold');
exports.move = require('./move');
exports.reschedule = require('./reschedule');
exports.setFulfillmentOrdersDeadline = require('./set-fulfillment-orders-deadline');
1 change: 1 addition & 0 deletions test/fixtures/fulfillment-order/req/reschedule.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "fulfillment_order": { "new_fulfill_at": "2025-08-24 10:26 UTC" } }
1 change: 1 addition & 0 deletions test/fixtures/fulfillment-order/res/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ exports.list = require('./list');
exports.locationsForMove = require('./locations-for-move');
exports.move = require('./move');
exports.releaseHold = require('./release-hold');
exports.reschedule = require('./reschedule');
56 changes: 56 additions & 0 deletions test/fixtures/fulfillment-order/res/reschedule.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"fulfillment_order": {
"id": 1046000788,
"shop_id": 548380009,
"order_id": 450789469,
"assigned_location_id": 24826418,
"request_status": "unsubmitted",
"status": "scheduled",
"fulfill_at": "2025-08-24T06:26:00-04:00",
"supported_actions": ["mark_as_open"],
"destination": {
"id": 1046000788,
"address1": "Chestnut Street 92",
"address2": "",
"city": "Louisville",
"company": null,
"country": "United States",
"email": "bob.norman@mail.example.com",
"first_name": "Bob",
"last_name": "Norman",
"phone": "+1(502)-459-2181",
"province": "Kentucky",
"zip": "40202"
},
"line_items": [
{
"id": 1058737492,
"shop_id": 548380009,
"fulfillment_order_id": 1046000788,
"quantity": 1,
"line_item_id": 518995019,
"inventory_item_id": 49148385,
"fulfillable_quantity": 1,
"variant_id": 49148385
}
],
"international_duties": null,
"fulfillment_holds": [],
"fulfill_by": null,
"created_at": "2024-07-24T06:26:30-04:00",
"updated_at": "2024-07-24T06:26:32-04:00",
"delivery_method": null,
"assigned_location": {
"address1": null,
"address2": null,
"city": null,
"country_code": "DE",
"location_id": 24826418,
"name": "Apple Api Shipwire",
"phone": null,
"province": null,
"zip": null
},
"merchant_requests": []
}
}
15 changes: 15 additions & 0 deletions test/fulfillment-order.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,19 @@ describe('Shopify#fulfillmentOrder', () => {
expect(data).to.deep.equal(output.fulfillment_order);
});
});

it('reschedules the fulfill_at time of a scheduled fulfillment order', () => {
const input = fixtures.req.reschedule;
const output = fixtures.res.reschedule;

scope
.post('/admin/fulfillment_orders/1046000788/reschedule.json', input)
.reply(200, output);

return shopify.fulfillmentOrder
.reschedule(1046000788, '2025-08-24 10:26 UTC')
.then((data) => {
expect(data).to.deep.equal(output.fulfillment_order);
});
});
});
4 changes: 4 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ declare class Shopify {
locationId: number
) => Promise<Shopify.IFulfillmentOrder>;
releaseHold: (id: number) => Promise<Shopify.IFulfillmentOrder>;
reschedule: (
id: number,
deadline: string
) => Promise<Shopify.IFulfillmentOrder>;
setFulfillmentOrdersDeadline: (
params: Shopify.ISetFulfillmentOrdersDeadline
) => Promise<void>;
Expand Down

0 comments on commit 189cbb1

Please sign in to comment.