How to use selected_options and entered_options in GraphQL Query Magento 2?

What is the Difference between selected options vs entered options GraphQL keyword?
From the Magento version 2.4, You can see new architectural changes for the Data Transfer Object (DTO) will be used widely in GraphQL Query.

You have also marked new updates selected_options and entered_options in the GraphQL Query.

selected and entered options value must be base64_encode in the query and you can use this feature in add to cart and wishlist by GraphQL mutation.

There will be two types of Options for each type of option in Magento.


  • selected_options: Selected Options will be used when you can select already existing options from the product or custom options. Its predefined options are available with the product.

Example, Drop Down, Radio Button, Checkbox, Swatch Attribute

For Example, Configurable product with choose color or size, Bundle with choose a different combination of items by click on the radio or checkbox.
All those options that will be selected from the product will be used as selected options.

A configurable item with two attributes, color, and size,

selected_options: [
  "Y29uZmlndXJhYmxlLzE4Ni8xNzY="
  "Y29uZmlndXJhYmxlLzkzLzY3"
]

Each Option base64 will be in a new line for the selected_options/entered options.


  • entered_options: An option entered by customers like text field, text area, date, image, etc. All those options where user manual input will be needed to be used as entered options.

For example, Product with a custom option type field and image, you need to enter an input value to a specific field.

entered_options: [
  {
    uid: "Sww3ZmlndXJhYmxlLzE4Ni8xNzY=",
    value: "User input Value"
  }
]

Different types of Items syntax to create base64 encoded value,

1. Configurable Item syntax,

base64_encode('configurable/<ATTRIBUTE_ID>/<OPTION_VALUE_ID>')

Color Attribute Id 93 and Option Value Red Id 67

base64_encode('configurable/93/67'); //Y29uZmlndXJhYmxlLzE4Ni8xNzY=

2. Bundle Item syntax,

base64_encode("<OPTION_TYPE>/<OPTION_ID>/<OPTION_VALUE_ID>/<OPTION_QUANTITY>")

Here,
<OPTION_TYPE> will be a bundle
<OPTION_ID> will be option id
<OPTION_VALUE_ID> will be option value id
<OPTION_QUANTITY> will be option qty

selected options for bundle item with child selection,

base64_encode("bundle/1/2/1") => "YnVuZGxlLzEvMi8x" 
base64_encode("bundle/2/4/2") => "YnVuZGxlLzIvNC8y" 
base64_encode("bundle/3/5/5") => "YnVuZGxlLzMvNS81" 
base64_encode("bundle/4/8/5") => "YnVuZGxlLzQvOC81"

Example,

{
    sku: "24-WG080"
    quantity: 1
    selected_options: [
      "YnVuZGxlLzEvMi8x"
      "YnVuZGxlLzIvNC8y"
      "YnVuZGxlLzMvNS81"
      "YnVuZGxlLzQvOC81"
    ]
}

3. Downloadable Item syntax

base64_encode('<OPTION_TYPE>/<OPTION_LINK_ID>')

<OPTION_TYPE> will be downloadable
<OPTION_LINK_Id> will be Item Link id.

For example,
Downloadable product SKU 240-LV09 from the Magento sample data,
Downloadable Episode 1 option id will be 6.
base64_encode("downloadable/6") // ZG93bmxvYWRhYmxlLzY=

{
sku: "240-LV09"
quantity: 1
selected_options: ["ZG93bmxvYWRhYmxlLzY="]
}

4. Custom Options Item Syntax,

base64_encode("<OPTION_TYPE>/<OPTION_ID>/<OPTION_VALUE_ID>")

Example, for Custom drop-down option for the Custom option Product,
“Gender(id = 1), with values Male(id = 1), Female(id = 2)”

Here,
OPTION_TYPE equals custom-option
OPTION_ID equals Gender(id = 1)
OPTION_VALUE_ID equals female(id = 2)

uid for Gender with Female will looks like,

base64_encode("custom-option/1/2") => "Y3VzdG9tLW9wdGlvbi8xLzI="

You can aware about all the details information for the selected and entered options.