Open MercatoDocsSearch docsAPI reference

Customization

Custom fields at a glance

A distributor might ask for a supplier code on each product while another wants a handling note. Add a field to the existing record when it has one value for that record. Ship its definition in code if every installation of your module needs it.

Open Mercato ships with a universal custom-fields system. Administrators can add metadata to any entity without touching code, while developers can commit the same definitions to version control.

Custom fields definition screen

Point-and-click configuration

Code-first definitions

Mirror the admin configuration by exporting entities from ce.ts within your module:

import { defineFields, cf } from '@open-mercato/core/modules/dsl';

export const entities = [
  {
    id: 'inventory:item',
    fields: defineFields([
      cf.text('bin_location', { label: 'Bin Location' }),
      cf.boolean('is_fragile', { label: 'Fragile' }),
    ]),
  },
];

Run yarn mercato entities install --module inventory --org <organizationId> to apply changes across environments. The admin UI will show the new fields alongside those created interactively.

Managing fieldsets via API

When entities need different attribute “palettes” (e.g., catalog products with Fashion vs. Services fieldsets) you can configure the selector programmatically. Call the Entities API endpoint POST /api/entities/definitions.batch with two keys:

curl -X POST "$BASE_URL/entities/definitions.batch" \
  -H "X-Api-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"entityId\": \"customers:person\",
    \"definitions\": [
      { \"key\": \"preferred_contact_method\", \"kind\": \"enum\", \"configJson\": { \"options\": [\"email\", \"phone\", \"sms\"], \"fieldset\": \"customer_profile\", \"group\": { \"code\": \"preferences\" } } }
    ],
    \"fieldsets\": [
      {
        \"code\": \"customer_profile\",
        \"label\": \"Customers · Profile\",
        \"icon\": \"lucide:user\",
        \"groups\": [
          { \"code\": \"identity\", \"title\": \"Identity\" },
          { \"code\": \"preferences\", \"title\": \"Preferences\" }
        ]
      }
    ],
    \"singleFieldsetPerRecord\": true
  }"

This request updates both the definitions and the curated list of fieldsets so CRUD forms immediately expose the new tab/dropdown. See Entities API → Field definitions for more parameters and scopes.

Decide who owns the definition

An extra delivery reference used by one tenant can be configured in the admin. A field required by every installation of a shipping module belongs in its code-defined defaults. In both cases, test saving and reopening a record with the value present and with it empty.

Previous: Create the data structures · Next: Add inventory forms