Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/endpoints/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions src/types/order.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export interface ShippingGroupBase extends Identifiable {
base: FormattedPrice
tax: FormattedPrice
fees: FormattedPrice
discount?: FormattedPrice
}
total_display_price: {
with_tax: FormattedPrice
Expand All @@ -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
Expand Down Expand Up @@ -587,4 +604,11 @@ export interface OrdersEndpoint

GetShippingGroup(id:string, ShippingGroupId: string): Promise<ResourceIncluded<ShippingGroupBase, ShippingIncluded>>

/**
* 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<Resource<ShippingGroupBase>>

}
52 changes: 52 additions & 0 deletions test/unit/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading