Add Product With Custom Options To Cart Graphql in Magento 2

Add product to cart GraphQL Magento 2

Add product to cart GraphQL Magento 2

Add product to cart GraphQL Magento 2 or Add Simple Product With Custom Options To Cart in Magento2

Method Post

AUTHORIZATION Bearer Token

BODY graphql

mutation {
  addSimpleProductsToCart(
    input: {
      cart_id: "ctxNWM4yYu4udYCUm8TSeXZOdv7VXv72"
      cart_items: [
        {
          data: {
            quantity: 1
            sku: "test"
          }
          customizable_options: {
              id: 16,
              value_string: "28"
          }
        }
      ]
    }
  ) {
    cart {
      items {
        id
        product {
          sku
          stock_status
        }
        quantity
      }
      prices {
          subtotal_excluding_tax{
              value
              currency
          }
          grand_total{
              value
              currency
          }
      }
    }
  }
}

Note :-
cart_id : It is a cart/qoute id.
quantity : Qty of the product.
sku : SKU of the product.
customizable_options :
id => It is a option_id, In my case 16 option_id of Custom option radio type.
value_string => It is a option_type_id, In my case 28 option_type_id of the selected option value(If you have custom otion input box, just enter string like “some text” in string format).

My product custom option, You can see by using get product detail by sku.

"options": [
{
"option_id": 16,
"title": "Custom option",
"required": true,
"sort_order": 1,
"value": [
{
"uid": "Y3VzdG9tLW9wdGlvbi8xNi8yOA==",
"option_type_id": 28,
"price": 5,
"price_type": "FIXED",
"sku": null,
"sort_order": 0,
"title": "No"
},
{
"uid": "Y3VzdG9tLW9wdGlvbi8xNi8yNw==",
"option_type_id": 27,
"price": 3,
"price_type": "FIXED",
"sku": null,
"sort_order": 1,
"title": "Yes"
}
]
}
]

Related Post : Syntax error unexpected eof in Graphql

Like us on Facebook and Linkedin for more updates.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top