Skip to main content
Version: 3.x

Order to checkout

info

This feature was introduced in Saleor 3.14.

caution

This feature is in the Feature Preview stage, which means that it is available for experimentation and feedback. However, it is still undergoing development and is subject to modifications.

Saleor allows you to create a checkout from existing orders. This feature can be used when implementing the reordering functionality.

The checkoutCreateFromOrder mutation accepts the Order ID as input and returns the new checkout, with the lines from the order attached to it. Lines that are not available (variants deleted, products deleted, variants not published, out of stock, etc.) are returned as unavailableVariants. Any discounts or custom prices attached to the order will not be carried over to the newly created checkout. The price of each checkout line will be based on the current price of the variant.

UnavailableVariants is a list of variants that could not be attached to the checkout. Each item has:

  • code that describes why Saleor could not add it to the checkout.
  • variantId that contains the ID of the unavailable variant.
  • lineId that contains the ID of the related orderLine.
  • message the error message.

The following example shows how the checkoutCreateFromOrder mutation creates a new checkout:

mutation CheckoutCreateFromOrder {
checkoutCreateFromOrder(
id: "T3JkZXI6OTM2ZTFlNzEtZDc4NS00MGZiLWI4OTAtYTRmMTk5MTJiOWM2"
) {
errors {
field
message
code
}
unavailableVariants {
message
code
variantId
lineId
}
checkout {
id
lines {
quantity
variant {
id
}
}
}
}
}
Expand â–¼

The response returns an order object:

{
"data": {
"checkoutCreateFromOrder": {
"errors": [],
"unavailableVariants": [],
"checkout": {
"id": "Q2hlY2tvdXQ6ZjIwMjE3MjAtYzI5Yy00N2NmLWFmYzYtYzZjNGZlOTIyODM2",
"lines": [
{
"quantity": 1,
"variant": {
"id": "UHJvZHVjdFZhcmlhbnQ6NDAw"
}
},
{
"quantity": 3,
"variant": {
"id": "UHJvZHVjdFZhcmlhbnQ6MzU0"
}
},
{
"quantity": 1,
"variant": {
"id": "UHJvZHVjdFZhcmlhbnQ6Mzkw"
}
}
]
}
}
}
}
Expand â–¼

If there are variants that cannot be attached to the checkout, the response will be as follows:

{
"data": {
"checkoutCreateFromOrder": {
"errors": [],
"unavailableVariants": [
{
"message": "Product variant not found",
"code": "NOT_FOUND",
"variantId": "UHJvZHVjdFZhcmlhbnQ6NDAw",
"lineId": "T3JkZXJMaW5lOjc2NWM2Y2JjLTZkZTktNDUwYS1hNjFlLTc5ZmQ1YjkwYmQzMg=="
},
{
"message": "Cannot add lines for unpublished variants.",
"code": "PRODUCT_NOT_PUBLISHED",
"variantId": "UHJvZHVjdFZhcmlhbnQ6Mzkw",
"lineId": "T3JkZXJMaW5lOmJhMGIxYTIyLWUyMGYtNDQyMC04NDgxLTA1MjgxYzdhMWE3MQ=="
}
],
"checkout": {
"id": "Q2hlY2tvdXQ6M2VlM2Y3NjEtZTRmYi00MTE5LTgwZmUtNTZmMzQ3MTkxYTFi",
"lines": [
{
"quantity": 3,
"variant": {
"id": "UHJvZHVjdFZhcmlhbnQ6MzU0"
}
}
]
}
}
}
}
Expand â–¼

Was this page helpful?