> For the complete documentation index, see [llms.txt](https://wiki.theshop.dev/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.theshop.dev/docs/frontstore/basic-selling-flow/product-detail/variants-tree.md).

# Variants tree

Let's assume you have product with these product attribute values:

* Size: *M*, *L*&#x20;
* Color: *yellow*, *red*&#x20;
* Material: *cotton*, *silk*

If all these product attribute values were used for generating product variants, then you would end up with 8 different combinations of product attribute values.

<figure><img src="/files/YAtYNM3wv8DnD0nHfnBE" alt=""><figcaption><p><strong>Choice of options</strong> drop-down menu with product variants</p></figcaption></figure>

Variants tree property helps you narrowing down the options for customer to get to the desired product variant with chosen product attribute values. Example use-case would be to show selected boxes to customer.&#x20;

It doesn't matter which product attribute you will use as first, because there are all in the first dimension of the array. Then, if you go deeper, you will get the remaining attribute values to further narrowing down the product variant selection until you end up with exactly filtered product variant. Verify that the end node of the variants tree includes the `uuid` and `slug` keys.

Structure of the variants tree:

```
$productAttributeName1 => [
    $productAttributeValueName1 => [
        $productAttributeName2 => [
            ...
        ]
    ]
]
```

<details>

<summary>A real-word example of a variant tree</summary>

```json
"variants_tree": {
      "Size": {
        "S": {
          "Color": {
            "yellow": {
              "Material": {
                "cotton": {
                  "uuid": "e62ea1a0-5aaf-4c5c-b3c9-b454543c5287",
                  "slug": "s-yellow-cotton"
                },
                "silk": {
                  "uuid": "4707f9bc-5a99-4ed3-b542-ef0324701057",
                  "slug": "s-yellow-silk"
                }
              }
            },
            "red": {
              "Material": {
                "cotton": {
                  "uuid": "dd168086-1262-4627-a7e6-787c77aa4eb3",
                  "slug": "s-red-cotton"
                },
                "silk": {
                  "uuid": "c7ce66ff-8ee4-44fe-b553-617ce5e1aa0e",
                  "slug": "s-red-silk"
                }
              }
            }
          },
          "Material": {
            "cotton": {
              "Color": {
                "yellow": {
                  "uuid": "e62ea1a0-5aaf-4c5c-b3c9-b454543c5287",
                  "slug": "s-yellow-cotton"
                },
                "red": {
                  "uuid": "dd168086-1262-4627-a7e6-787c77aa4eb3",
                  "slug": "s-red-cotton"
                }
              }
            },
            "silk": {
              "Color": {
                "yellow": {
                  "uuid": "4707f9bc-5a99-4ed3-b542-ef0324701057",
                  "slug": "s-yellow-silk"
                },
                "red": {
                  "uuid": "c7ce66ff-8ee4-44fe-b553-617ce5e1aa0e",
                  "slug": "s-red-silk"
                }
              }
            }
          }
        },
        "M": {
          "Color": {
            "yellow": {
              "Material": {
                "cotton": {
                  "uuid": "32977208-4d5e-4feb-8da0-5b85193fe782",
                  "slug": "m-yellow-cotton"
                },
                "silk": {
                  "uuid": "b09c4361-10da-4591-9221-81e9af52a389",
                  "slug": "m-yellow-silk"
                }
              }
            },
            "red": {
              "Material": {
                "cotton": {
                  "uuid": "bdca942a-a7c8-47a0-842a-161adeb69e71",
                  "slug": "m-red-cotton"
                },
                "silk": {
                  "uuid": "049c002d-ec84-4991-bf4b-5488637150dd",
                  "slug": "m-red-silk"
                }
              }
            }
          },
          "Material": {
            "cotton": {
              "Color": {
                "yellow": {
                  "uuid": "32977208-4d5e-4feb-8da0-5b85193fe782",
                  "slug": "m-yellow-cotton"
                },
                "red": {
                  "uuid": "bdca942a-a7c8-47a0-842a-161adeb69e71",
                  "slug": "m-red-cotton"
                }
              }
            },
            "silk": {
              "Color": {
                "yellow": {
                  "uuid": "b09c4361-10da-4591-9221-81e9af52a389",
                  "slug": "m-yellow-silk"
                },
                "red": {
                  "uuid": "049c002d-ec84-4991-bf4b-5488637150dd",
                  "slug": "m-red-silk"
                }
              }
            }
          }
        }
      },
      "Color": {
        "yellow": {
          "Size": {
            "S": {
              "Material": {
                "cotton": {
                  "uuid": "e62ea1a0-5aaf-4c5c-b3c9-b454543c5287",
                  "slug": "s-yellow-cotton"
                },
                "silk": {
                  "uuid": "4707f9bc-5a99-4ed3-b542-ef0324701057",
                  "slug": "s-yellow-silk"
                }
              }
            },
            "M": {
              "Material": {
                "cotton": {
                  "uuid": "32977208-4d5e-4feb-8da0-5b85193fe782",
                  "slug": "m-yellow-cotton"
                },
                "silk": {
                  "uuid": "b09c4361-10da-4591-9221-81e9af52a389",
                  "slug": "m-yellow-silk"
                }
              }
            }
          },
          "Material": {
            "cotton": {
              "Size": {
                "S": {
                  "uuid": "e62ea1a0-5aaf-4c5c-b3c9-b454543c5287",
                  "slug": "s-yellow-cotton"
                },
                "M": {
                  "uuid": "32977208-4d5e-4feb-8da0-5b85193fe782",
                  "slug": "m-yellow-cotton"
                }
              }
            },
            "silk": {
              "Size": {
                "S": {
                  "uuid": "4707f9bc-5a99-4ed3-b542-ef0324701057",
                  "slug": "s-yellow-silk"
                },
                "M": {
                  "uuid": "b09c4361-10da-4591-9221-81e9af52a389",
                  "slug": "m-yellow-silk"
                }
              }
            }
          }
        },
        "red": {
          "Size": {
            "S": {
              "Material": {
                "cotton": {
                  "uuid": "dd168086-1262-4627-a7e6-787c77aa4eb3",
                  "slug": "s-red-cotton"
                },
                "silk": {
                  "uuid": "c7ce66ff-8ee4-44fe-b553-617ce5e1aa0e",
                  "slug": "s-red-silk"
                }
              }
            },
            "M": {
              "Material": {
                "cotton": {
                  "uuid": "bdca942a-a7c8-47a0-842a-161adeb69e71",
                  "slug": "m-red-cotton"
                },
                "silk": {
                  "uuid": "049c002d-ec84-4991-bf4b-5488637150dd",
                  "slug": "m-red-silk"
                }
              }
            }
          },
          "Material": {
            "cotton": {
              "Size": {
                "S": {
                  "uuid": "dd168086-1262-4627-a7e6-787c77aa4eb3",
                  "slug": "s-red-cotton"
                },
                "M": {
                  "uuid": "bdca942a-a7c8-47a0-842a-161adeb69e71",
                  "slug": "m-red-cotton"
                }
              }
            },
            "silk": {
              "Size": {
                "S": {
                  "uuid": "c7ce66ff-8ee4-44fe-b553-617ce5e1aa0e",
                  "slug": "s-red-silk"
                },
                "M": {
                  "uuid": "049c002d-ec84-4991-bf4b-5488637150dd",
                  "slug": "m-red-silk"
                }
              }
            }
          }
        }
      },
      "Material": {
        "cotton": {
          "Size": {
            "S": {
              "Color": {
                "yellow": {
                  "uuid": "e62ea1a0-5aaf-4c5c-b3c9-b454543c5287",
                  "slug": "s-yellow-cotton"
                },
                "red": {
                  "uuid": "dd168086-1262-4627-a7e6-787c77aa4eb3",
                  "slug": "s-red-cotton"
                }
              }
            },
            "M": {
              "Color": {
                "yellow": {
                  "uuid": "32977208-4d5e-4feb-8da0-5b85193fe782",
                  "slug": "m-yellow-cotton"
                },
                "red": {
                  "uuid": "bdca942a-a7c8-47a0-842a-161adeb69e71",
                  "slug": "m-red-cotton"
                }
              }
            }
          },
          "Color": {
            "yellow": {
              "Size": {
                "S": {
                  "uuid": "e62ea1a0-5aaf-4c5c-b3c9-b454543c5287",
                  "slug": "s-yellow-cotton"
                },
                "M": {
                  "uuid": "32977208-4d5e-4feb-8da0-5b85193fe782",
                  "slug": "m-yellow-cotton"
                }
              }
            },
            "red": {
              "Size": {
                "S": {
                  "uuid": "dd168086-1262-4627-a7e6-787c77aa4eb3",
                  "slug": "s-red-cotton"
                },
                "M": {
                  "uuid": "bdca942a-a7c8-47a0-842a-161adeb69e71",
                  "slug": "m-red-cotton"
                }
              }
            }
          }
        },
        "silk": {
          "Size": {
            "S": {
              "Color": {
                "yellow": {
                  "uuid": "4707f9bc-5a99-4ed3-b542-ef0324701057",
                  "slug": "s-yellow-silk"
                },
                "red": {
                  "uuid": "c7ce66ff-8ee4-44fe-b553-617ce5e1aa0e",
                  "slug": "s-red-silk"
                }
              }
            },
            "M": {
              "Color": {
                "yellow": {
                  "uuid": "b09c4361-10da-4591-9221-81e9af52a389",
                  "slug": "m-yellow-silk"
                },
                "red": {
                  "uuid": "049c002d-ec84-4991-bf4b-5488637150dd",
                  "slug": "m-red-silk"
                }
              }
            }
          },
          "Color": {
            "yellow": {
              "Size": {
                "S": {
                  "uuid": "4707f9bc-5a99-4ed3-b542-ef0324701057",
                  "slug": "s-yellow-silk"
                },
                "M": {
                  "uuid": "b09c4361-10da-4591-9221-81e9af52a389",
                  "slug": "m-yellow-silk"
                }
              }
            },
            "red": {
              "Size": {
                "S": {
                  "uuid": "c7ce66ff-8ee4-44fe-b553-617ce5e1aa0e",
                  "slug": "s-red-silk"
                },
                "M": {
                  "uuid": "049c002d-ec84-4991-bf4b-5488637150dd",
                  "slug": "m-red-silk"
                }
              }
            }
          }
        }
      }
    }
```

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://wiki.theshop.dev/docs/frontstore/basic-selling-flow/product-detail/variants-tree.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
