> For the complete documentation index, see [llms.txt](https://partners.tray.com.br/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://partners.tray.com.br/themes/construindo-seu-template/referencias/funcoes/products.md).

# Products()

A função `Products()` retorna os produtos cadastrados na loja.

{% hint style="info" %}
**Disponível em todas as páginas.**\
**Para saber mais sobre como gerenciar produtos acesse** [Cadastrar Produto](https://basedeconhecimento.tray.com.br/hc/pt-br/articles/6732451110171-Cadastrar-Produto)
{% endhint %}

As requisições de produtos sempre retornarão um array de dados.

É possível aplicar filtros a essa função para que ela retorne apenas os produtos desejados.\
Segue abaixo a relação de filtros disponíveis:

| Filtro       | Parametro                                                                                                      |      |                |              |                      |
| ------------ | -------------------------------------------------------------------------------------------------------------- | ---- | -------------- | ------------ | -------------------- |
| `filter`     | <p>O filtro <code>filter</code> pode receber os seguintes parâmetros:<br><code>featured                        | new  | free\_shipping | available    | promotion</code></p> |
| `limit`      | Recebe um valor da qual será a quantidade maxima de produtos.                                                  |      |                |              |                      |
| `order`      | <p>O filtro order é usado para ordernar a lista de produtos, pode receber os seguintes parâmetros:<br><code>id | name | price          | price\_offer | stock</code></p>     |
| `categories` | O filtro `categories` Recebe o id das categorias da qual deseja filtrar os produtos.                           |      |                |              |                      |
| `brands`     | O filtro `brands` Recebe o nome da marca da qual deseja filtrar os produtos.                                   |      |                |              |                      |

## Como Usar

Abaixo alguns exemplos de utilização da função `Products()` para exibir todos os produtos da loja.

Retorna um array com todos os produtos da loja

```twig
{% set products = Products() %}
```

A chamada abaixo retornará até 8 produtos em destaque ordenados pelos mais vendidos que estejam cadastrados nas categorias 1 e 2 e tenham como marca "Tray".

```twig
{% set products = Products({
   'filter': 'featured',
   'limit': 8,
   'order': {'quantity_sold': 'desc'},
    'categories': [2, 3],
   'brands': 'Tray'
}) %} 
```

É possível também realizar múltiplas ordenações, conforme exemplo:

```twig
{% set products = Products({
    'order': {
        'quantity_sold': 'desc',
        'name': 'asc',
        'id': 'desc'
    }
}) %}  
```

A chamada abaixo retornará até 4 produtos que estejam disponíveis para venda e ordenados pelos mais vendidos.

```twig
{% set products = Products({
   'filter': 'available',
   'limit': 4,
   'order': {'quantity_sold': 'desc'}
}) %} 
```


---

# 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://partners.tray.com.br/themes/construindo-seu-template/referencias/funcoes/products.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.
