# Mixin Schemas

The **Mixin Schemas** section allows extending entities in Management Dashboard, for example a product, with customized fields of different types.

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-c995d084313ba9dd5b0ba85e1d43cf888464e0f6%2Fmixinschemas.png?alt=media" alt="Mixin Schemas overview in Management Dashboard"><figcaption><p>Mixin Schemas overview in Management Dashboard</p></figcaption></figure>

## Creating a mixin schema

There are two ways to define a new schema in Management Dashboard:

* defining a schema manually
* uploading a JSON file

{% hint style="info" %}
In Management Dashboard, you can extend the data model for the following entities: cart, cart item, category, classification, company, coupon, custom entity, customer, customer address, order, order entry, price list, product, quote, return, site and vendor.
{% endhint %}

### Defining a schema manually

{% stepper %}
{% step %}

#### Choose to add a mixin schema

Go to **Settings** -> **Mixin Schemas** and choose **Add new mixin schema**.
{% endstep %}

{% step %}

#### Choose the entity

Select an entity or multiple entities that you want to customize from the dropdown menu and enter the name for the schema.\
You can also provide a key value for your new schema, which then works as its unique identifier. If you don't provide the key value on your own, it's generated automatically.

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-7913a67dd70d318ed2163219ff9c96ae8d5ea823%2Fcreatemixin.png?alt=media" alt="Choosing an entity and naming a new mixin schema"><figcaption><p>Choosing an entity and naming a new mixin schema</p></figcaption></figure>

{% hint style="warning" %}
The localized name you define for the schema later appears as a separate tab in the modified entity.
{% endhint %}
{% endstep %}

{% step %}

#### Save your configuration

Choose the **Confirm** button.
{% endstep %}

{% step %}

#### Define mixin fields

Go to **Fields** tab and choose **+** icon to add a mixin field.

* **Type**: Select a field type relevant to its purpose.

{% hint style="info" %}
The following field types are supported: array, boolean, date, date\_time, decimal, enum, number, object, text, and time.

The **array** mixin types support values of different types as well: boolean, date, date\_time, decimal, enum, number, object, text, and time.

Additionally, mixin schemas for **Custom Entities** support reference field types for establishing one-to-one relationship, and array of references for one-to-many relationships. The reference can point to any other custom entity type or to the following Emporix types: cart, category, customer, customer segment, classification, legal entity, media, order, price list, and product. When you create or edit a specific instance of such custom entity, you can select instances of referenced types.
{% endhint %}

* **Key**: Define a name of the field.
* **Name**: Provide the name to display and its translation in desired languages.
* **Array Type** (only for the **Array** type): Choose the relevant type of values in an array.
* **Values** (only for **Enum** type): Define the default values for the field. Confirm each value with **Enter** key.
* **Reference Type** (only for **Reference** type and **Reference** in **Array Type**): Select entity you want to establish reference to. This is supported for custom entity schemas only.
* Provide relevant configuration in **Settings**:
  * **Localized** (only for **Text** type): Decide whether the field is translated to other languages.
  * **ReadOnly**: Decide whether the field is non-editable.
  * **Required** (except for **Boolean** type): Decide whether the field is mandatory.
  * **Nullable**: Decide whether the field can accept `null` values.
  * **Array Localized** (only for **Text** in **Array Type**): Decide whether texts within the array are localized.
  * **Array Values** (only for **Enum** in **Array Type**): Define the default values for the field. Confirm each value with **Enter** key.

<div align="center"><figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-ec6f07f45a10440b2da01382bca0f6d794e15738%2Fmixin_addfield.png?alt=media" alt="Configuring basic settings for a mixin field"><figcaption><p>Configuring basic settings for a mixin field</p></figcaption></figure> <figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-4b58f3e7f29fceb16dcba344a3350a893df29223%2Fmixin_addfield_ref.png?alt=media" alt="Configuring reference settings for a mixin field"><figcaption><p>Configuring reference settings for a mixin field</p></figcaption></figure></div>
{% endstep %}

{% step %}

#### Save the fields

Save a field with **Confirm** button.

Repeat these steps to add as many fields as you require for the given entity.
{% endstep %}

{% step %}

#### Optional: Define object fields

If you've added fields of **object** type or of **array of objects** type, choose **+** icon within the given row to define the object's fields (only for **object** and **array of objects** types).

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-9d389d5eec126174ba959d0a5389dd0f9dbe1687%2Fmixin_addfields.png?alt=media" alt="Defining nested fields for object and array of objects mixin types"><figcaption><p>Defining nested fields for object and array of objects mixin types</p></figcaption></figure>
{% endstep %}

{% step %}

#### Save the schema

When you're done with defining mixin schema fields, confirm schema creation with **Save**. This action generates the schema for a particular entity or entities. You can already view the schema details in the Management Dashboard. If you need the JSON schema file, choose **Open Generated JSON** to access it.

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-81ffdb248ea3f56e5a3dc8d26b828ab489db3fdf%2Fmixin_schema_preview.png?alt=media" alt="Preview of a generated mixin schema"><figcaption><p>Preview of a generated mixin schema</p></figcaption></figure>
{% endstep %}
{% endstepper %}

**Result**: The new schema is in use. It means that if, for example, you've created a schema called *Size* for a product entity, next time you create or edit a product, the new fields are available in a *Size* tab.

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-41c4f64eac569f971908e1d4c3570a38a3fb0852%2Fproduct_mixin.png?alt=media" alt="Product detail view showing fields from an assigned mixin schema"><figcaption><p>Product detail view showing fields from an assigned mixin schema</p></figcaption></figure>

The schemas of **object** type display the defined objects as nested within a hierarchical structure:

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-609e710b21f7de5972a1d4738c9f1a9969180597%2Fproduct_objectmixin.png?alt=media" alt="Product mixin schema with object-type fields displayed as a hierarchy"><figcaption><p>Product mixin schema with object-type fields displayed as a hierarchy</p></figcaption></figure>

The schemas of **array of objects** type also allow for adding objects with the defined fields:

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-c8fa34fcdf4891244434677c673216d93c4793fc%2Fproduct_arraymixin.png?alt=media" alt="Product mixin schema with an array of objects and their defined fields"><figcaption><p>Product mixin schema with an array of objects and their defined fields</p></figcaption></figure>

### Uploading a JSON file

Updating schema by JSON file might be useful when you have an already defined data model.

{% hint style="info" %}
If you want to learn how to create JSON schema file, see [Prepare a JSON schema definition](https://app.gitbook.com/s/d4POTWomuSS7d3dnh4Dg/api-guides/utilities/schema/schema#prepare-a-json-schema-definition).
{% endhint %}

{% stepper %}
{% step %}

#### Choose to add new schema

Go to **Settings** -> **Mixin Schemas** and choose **Add new schema**.
{% endstep %}

{% step %}

#### Add a name for entity schema

Choose an entity or multiple entities that you want to customize from the dropdown menu and enter the name for the schema.
{% endstep %}

{% step %}

#### Add a mixin schema file

Choose the schema file from your device or drag and drop it to the selected area and choose **Confirm**.

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-3fecdf39d43f7d51cfea10903684196c740b0526%2Fmixins_json.png?alt=media" alt="Uploading a JSON file to create or update a mixin schema" width="463"><figcaption><p>Uploading a JSON file to create or update a mixin schema</p></figcaption></figure>
{% endstep %}

{% step %}

#### Save your changes

{% endstep %}
{% endstepper %}

**Result**: The new schema is in use. It means that if, for example, you've updated a schema for a product entity, next time you create a product, the new fields are available in a separate tab called the same as your schema.

## Editing mixin schemas

{% stepper %}
{% step %}

#### Choose to edit a schema

Go to **Settings** -> **Mixin Schemas** and select the schema you want to change. Choose the Edit icon to modify it.
{% endstep %}

{% step %}

#### Make the changes

Make changes to the schema or to particular fields in the schema:

* In **Schema** tab, you can select or unselect entities types you want to apply the schema to.
* In **Fields** tab, you can change settings for particular fields, add more or remove fields from the schema.
  {% endstep %}

{% step %}

#### Save your configuration

Confirm your changes with **Save** and confirm you want to update the existing schema.

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-50bc05f40f43261b9d2eb58834cdf12c49655c80%2Fmixin_newversion.png?alt=media" alt="Confirmation dialog for saving a new version of a mixin schema" width="375"><figcaption><p>Confirmation dialog for saving a new version of a mixin schema</p></figcaption></figure>
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
Each time you edit a schema, you generate its new version. This behavior is to prevent validation errors for the objects that were created/edited earlier and use the older schema versions. The latest schema version is always applied by default.
{% endhint %}

**Result**: A new version of the schema has been uploaded and is now in use.

{% hint style="info" %}
If you have a schema applied to multiple entities, it is possible to modify the schema for each entity separately. You need to select the entities you want your changes to apply to when editing the schema. Then, the new schema version is in use only for the selected entities while the other ones still use the previous version.
{% endhint %}

### Mixin schema versioning

When you edit a mixin schema that is already assigned to an entity, your changes become visible in the entity view.

For example, suppose you have a custom instance schema for mobile phones. If you update the schema to add new fields or modify existing field types, those changes automatically appear in the entity that uses the schema.

When a mixin schema is used in an entity, an indicator in the view displays the mixin schema version number.

Each time you update the mixin schema and open the entity that uses it, you can see which fields were added or modified. For instance, in the mobile phone instance schema below, the newly added and updated fields are highlighted accordingly - blue for new, yellow for the changed ones.

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-4e409d1a34488c9178c2804e322183baff58ae41%2Fmixins_version_1.png?alt=media" alt="Entity view showing newly added (blue) and modified (yellow) mixin fields"><figcaption><p>Entity view showing newly added (blue) and modified (yellow) mixin fields</p></figcaption></figure>

In this view, you can compare the current mixin schema version with the new one. You can either keep the old version, or decide to use the new one.

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-68dfdbb86a07f9a98d3da246b18078bc88765eff%2Fmixins_version_save.png?alt=media" alt="Preview and confirmation screen for applying an updated mixin schema version"><figcaption><p>Preview and confirmation screen for applying an updated mixin schema version</p></figcaption></figure>

New fields and updates are highlighted only if the instance already has previously saved mixin values. If the entity uses the same mixin schema but has no saved values, it automatically updates to the latest schema version without displaying a preview of the changes. For example:

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-f1643db1ba92b397b321920861afdc337257d124%2Fmixins_version_empty.png?alt=media" alt="Entity using a mixin schema without previously saved values, automatically updated to the latest version"><figcaption><p>Entity using a mixin schema without previously saved values, automatically updated to the latest version</p></figcaption></figure>

If you need a more detailed, technical comparison of all your changes, choose the **Technical** button. This opens a side-by-side comparison of the current and updated schemas in a JSON format. At the top, you can see a list of differences showing the unique keys of the newly added fields. The format of these keys depends on whether they were custom-defined or auto-generated.

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-d408de75b0954592f8e4e06a944a321003e710e9%2Fmixins_version_technical.png?alt=media" alt="Technical JSON diff view comparing current and updated mixin schemas"><figcaption><p>Technical JSON diff view comparing current and updated mixin schemas</p></figcaption></figure>

See other examples for Product and Customer entities:

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-dc34f8163745bda13e4637aa00a9c9a816b76e72%2Fmixins_version_product.png?alt=media" alt="Example of mixin schema versioning for a Product entity"><figcaption><p>Example of mixin schema versioning for a Product entity</p></figcaption></figure>

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-bb4217f8003f3886a4dc522cb4154df3f9712b31%2Fmixins_version_customer.png?alt=media" alt="Example of mixin schema versioning for a Customer entity"><figcaption><p>Example of mixin schema versioning for a Customer entity</p></figcaption></figure>

## Displaying mixins in entity list view

You can add a mixin field as a column in the list view of a selected entity. The mixin field can serve as a filter so that you can find the items of your interest.

{% stepper %}
{% step %}

#### Choose to customize your view

Go to the selected entity view and choose the **Orchestration** icon.

<div align="left"><figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-7cfcfdf2cec4c375b7575ad6c176c07374395af1%2Forchestration.png?alt=media" alt="Orchestration icon for customizing the entity list view"><figcaption><p>Orchestration icon for customizing the entity list view</p></figcaption></figure></div>
{% endstep %}

{% step %}

#### Choose the mixins

In the **Mixins** section, look for the mixin fields you want to add as filter columns. Or, choose **Add custom mixin** to add a new mixin field.

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-c433ed7b39d60d69c753ad11a8ff56865dd83344%2Forders_mixins.png?alt=media" alt="Selecting mixin fields to add as list view columns and filters" width="200"><figcaption><p>Selecting mixin fields to add as list view columns and filters</p></figcaption></figure>

The selected mixin fields appear in the list.

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-4a1f7da64ce70180d02b74b17709bf63aeab12f4%2Fcolumns_mixins.png?alt=media" alt="Entity list view with mixin columns added" width="200"><figcaption><p>Entity list view with mixin columns added</p></figcaption></figure>
{% endstep %}

{% step %}

#### Adjust the way how the columns are displayed

Use the **Edit** icon. You can edit the displayed label of the mixin column.

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-5fa1f615b2be7e17f81b7b627c21d98454ae7b0f%2Fmixin_column_edit.png?alt=media" alt="Editing the label of a mixin field column in the list view" width="375"><figcaption><p>Editing the label of a mixin field column in the list view</p></figcaption></figure>
{% endstep %}

{% step %}

#### Save the selection

The columns appear instantly in the entity list view.
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
Only the mixins defined in the Schema Service can serve as column filters. If you use the API to create mixins instead of the Schema Service, you won't be able to add the mixin fields from the API upload. To get around this, first define the mixin fields for a given entity in the Schema Service.

Adding mixins as column filters is possible for the following entities: cart, category, classification, company, coupon, custom entity, customer, customer address, order, order entry, price list, product, quote, and return.
{% endhint %}

## Unassigning a schema

If you no longer want to apply the latest version of a schema to an entity, you can unassign it.

{% stepper %}
{% step %}

#### Select the schema

Go to **Settings** -> **Mixin Schemas** and select the schema you want to remove from an entity.
{% endstep %}

{% step %}

#### Choose **Unassign** icon

Choose the icon to remove the connection between the latest schema version and entity.

<div align="left"><figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-22aed7e260f3935b6fd14ff56104630f6dec3cb2%2Funassign_icon.png?alt=media" alt="Unassign icon used to detach a schema from an entity" width="111"><figcaption><p>Unassign icon used to detach a schema from an entity</p></figcaption></figure></div>
{% endstep %}

{% step %}

#### Confirm the action

Choose **Yes** to confirm, or **Cancel** to keep the assignment.

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-a0640d805e865b3d86d70142d4db015ca9f7228c%2Fmixin_unassign.png?alt=media" alt="Confirmation dialog for unassigning a schema from an entity" width="375"><figcaption><p>Confirmation dialog for unassigning a schema from an entity</p></figcaption></figure>
{% endstep %}
{% endstepper %}

**Result**: The particular entity uses the previous version of the schema that exists in the database. If you had only one schema version and you unassign it from an entity, the schema tab is no longer visible when you create or edit objects of that type.

{% hint style="warning" %}
The unassigned schemas are not displayed in the Management Dashboard. To retrieve, edit or delete an unassigned schema, use API mechanism. See more in [Schema Service](https://app.gitbook.com/s/d4POTWomuSS7d3dnh4Dg/api-guides/utilities/schema).
{% endhint %}
