Skip to main content

Attributes and Types Overview

An attribute is a reusable field that can be assigned to a product or a variant, similar to fields in a CMS.

Here is an overview of all possible attribute types:

NameDescriptionExample
DropdownList of predefined choices; rendered as a single-select dropdown.Store a color of a variant with predefined choices: orange, black, blue, etc.
MultiselectList of predefined choices; rendered as a multi-select dropdown.Add multiple tags to a product or a page.
FileAllows to store a file as an attribute value; rendered as a file input.Store a product manual as a PDF file; store a hero image for a page.
ReferenceValues are references to other entities such as products, variants, pages, collections or categories.Render a list of related products on a product page.
Single referenceStores a reference to other entity such as product, variant, page, collection or category.Render a related collection on a product page.
NumericValues are numbers; optionally, a unit can be provided to represent measures and dimensions.Dimensions of a product represented with three numeric attributes: length, width, and depth.
Rich textValue is stored as rich-text content; rendered as a rich-text editor.Additional content blocks for a page or product.
Plain textValue is stored as plain text; rendered as a text input.Stores unformatted text for simple labels, e.g., "Material: 100% Cotton".
SwatchStores a color code or an image.Stores a color or an image to visually represent options like colors or patterns.
BooleanAllows storing boolean values.Yes/no properties, e.g., "Product is fair trade certified: yes/no".
DateAllows storing date values.Store release date of a product.
Date timeAllows storing date-time values.Store release date with the time of a product.

Reference attributes with restricted choices​

You can restrict the allowed target types for Reference and Single reference attributes.

  • For PRODUCT and PRODUCT_VARIANT reference attributes (reference attributes with PRODUCT or PRODUCT_VARIANT entity type), define the allowed product types.
  • For PAGE reference attributes (reference attributes with PAGE entity type), define the allowed page types.
  • Category and collection reference attributes (reference attributes with CATEGORY or COLLECTION entity type) do not support restricting choices.

Configure these constraints on the attribute using the AttributeCreate or AttributeUpdate mutation by providing the referenceTypes field.

When assigning a reference attribute value to a product, variant, or page, if the target does not match one of the allowed types, a validation error is returned.

note

Changing the allowed reference types does not modify existing references.

If you clear the allowed types, updates to existing references and any newly provided references will no longer be validated against types.

See the guide on configuring reference attributes with restricted choices.

Product and Content Types​

A type is a collection of attributes that make up the shape of data in a product or a content block.

Reusable attributes​

Each attribute configuration is reusable across different product types, which is convenient when managing them across multiple products.

For example attribute T-shirt Size might have range of values S - L where is attribute Shoe Size have 34-46, therefore they can be used in different product types without creating attribute from scratch in each flavor of Shoe or T-shirt product type.

Using dropdown attributes can also help to maintain consistency across the store.

Attributes vs. Metadata Difference​

Saleor uses both Attributes and Metadata in various places. Attributes have a strict structure with data types, validation, schema etc. Metadata is a simple key: value structure without types. You might wonder, do we need both? Or which should I use where?

Attributes:

  • intended to be filled in by people
  • strictly typed
  • the schema is strict so that the storefront can depend on this value being of a specific shape e.g. a field for number of pages will not contain a photo of jeans
  • attributes are typically used in the UI layer, presented to customers, merchandisers, or admins

Metadata:

  • intended to be filled by an app, an automation or integration through the API
  • validation should happen in unit tests of the app
  • metadata has no schema so that it doesn’t require a human to change how the code is operating with them