Order Edits
Queries and Mutations listed here are used to send requests to the Admin Order Edit API Routes.
All hooks listed require authentication.
An admin can edit an order to remove, add, or update an item's quantity. When an admin edits an order, they're stored as an OrderEdit
.
Related Guide: How to edit an order.
Mutations
useAdminCreateOrderEdit
This hook creates an order edit.
Example
import React from "react"
import { useAdminCreateOrderEdit } from "medusa-react"
const CreateOrderEdit = () => {
const createOrderEdit = useAdminCreateOrderEdit()
const handleCreateOrderEdit = (orderId: string) => {
createOrderEdit.mutate({
order_id: orderId,
}, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.id)
}
})
}
// ...
}
export default CreateOrderEdit
Mutation Function Parameters
The details of the order edit to create.
Mutation Function Returned Data
The order edit details.
useAdminDeleteOrderEdit
This hook deletes an order edit. Only order edits that have the status created
can be deleted.
Example
import React from "react"
import { useAdminDeleteOrderEdit } from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const deleteOrderEdit = useAdminDeleteOrderEdit(
orderEditId
)
const handleDelete = () => {
deleteOrderEdit.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default OrderEdit
Hook Parameters
id
stringRequiredMutation Function Returned Data
The response returned for a
DELETE
request.
DELETE
request.useAdminDeleteOrderEditItemChange
This hook deletes a line item change that indicates the addition, deletion, or update of a line item in the original order.
Example
import React from "react"
import { useAdminDeleteOrderEditItemChange } from "medusa-react"
type Props = {
orderEditId: string
itemChangeId: string
}
const OrderEditItemChange = ({
orderEditId,
itemChangeId
}: Props) => {
const deleteItemChange = useAdminDeleteOrderEditItemChange(
orderEditId,
itemChangeId
)
const handleDeleteItemChange = () => {
deleteItemChange.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default OrderEditItemChange
Hook Parameters
orderEditId
stringRequireditemChangeId
stringRequiredMutation Function Returned Data
The details of deleting order edit item changes.
useAdminOrderEditUpdateLineItem
This hook creates or updates a line item change in the order edit that indicates addition, deletion, or update of a line item into an original order. Line item changes are only reflected on the original order after the order edit is confirmed.
Example
import React from "react"
import { useAdminOrderEditUpdateLineItem } from "medusa-react"
type Props = {
orderEditId: string
itemId: string
}
const OrderEditItemChange = ({
orderEditId,
itemId
}: Props) => {
const updateLineItem = useAdminOrderEditUpdateLineItem(
orderEditId,
itemId
)
const handleUpdateLineItem = (quantity: number) => {
updateLineItem.mutate({
quantity,
}, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.items)
}
})
}
// ...
}
export default OrderEditItemChange
Hook Parameters
orderEditId
stringRequireditemId
stringRequiredMutation Function Parameters
The details to create or update of the line item change.
Mutation Function Returned Data
The order edit details.
useAdminOrderEditDeleteLineItem
This hook creates a line item change in the order edit that indicates deleting an item in the original order. The item in the original order will not be deleted until the order edit is confirmed.
Example
import React from "react"
import { useAdminOrderEditDeleteLineItem } from "medusa-react"
type Props = {
orderEditId: string
itemId: string
}
const OrderEditLineItem = ({
orderEditId,
itemId
}: Props) => {
const removeLineItem = useAdminOrderEditDeleteLineItem(
orderEditId,
itemId
)
const handleRemoveLineItem = () => {
removeLineItem.mutate(void 0, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.changes)
}
})
}
// ...
}
export default OrderEditLineItem
Hook Parameters
orderEditId
stringRequireditemId
stringRequiredMutation Function Returned Data
The order edit details.
useAdminUpdateOrderEdit
This hook updates an Order Edit's details.
Example
import React from "react"
import { useAdminUpdateOrderEdit } from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const updateOrderEdit = useAdminUpdateOrderEdit(
orderEditId,
)
const handleUpdate = (
internalNote: string
) => {
updateOrderEdit.mutate({
internal_note: internalNote
}, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.internal_note)
}
})
}
// ...
}
export default OrderEdit
Hook Parameters
id
stringRequiredMutation Function Parameters
The details to update of the order edit.
Mutation Function Returned Data
The order edit details.
useAdminOrderEditAddLineItem
This hook creates a line item change in the order edit that indicates adding an item in the original order. The item will not be added to the original order until the order edit is confirmed.
Example
import React from "react"
import { useAdminOrderEditAddLineItem } from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const addLineItem = useAdminOrderEditAddLineItem(
orderEditId
)
const handleAddLineItem =
(quantity: number, variantId: string) => {
addLineItem.mutate({
quantity,
variant_id: variantId,
}, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.changes)
}
})
}
// ...
}
export default OrderEdit
Hook Parameters
id
stringRequiredMutation Function Parameters
The details of the line item change to create.
Mutation Function Returned Data
The order edit details.
useAdminRequestOrderEditConfirmation
This hook requests customer confirmation of an order edit. This would emit the event order-edit.requested
which Notification Providers listen to and send
a notification to the customer about the order edit.
Example
import React from "react"
import {
useAdminRequestOrderEditConfirmation,
} from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const requestOrderConfirmation =
useAdminRequestOrderEditConfirmation(
orderEditId
)
const handleRequestConfirmation = () => {
requestOrderConfirmation.mutate(void 0, {
onSuccess: ({ order_edit }) => {
console.log(
order_edit.requested_at,
order_edit.requested_by
)
}
})
}
// ...
}
export default OrderEdit
Hook Parameters
id
stringRequiredMutation Function Returned Data
The order edit details.
useAdminCancelOrderEdit
This hook cancels an order edit.
Example
import React from "react"
import {
useAdminCancelOrderEdit,
} from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const cancelOrderEdit =
useAdminCancelOrderEdit(
orderEditId
)
const handleCancel = () => {
cancelOrderEdit.mutate(void 0, {
onSuccess: ({ order_edit }) => {
console.log(
order_edit.id
)
}
})
}
// ...
}
export default OrderEdit
Hook Parameters
id
stringRequiredMutation Function Returned Data
The order edit details.
useAdminConfirmOrderEdit
This hook confirms an order edit. This will reflect the changes in the order edit on the associated order.
Example
import React from "react"
import { useAdminConfirmOrderEdit } from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const confirmOrderEdit = useAdminConfirmOrderEdit(
orderEditId
)
const handleConfirmOrderEdit = () => {
confirmOrderEdit.mutate(void 0, {
onSuccess: ({ order_edit }) => {
console.log(
order_edit.confirmed_at,
order_edit.confirmed_by
)
}
})
}
// ...
}
export default OrderEdit
Hook Parameters
id
stringRequiredMutation Function Returned Data
The order edit details.
Queries
useAdminOrderEdit
This hook retrieves an order edit's details.
Example
A simple example that retrieves an order edit by its ID:
import React from "react"
import { useAdminOrderEdit } from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const {
order_edit,
isLoading,
} = useAdminOrderEdit(orderEditId)
return (
<div>
{isLoading && <span>Loading...</span>}
{order_edit && <span>{order_edit.status}</span>}
</div>
)
}
export default OrderEdit
To specify relations that should be retrieved:
import React from "react"
import { useAdminOrderEdit } from "medusa-react"
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const {
order_edit,
isLoading,
} = useAdminOrderEdit(
orderEditId,
{
expand: "order"
}
)
return (
<div>
{isLoading && <span>Loading...</span>}
{order_edit && <span>{order_edit.status}</span>}
</div>
)
}
export default OrderEdit
Hook Parameters
id
stringRequiredConfigurations to apply on the retrieved order edit.
Query Returned Data
Order edit details
useAdminOrderEdits
This hook retrieves a list of order edits. The order edits can be filtered by fields such as q
or order_id
passed to the query
parameter.
The order edits can also be paginated.
Example
To list order edits:
import React from "react"
import { useAdminOrderEdits } from "medusa-react"
const OrderEdits = () => {
const { order_edits, isLoading } = useAdminOrderEdits()
return (
<div>
{isLoading && <span>Loading...</span>}
{order_edits && !order_edits.length && (
<span>No Order Edits</span>
)}
{order_edits && order_edits.length > 0 && (
<ul>
{order_edits.map((orderEdit) => (
<li key={orderEdit.id}>
{orderEdit.status}
</li>
))}
</ul>
)}
</div>
)
}
export default OrderEdits
To specify relations that should be retrieved within the order edits:
import React from "react"
import { useAdminOrderEdits } from "medusa-react"
const OrderEdits = () => {
const { order_edits, isLoading } = useAdminOrderEdits({
expand: "order"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{order_edits && !order_edits.length && (
<span>No Order Edits</span>
)}
{order_edits && order_edits.length > 0 && (
<ul>
{order_edits.map((orderEdit) => (
<li key={orderEdit.id}>
{orderEdit.status}
</li>
))}
</ul>
)}
</div>
)
}
export default OrderEdits
By default, only the first 50
records are retrieved. You can control pagination by specifying the limit
and offset
properties:
import React from "react"
import { useAdminOrderEdits } from "medusa-react"
const OrderEdits = () => {
const {
order_edits,
limit,
offset,
isLoading
} = useAdminOrderEdits({
expand: "order",
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{order_edits && !order_edits.length && (
<span>No Order Edits</span>
)}
{order_edits && order_edits.length > 0 && (
<ul>
{order_edits.map((orderEdit) => (
<li key={orderEdit.id}>
{orderEdit.status}
</li>
))}
</ul>
)}
</div>
)
}
export default OrderEdits
Hook Parameters
query
GetOrderEditsParamsFilters and pagination configurations applied to retrieved order edits.
query
GetOrderEditsParamsQuery Returned Data
limit
numberRequiredoffset
numberRequiredcount
numberRequired