vendure-ecommerce/vendure

Implement relational structured data for products

Opened this issue · 1 comments

Is your feature request related to a problem? Please describe.
I am working on a pet food store (yes, really). I would like to be able to attach structured and relational data for my products. For example, I would like to be able to provide a table with two columns (ingredient name and composition percentage), instead of writing this data in an unstructured manner in the description.

image

Describe the solution you'd like
It would be great if the Admin UI could allow to provide custom components not just for custom fields but also for entities. (something similar to what is discussed here https://docs.vendure.io/guides/extending-the-admin-ui/custom-form-inputs/#custom-field-controls-for-relations)

Describe alternatives you've considered
For now, I have implemented a hack consisting of a component that saves my data as stringified JSON. However, although this does the job, there are negative implications to having the data unstructured.

Additional context
The original thread where this feature was discussed and requested: https://discord.com/channels/1100672177260478564/1252882486342582353

Idea: Struct custom field type

I've had this idea for a while: a new type for custom fields which is named "struct". The naming open for debate - there might be a better word like "object" or something. Anyway, I'll use "struct" for now.

It would be defined like this:

const config = {
    // ...
    customFields: {
        Product: [
            {
                name: 'composition',
                type: 'struct',
                fields: [
                    { name: 'ingredient', type: 'string' },
                    { name: 'compositionPercentage', type: 'float' },
                ],
            },
        ],
    },
};

When using the struct type, you are then required to define the fields array, which specifies the properties on that struct.

The fields would be like a subset of the custom field definition, allowing only primitive types: string, text, int, float, datetime, because internally this will get serialized into a JSON string.

It will not support localized strings or relation types, as these cannot easily be serialized into a JSON string.

It may support lists of those primitive types, but this is subject to more investigation on how complex this would be to support.

The Admin UI would understand how to render inputs for the struct type, and individual fields could also have custom ui components defined just like regular custom fields.