Magento 2 How to create order using GraphQL

In this article, we will show you how to create order using GraphQL. The placeOrder mutation converts the cart into an order and returns an Order ID. We cannot manage orders with GraphQL, because orders are part of the backend. You can use REST or SOAP calls to manage orders to their completion.

The following actions are perform before using placeOrder mutation:

  1. Create an empty cart
  2. Add one or more products to the cart
  3. Set the billing address
  4. Set the shipping address
  5. Set the shipping method
  6. Set the payment method
  7. For guest customers, assign an email to the cart (use setGuestEmailOnCart)

Syntax

mutation {
  placeOrder(
    input: PlaceOrderInput
  ) {
    PlaceOrderOutput
  }
}

The following example for create order.

Request

saveCopyzoom_out_map
mutation { placeOrder( input: { cart_id: "tfwJXU8gMmjjXqcKyINO3ydMSsRd5Ogy" } ) { order { order_number } } }

Response

saveCopyzoom_out_map
{ "data": { "placeOrder": { "order": { "order_number": "000000004" } } } }

That's it!!

If you are looking for more GraphQL solutions then check out our another article which is List of GraphQL Queries and Mutations for Magento 2.

I hope this article helps you to find what you were looking for.

Bookmark it for your future reference. Do comment below if you have any other questions on that.

P.S. Do share this article with your team.




Recent Articles
Tags
Newsletter
Chrome Extension
Copyright © 2024 devhooks.in All rights reserved.
Ads OFF toggle_off
wifi_off