Magento 2 How to get Products with CustomOptions in GraphQL

In this artical we will show you how to get products with custom options. CustomizableProductInterface attributes can be used in any products query.

The following query returns information about the customizable options configured for the product with a sku of any.

Request

saveCopyzoom_out_map
{
  products(filter: {sku: {eq: "24-MB01"}}) {
    items {
      id
      name
      sku
      __typename
      ... on CustomizableProductInterface {
        options {
          title
          required
          sort_order
          option_id
          ... on CustomizableDropDownOption{
             value{
              option_type_id
              price
              price_type
              sku
              sort_order
              title
            }
          }
        }
      }
    }
  }
}

Response

saveCopyzoom_out_map
{
  "data": {
    "products": {
      "items": [
        {
          "id": 1,
          "name": "Joust Duffle Bag",
          "sku": "24-MB01",
          "__typename": "SimpleProduct",
          "options": [
            {
              "title": "Custom Options",
              "required": true,
              "sort_order": 1,
              "option_id": 1
            }
          ]
        }
      ]
    }
  }
}

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
Copyright © 2023 devhooks.in All rights reserved.
Ads OFF toggle_off
wifi_off