> ## Documentation Index
> Fetch the complete documentation index at: https://docs-loja.usecorvex.com.br/llms.txt
> Use this file to discover all available pages before exploring further.

# Product customization

> Campos de personalização do produto (nome na camisa, texto, select, imagem).

Personalização configurada no dashboard (**Produtos → Customizações**) e ligada a um ou mais produtos. A API pública devolve os campos no **detalhe** do produto; o cliente preenche na PDP e envia as respostas no `addItem`.

Fonte normativa: `ProductCustomization`, `CartCustomizationAnswer`, `CartLineCustomization` em `@corvex/theme-sdk` types.

***

## Disponível em

* `usePage('product').product.customizations`
* `storefront.products.get(id)` / `getByHandle(handle)` → `product.customizations`
* Linha do carrinho: `cart.items[n].customizations` (snapshot após o `addItem`)
* Upload IMAGE (cliente): `storefront.customizations.upload(file)`

Listagens (`products.list`, cards) **não** garantem `customizations`. Use o detalhe do produto na PDP.

***

## ProductCustomization

| Campo | Tipo | Descrição |
| - | - | - |
| `id` | `string` | UUID do campo — use como `customizationId` no `addItem` |
| `name` | `string` | Rótulo (ex.: `Nome`) |
| `type` | `'TEXT' \| 'SELECT' \| 'IMAGE'` | Tipo do input |
| `required` | `boolean` | Obrigatório (já considera `allowPurchaseWithout` do vínculo) |
| `additionalPrice` | `number` | Acréscimo base (BRL) |
| `placeholder` | `string \| null` | Placeholder do input |
| `helpText` | `string \| null` | Texto de ajuda |
| `minLength` / `maxLength` | `number \| null` | Limites para `TEXT` |
| `maxFileSizeMb` | `number \| null` | Limite para `IMAGE` (upload) |
| `allowPurchaseWithout` | `boolean` | Loja permite comprar sem preencher |
| `options` | `{ id, label, additionalPrice }[]` | Só para `SELECT` — `value` do addItem = `option.id` |

Array vazio (`[]`) quando o produto não tem personalização ativa.

***

## Respostas no carrinho

| Campo (answer) | Tipo | Descrição |
| - | - | - |
| `customizationId` | `string` | `ProductCustomization.id` |
| `value` | `string` | Texto; para `SELECT` = id da opção; para `IMAGE` = URL `https` (via `customizations.upload`) |

Após o add, a linha traz snapshots:

| Campo | Tipo |
| - | - |
| `id` / `name` / `type` | espelho do campo |
| `value` | valor enviado |
| `displayValue` | rótulo legível (ex.: label da opção) |
| `additionalPrice` | acréscimo aplicado na linha |

***

## Exemplo — PDP

```jsx theme={"theme":{"light":"github-light","dark":"github-dark"}}
import { usePage, useCorvexCart } from '@corvex/theme-sdk';
import { useState } from 'react';

export default function ProductPersonalization() {
  const { product } = usePage('product');
  const { addItem, mutating } = useCorvexCart();
  const [values, setValues] = useState({});

  if (!product.customizations?.length) return null;

  async function handleAdd() {
    const answers = product.customizations.map((field) => ({
      customizationId: field.id,
      value: values[field.id] ?? '',
    }));
    await addItem(product, 1, null, answers);
  }

  return (
    <div>
      {product.customizations.map((field) => (
        <label key={field.id}>
          {field.name}
          {field.required ? ' *' : ''}
          <input
            value={values[field.id] ?? ''}
            placeholder={field.placeholder || undefined}
            maxLength={field.maxLength || undefined}
            onChange={(e) =>
              setValues((prev) => ({ ...prev, [field.id]: e.target.value }))
            }
          />
          {field.helpText ? <span>{field.helpText}</span> : null}
        </label>
      ))}
      <button type="button" disabled={mutating} onClick={handleAdd}>
        Adicionar ao carrinho
      </button>
    </div>
  );
}
```

## Upload IMAGE

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
const storefront = useStorefront();
const { url } = await storefront.customizations.upload(file);
await addItem(product, 1, variant, [
  { customizationId: field.id, value: url },
]);
```

| | |
| - | - |
| Método | `storefront.customizations.upload(file, options?)` |
| `file` | `File` ou `Blob` (só no **cliente**) |
| `options.fileName` | opcional se o Blob não tiver `.name` |
| Retorno | `{ url: string, fileName: string \| null }` |
| Backend | `POST /public/stores/:storeId/product-customizations/upload` (multipart campo `file`) |

JPG / PNG / WEBP. Backend limita a 5MB; respeite também `field.maxFileSizeMb` quando vier preenchido.

Cookbook: [Product customization](https://docs-loja.usecorvex.com.br/cookbook/product-customization.md). Carrinho: [Cart actions](https://docs-loja.usecorvex.com.br/data/actions/cart.md).

***

## Pitfalls

* **Campos obrigatórios** — o backend rejeita `addItem` sem resposta válida (`400`). Valide no tema antes de chamar.
* **SSR** — `customizations` vem no GET do produto; inputs, estado e `customizations.upload` ficam no cliente (`File`/`Blob`).
* **SELECT** — envie o **id** da opção, não o `label`.
* **IMAGE** — use `storefront.customizations.upload(file)` e passe `url` como `value`. Não monte o `fetch` multipart à mão.
* **Preço** — não some `additionalPrice` no cliente para cobrar; o backend inclui no `unitPrice` da linha.
* **Mesclar linhas** — mesma variante + mesmas respostas = quantidade somada; respostas diferentes = linhas distintas.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.