diff --git a/src/endpoints/orders.js b/src/endpoints/orders.js index a3b28cf..f16efec 100644 --- a/src/endpoints/orders.js +++ b/src/endpoints/orders.js @@ -29,6 +29,17 @@ class OrdersEndpoint extends BaseExtend { ) } + UpdateShippingGroup(orderId, shippingGroupId, body) { + return this.request.send( + `${this.endpoint}/${orderId}/shipping-groups/${shippingGroupId}`, + 'PUT', + { + ...body, + type: 'shipping_group' + } + ) + } + Payment(orderId, body) { return this.request.send(`${this.endpoint}/${orderId}/payments`, 'POST', { data: body, diff --git a/src/types/order.d.ts b/src/types/order.d.ts index 509c1fa..f45bc17 100644 --- a/src/types/order.d.ts +++ b/src/types/order.d.ts @@ -135,6 +135,7 @@ export interface ShippingGroupBase extends Identifiable { base: FormattedPrice tax: FormattedPrice fees: FormattedPrice + discount?: FormattedPrice } total_display_price: { with_tax: FormattedPrice @@ -146,10 +147,26 @@ export interface ShippingGroupBase extends Identifiable { authorized: FormattedPrice without_discount: FormattedPrice shipping: FormattedPrice + shipping_discount?: FormattedPrice } } } +/** + * Fields accepted by PUT /v2/orders/:id/shipping-groups/:id. + * `delivery_estimate` is replaced wholesale: omit it and the API clears it. + */ +export interface ShippingGroupUpdateBody { + address?: OrderShippingAddress + shipping_type?: string + tracking_reference?: string + external_ref?: string + delivery_estimate?: { + start: string + end: string + } +} + /** * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/orders-and-customers/orders/filtering.html @@ -587,4 +604,11 @@ export interface OrdersEndpoint GetShippingGroup(id:string, ShippingGroupId: string): Promise> + /** + * Update a Shipping Group on an Order + * Description: Updates the address, shipping type, tracking reference, external ref or delivery estimate of a shipping group. + * DOCS: https://elasticpath.dev/docs/api/carts/update-order-shipping-group + */ + UpdateShippingGroup(id: string, ShippingGroupId: string, body: ShippingGroupUpdateBody): Promise> + } diff --git a/test/unit/orders.ts b/test/unit/orders.ts index e6e067b..7047aca 100644 --- a/test/unit/orders.ts +++ b/test/unit/orders.ts @@ -292,6 +292,58 @@ describe('ElasticPath orders', () => { }) }) + it('should update a shipping group on an order', () => { + const ElasticPath = ElasticPathGateway({ + client_id: 'XXX' + }) + + const address = { + first_name: 'John', + last_name: 'Doe', + line_1: '1 Main Street', + city: 'Springfield', + postcode: '12345', + county: 'Hampden', + region: 'MA', + country: 'US' + } + + // Intercept the API request + nock(apiUrl, { + reqheaders: { + Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' + } + }) + .put('/orders/order-1/shipping-groups/shipping-group-1', { + data: { + type: 'shipping_group', + address, + delivery_estimate: { + start: '2026-09-10T00:00:00Z', + end: '2026-09-17T00:00:00Z' + } + } + }) + .reply(200, { + data: { + id: 'shipping-group-1', + type: 'shipping_group', + address + } + }) + + return ElasticPath.Orders.UpdateShippingGroup('order-1', 'shipping-group-1', { + address, + delivery_estimate: { + start: '2026-09-10T00:00:00Z', + end: '2026-09-17T00:00:00Z' + } + }).then(response => { + assert.propertyVal(response.data, 'id', 'shipping-group-1') + assert.propertyVal(response.data.address, 'city', 'Springfield') + }) + }) + it('should get orders attributes', () => { const ElasticPath = ElasticPathGateway({ client_id: 'XXX'