This is a beta release of documentation for Magento 2.4, published for previewing soon-to-be-released functionality. Content in this version is subject to change. Links to the v2.4 code base may not properly resolve until the code is officially released.

reorderItems mutation

The reorderItems mutation allows a logged-in user to add all the products from a previous order into their cart. The Stores > Settings > Sales > Sales > Reorder > Allow Reorder field must be set to Yes to enable reorders. You must provide a customer authorization token with the call.

The mutation returns an error if it cannot add a product to the customer’s cart:

Error code Description
INSUFFICIENT_STOCK The requested quantity is greater than the available stock.
NOT_SALABLE The product is out of stock, disabled, or otherwise prevented from being sold.
REORDER_NOT_AVAILABLE Reorders have been disabled.
PRODUCT_NOT_FOUND The product has been deleted.
UNDEFINED An unknown error occurred.

The reorderItems mutation will not add any products to the cart if it encounters the REORDER_NOT_AVAILABLE error. For any other error code, the mutation will add the product to the cart, if possible, and it will continue adding other products, if applicable.

Syntax

mutation: {reorderItems(orderNumber: String!) {ReorderItemsOutput}}

Example usage

In the following example, the customer previously created an order containing the following items:

Item Name SKU Quantity Ordered
Aeon Capri WP07-29-Black 3
Dual Handle Cardio Ball 24-UG07 1
Elisa EverCool Tee WS06-S-Gray 1
Sprite Foam Yoga Brick 24-WG084 1

The customer wants to reorder these items, but the status of some of these items has changed:

  • Aeon Capri (WP07-29-Black) is in stock, but fewer than three items are available for sale.
  • The Sprite Foam Yoga Brick (24-WG084) is out of stock.

These items will not be added to the cart.

Request:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
mutation{
  reorderItems(orderNumber: "000000003"){
    cart {
      id
      items {
        id
        product {
          sku
        }
        quantity
        prices {
          price {
            value
          }
        }
      }
    }
    userInputErrors{
      code
      message
      path
    }
  }
}

Response:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{
  "data": {
    "reorderItems": {
      "cart": {
        "id": "LrMHhWHUaOqiBGC6S0KOcnYKsINUHTWz",
        "items": [
          {
            "id": "44",
            "product": {
              "sku": "24-UG07"
            },
            "quantity": 1,
            "prices": {
              "price": {
                "value": 12
              }
            }
          },
          {
            "id": "45",
            "product": {
              "sku": "WS06"
            },
            "quantity": 1,
            "prices": {
              "price": {
                "value": 29
              }
            }
          }
        ]
      },
      "userInputErrors": [
        {
          "code": "NOT_SALABLE",
          "message": "Could not add the product with SKU \"24-WG084\" to the shopping cart: Product that you are trying to add is not available.",
          "path": [
            "orderNumber"
          ]
        },
        {
          "code": "INSUFFICIENT_STOCK",
          "message": "Could not add the product with SKU \"WP07-29-Black\" to the shopping cart: The requested qty is not available",
          "path": [
            "orderNumber"
          ]
        }
      ]
    }
  }
}

Input attributes

The reorderItems mutation requires a valid order number. The customer associated with the authorization token must match the customer who placed the specified order.

Attribute Type Description
orderNumber String! The ID of the order to be used as the source for reordering products

Output attributes

The ReorderItemsOutput object contains the following objects:

Attribute Data Type Description
cart Cart! Describes the contents of the specified shopping cart
userInputErrors [CheckoutUserInputError]! An array of reordering errors

Cart object

Attribute Data Type Description
applied_coupon AppliedCoupon Deprecated. Use applied_coupons instead
applied_coupons [AppliedCoupon] An array of AppliedCoupon objects. Each object contains the code text attribute, which specifies the coupon code
applied_gift_cards [AppliedGiftCard] An array of AppliedGiftCard objects. An AppliedGiftCard object contains the code text attribute, which specifies the gift card code. applied_gift_cards is a Commerce-only attribute, defined in the GiftCardAccountGraphQl module
applied_store_credit AppliedStoreCredit Contains store credit information applied to the cart. applied_store_credit is a Commerce-only attribute, defined in the CustomerBalanceGraphQl module
available_payment_methods [AvailablePaymentMethod] Available payment methods
billing_address BillingCartAddress Contains the billing address specified in the customer’s cart
email String The customer’s email address
id ID! The ID of the cart
is_virtual Boolean! Indicates whether the cart contains only virtual products
items [CartItemInterface] Contains the items in the customer’s cart
prices CartPrices Contains subtotals and totals
selected_payment_method SelectedPaymentMethod Selected payment method
shipping_addresses [ShippingCartAddress]! Contains one or more shipping addresses
total_quantity Float! Total Quantity of products in the cart

Cart query output provides more information about the Cart object.

userInputErrors object

The userInputErrors object contains an array of errors encountered while attempting to reorder products.

Attribute Data Type Description
userInputErrors [CheckoutUserInputError]! An array of reordering errors

CheckoutUserInputError object

Attribute Data Type Description
message String! A localized error message
path [String]! The value for this mutation is orderNumber