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

Utilities: Extra fields ​

Custom columns on MiniShop3 models without editing the core. The field is written to the DB and appears in Manager forms.

Cookbook

Step-by-step cases (order, repeater, key-value): Extra fields cookbook. Examples: order field, product wholesale price.

Purpose ​

You create a key, widget type, and column type. After the column migration applies, the field is available on the model card and (for products) in CSV import.

Supported models ​

In the UI you pick a short name; the DB and POST store the full MiniShop3\Model\... class.

Short nameClass in API / DBDescription
msProductMiniShop3\Model\msProductProduct resource
msProductDataMiniShop3\Model\msProductDataProduct data
msCategoryMiniShop3\Model\msCategoryCategory
msVendorMiniShop3\Model\msVendorVendor
msOptionMiniShop3\Model\msOptionOption
msLinkMiniShop3\Model\msLinkLink type
msOrderMiniShop3\Model\msOrderOrder
msOrderAddressMiniShop3\Model\msOrderAddressDelivery address
msOrderProductMiniShop3\Model\msOrderProductOrder line
msOrderStatusMiniShop3\Model\msOrderStatusOrder status
msCustomerMiniShop3\Model\msCustomerCustomer
msCustomerAddressMiniShop3\Model\msCustomerAddressCustomer address
msDeliveryMiniShop3\Model\msDeliveryDelivery
msPaymentMiniShop3\Model\msPaymentPayment

Extra-fields CRUD requires mssetting_save. The order card also calls GET /extra-fields on load: without that permission widget metadata will not load (column values still arrive in GET /orders/{id}).

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-selectFixed selectStatus, delivery type
ms3-combo-vendorVendor pickerLink to vendor
ms3-combo-autocompleteAutocompletePick from list
ms3-combo-optionsOption pickerProduct variants
ms3-repeaterRow table (JSON)Specs, list characteristics
ms3-key-valueKey → value (JSON)Named property set

Repeater (ms3-repeater) ​

Since v1.12. In properties / widget config set repeater_config:

json
{
  "columns": [
    { "key": "name", "label": "Name" },
    { "key": "qty", "label": "Qty", "type": "number" }
  ],
  "minRows": 0,
  "maxRows": 50,
  "sortable": true,
  "rankField": "rank"
}

In the DB the column is usually json. Repeater is not included in CSV import.

Key-value (ms3-key-value) ​

Config key_value_config:

json
{
  "mode": "fixed",
  "keys": [
    { "key": "width", "label": "Width", "valueType": "number", "required": false },
    { "key": "material", "label": "Material", "valueType": "string", "required": true }
  ]
}

mode: fixed (only defined keys) or free (customer/manager adds pairs).

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