Skip to content
  1. Extras
  2. MiniShop3
  3. Manager interface
  4. Utilities
  5. TV fields

Utilities: Extra fields

Creating new fields to extend MiniShop3 standard models.

Purpose

The tool lets you add custom fields to data models without editing source code. Fields are stored in the database and shown in the interface automatically.

Supported models

ModelDescription
msProductDataProduct data
msVendorVendor
msOrderOrder
msOrderAddressDelivery address
msCategoryCategory

Creating a field

Step 1: Select model

Choose a model from the dropdown at the top of the page.

Step 2: Add field

Click "Add field" and fill the form.

Field parameters

Basic

ParameterDescriptionRequired
Key (key)Unique field name (Latin, snake_case)Yes
Label (label)Display nameYes
DescriptionHint for userNo
ActiveField is usedYes

Field key

The key must be unique within the model. Use Latin letters and underscores. Examples: wholesale_price, external_id, custom_field.

Widget type (xtype)

TypeDescriptionUse
textfieldText fieldStrings, SKUs
numberfieldNumber fieldPrices, quantities
textareaMulti-line fieldDescriptions
xcheckboxCheckboxYes/No
ms3-combo-vendorVendor selectionVendor relation
ms3-combo-autocompleteAutocompleteList selection
ms3-combo-optionsOption selectionProduct variants

Database type (dbtype)

TypeDescriptionExample values
varcharVariable-length stringText up to 255 chars
textLong textDescriptions, HTML
intIntegerIDs, quantities
decimalDecimal numberPrices with decimals
tinyintSmall integer (0-255)Flags, ratings
datetimeDate and time2024-01-15 12:30:00
timestampTimestampUnix timestamp
jsonJSON dataArrays, objects

Precision

For varchar and decimal:

  • varchar — maximum string length (default 255)
  • decimal — format 10,2 means 10 digits total, 2 after decimal

PHP type (phptype)

TypeDescription
stringString
integerInteger
floatFloat
booleanBoolean
jsonJSON (auto encode/decode)
datetimeDateTime object
timestampUnix timestamp

Default value

TypeDescription
NULLEmpty value
CURRENT_TIMESTAMPCurrent time (for datetime)
USER_DEFINEDSet manually
NONENo default

Indexing

TypeDescriptionWhen to use
NONENo indexRarely used fields
INDEXRegular indexSearch/sort fields
UNIQUEUnique indexUnique values
FULLTEXTFull-text indexText search

Field examples

Wholesale price

Key: wholesale_price
Label: Wholesale price
xtype: numberfield
dbtype: decimal
Precision: 12,2
phptype: float
Default: NULL
Index: NONE

External ID (1C)

Key: external_id
Label: 1C ID
xtype: textfield
dbtype: varchar
Precision: 50
phptype: string
Default: NULL
Index: UNIQUE

Delivery days

Key: delivery_days
Label: Delivery time (days)
xtype: numberfield
dbtype: int
phptype: integer
Default: USER_DEFINED → 3
Index: NONE

Extra attributes (JSON)

Key: extra_attributes
Label: Extra attributes
xtype: textarea
dbtype: json
phptype: json
Default: NULL
Index: NONE

Editing a field

Click the field row in the table to open the edit dialog.

Limitations

Some parameters cannot be changed after creation:

  • Field key
  • Database type (dbtype)

To change these, delete the field and create a new one.

Deleting a field

  1. Click the delete icon on the field row
  2. Confirm in the dialog

Warning

Deleting a field permanently removes:

  • Field definition from schema
  • Column from database table
  • All data in that field for all records

Using in code

Getting value

php
// Get product
$product = $modx->getObject(\MiniShop3\Model\msProduct::class, $id);

// Get product data
$data = $product->getOne('Data');

// Get extra field value
$wholesalePrice = $data->get('wholesale_price');

Saving value

php
$data = $product->getOne('Data');
$data->set('wholesale_price', 999.99);
$data->save();

In snippets (Fenom)

fenom
{$wholesale_price}
{if $wholesale_price > 0}
    <span class="wholesale">Wholesale: {$wholesale_price | number_format : 0}</span>
{/if}

API Endpoints

List model fields

GET /api/mgr/extra-fields?class=MiniShop3\Model\msProductData

Create field

POST /api/mgr/extra-fields

Request body:

json
{
  "class": "MiniShop3\\Model\\msProductData",
  "key": "wholesale_price",
  "label": "Wholesale price",
  "xtype": "numberfield",
  "dbtype": "decimal",
  "precision": "12,2",
  "phptype": "float",
  "null": true,
  "default": "NULL",
  "index_type": "NONE",
  "active": true
}

Update field

PUT /api/mgr/extra-fields/{id}

Delete field

DELETE /api/mgr/extra-fields/{id}

Migrations

When creating a field:

  1. A record is added to the field config table
  2. A column is added to the model table (ALTER TABLE)
  3. An index is created (if specified)

When deleting a field:

  1. Config record is removed
  2. Column is dropped from the database table