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

Utilities: Extra fields

Create new fields to extend standard MiniShop3 models.

Purpose

Add custom fields to data models without editing source code. Fields are stored in the database and appear automatically in the interface.

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
KeyUnique field name (Latin, snake_case)Yes
LabelDisplay nameYes
DescriptionUser hintNo
ActiveField in useYes

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
textareaMultiline fieldDescriptions
xcheckboxCheckboxYes/No
ms3-combo-vendorVendor pickerLink to vendor
ms3-combo-autocompleteAutocompletePick from list
ms3-combo-optionsOption pickerProduct variants

Database type (dbtype)

TypeDescriptionExample values
varcharVariable-length stringText up to 255 chars
textLong textDescriptions, HTML
intIntegerIDs, quantities
decimalDecimalPrices with cents
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 — max 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 and 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 (ERP)

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

Delivery lead time

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 a row in the table to open the edit dialog.

Limitations

Some parameters cannot change after creation:

  • Field key
  • Database type (dbtype)

To change these, delete the field and create it again.

Deleting a field

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

Warning

Deleting a field permanently removes:

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

Use in code

Getting a 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 a 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

Model field list

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 a field is created the system automatically:

  1. Creates a record in the field configuration table
  2. Adds a column to the model table (ALTER TABLE)
  3. Creates an index (if specified)

When a field is deleted:

  1. Removes the configuration record
  2. Drops the column from the database table