Hello everyone,
I’m working on a PIM project where I need to associate multiple specifications with a product (using a M2M
field to a specifications
collection). Each specification can have multiple possible values.
Example:
- Product: Water Bottle
- Specifications: Volume, Weight, Dimensions
- Values: 1L, 2L, 1Kg, 2Kg, 30cm x 10cm
For each specification linked to a product, I want to:
- Select a predefined value from a list (e.g., 1L, 2L)
- Or enter a custom value (e.g., a specific dimension)
My questions are:
- Is it possible to achieve this logic using only the default fields and interfaces in Directus?
- If not, would a custom component or extension be required to enable this kind of dynamic value selection?
- Do you have any examples or recommended workflows for this setup?
I absolutely need to be able to:
- Select multiple specifications
- Assign a value to each of these specifications (ideally non-duplicated and reusable across multiple products)
- Do all of this in a single step, directly from the product page
- Create a value on the fly if it doesn’t already exist
- Prevent duplication
Optional:
- Use specific units related to the specification (for example, for volume, only display values where the unit is relevant to volume)
Thanks a lot for your insights!
You can model this relationship easily in Directus and there’s multiple ways you could do it.
When possible, I usually prefer to add the specifications
directly to a product.
You can check out the Simple eCommerce template inside the demo for an example of this. You can find this one in the Community Templates when running npx directus-template-cli@latest apply
as well.
The fields for size
and color
are added on the product
and then there’s a flow that creates variants for the different combinations.
This is a simple setup and fairly easy to reason about as well. Also a nice part of using Directus as a PIM is that you can just create new structures as needed as opposed to being restricted to the structure and relationships other tools provide you with.
If you have a bunch of different attributes or specifications that don’t really apply (let’s say you’re tracking tons of the different ‘product types’) then using a junction collection like you’ve described is a good way to go.
If you want to reuse the specifications AND the values over again across different products - you’d probably end up taking it further with a specification_values
collection that stores the actual value and the id of the specification
in a M2O.
If you go that route, I’d probably consider a custom Interface extension to make this process a little easier UI / UX wise for the end user, because right now you have to add the M2M relationship because you can start to edit values from the junction collection. This is a little clunkier than I’d like for this sort of use.
The Multilevel Autocomplete Interface extension from our directus-labs/extensions repo might be a good one to reference as a starting point.