Magento 2 EAV & Attributes
Before writing code
Fetch live docs:
- Web-search
site:developer.adobe.com commerce php development components attributes for attribute development guide
- Web-search
site:developer.adobe.com commerce php tutorials backend custom-attributes for attribute creation tutorial
- Web-search
magento 2 EAV attribute data patch for current patterns using data patches
Conceptual Architecture
What EAV Is
Entity-Attribute-Value is Magento's flexible storage pattern. Instead of one column per attribute, values are stored in separate typed tables. This allows merchants to add unlimited attributes without schema changes.
EAV Entities
Four entity types use EAV:
- Products (
catalog_product_entity)
- Categories (
catalog_category_entity)
- Customers (
customer_entity)
- Customer Addresses (
customer_address_entity)
EAV Table Structure
Each entity has typed value tables:
*_entity — base entity table (entity_id, sku, type_id, etc.)
*_entity_varchar — short text values
*_entity_int — integer values (including boolean, select)
*_entity_decimal — decimal/price values
*_entity_datetime — date/time values
*_entity_text — long text values
Attribute Properties
Key properties when creating attributes:
- type — backend storage type (varchar, int, decimal, datetime, text, static)
- input — frontend input type (text, textarea, select, multiselect, boolean, date, price, media_image, etc.)
- label — human-readable name
- required — is this attribute mandatory?
- source — source model for select/multiselect options
- backend — backend model for validation/processing
- frontend — frontend model for display formatting
- global — scope: store view, website, or global
- visible — shown in admin forms
- searchable — indexed for catalog search
- filterable — available as layered navigation filter
- comparable — shown in product comparison
- used_in_product_listing — available in category listing pages
Attribute Sets and Groups
- Attribute Set — a named collection of attributes (e.g., "Default", "Clothing", "Electronics")
- Attribute Group — organizes attributes within a set into tabs (e.g., "General", "Prices", "Images")
- Every product is assigned one attribute set
- The Default attribute set contains core attributes
Creating Attributes via Data Patch
The modern approach uses Data Patches with EavSetupFactory:
- Create a data patch class in
Setup/Patch/Data/
- Inject
EavSetupFactory (or CategorySetupFactory for categories)
- Call
$eavSetup->addAttribute() with entity type, code, and properties
- Assign to attribute set/group
Source Models
For select/multiselect attributes, source models provide options:
- Built-in:
Magento\Eav\Model\Entity\Attribute\Source\Boolean, Table
- Custom: extend
AbstractSource, implement getAllOptions()
Static Attributes
Attributes with type static are stored as columns directly on the entity table rather than in EAV value tables. Used for frequently queried fields (e.g., sku, type_id, created_at).
Best Practices
- Use data patches (not install/upgrade scripts) for attribute creation
- Choose the correct backend type —
int for select/boolean, decimal for prices
- Set
searchable, filterable, comparable thoughtfully — each adds indexing overhead
- Use
static type sparingly — it modifies the entity table schema
- Test attribute creation on a clean install and with
setup:upgrade
Fetch the attribute development docs for exact addAttribute() parameters, source model patterns, and current entity type constants before implementing.
1---2name: magento-eav-attributes3description: Work with Magento 2 EAV (Entity-Attribute-Value) system — create custom attributes, attribute sets, manage EAV tables, and understand the EAV data model. Use when adding product/category/customer attributes or working with the attribute system.4allowed-tools: Read, Write, Edit, Bash, Grep, Glob, WebSearch, WebFetch5metadata:6 source: https://skillmd.com/skills/orcaqubits/magento-eav-attributes7---89# Magento 2 EAV & Attributes1011## Before writing code1213**Fetch live docs**:141. Web-search `site:developer.adobe.com commerce php development components attributes` for attribute development guide152. Web-search `site:developer.adobe.com commerce php tutorials backend custom-attributes` for attribute creation tutorial163. Web-search `magento 2 EAV attribute data patch` for current patterns using data patches1718## Conceptual Architecture1920### What EAV Is2122Entity-Attribute-Value is Magento's flexible storage pattern. Instead of one column per attribute, values are stored in separate typed tables. This allows merchants to add unlimited attributes without schema changes.2324### EAV Entities2526Four entity types use EAV:27- **Products** (`catalog_product_entity`)28- **Categories** (`catalog_category_entity`)29- **Customers** (`customer_entity`)30- **Customer Addresses** (`customer_address_entity`)3132### EAV Table Structure3334Each entity has typed value tables:35- `*_entity` — base entity table (entity_id, sku, type_id, etc.)36- `*_entity_varchar` — short text values37- `*_entity_int` — integer values (including boolean, select)38- `*_entity_decimal` — decimal/price values39- `*_entity_datetime` — date/time values40- `*_entity_text` — long text values4142### Attribute Properties4344Key properties when creating attributes:45- **type** — backend storage type (varchar, int, decimal, datetime, text, static)46- **input** — frontend input type (text, textarea, select, multiselect, boolean, date, price, media_image, etc.)47- **label** — human-readable name48- **required** — is this attribute mandatory?49- **source** — source model for select/multiselect options50- **backend** — backend model for validation/processing51- **frontend** — frontend model for display formatting52- **global** — scope: store view, website, or global53- **visible** — shown in admin forms54- **searchable** — indexed for catalog search55- **filterable** — available as layered navigation filter56- **comparable** — shown in product comparison57- **used_in_product_listing** — available in category listing pages5859### Attribute Sets and Groups6061- **Attribute Set** — a named collection of attributes (e.g., "Default", "Clothing", "Electronics")62- **Attribute Group** — organizes attributes within a set into tabs (e.g., "General", "Prices", "Images")63- Every product is assigned one attribute set64- The Default attribute set contains core attributes6566### Creating Attributes via Data Patch6768The modern approach uses Data Patches with `EavSetupFactory`:691. Create a data patch class in `Setup/Patch/Data/`702. Inject `EavSetupFactory` (or `CategorySetupFactory` for categories)713. Call `$eavSetup->addAttribute()` with entity type, code, and properties724. Assign to attribute set/group7374### Source Models7576For select/multiselect attributes, source models provide options:77- Built-in: `Magento\Eav\Model\Entity\Attribute\Source\Boolean`, `Table`78- Custom: extend `AbstractSource`, implement `getAllOptions()`7980### Static Attributes8182Attributes with type `static` are stored as columns directly on the entity table rather than in EAV value tables. Used for frequently queried fields (e.g., `sku`, `type_id`, `created_at`).8384### Best Practices8586- Use data patches (not install/upgrade scripts) for attribute creation87- Choose the correct backend type — `int` for select/boolean, `decimal` for prices88- Set `searchable`, `filterable`, `comparable` thoughtfully — each adds indexing overhead89- Use `static` type sparingly — it modifies the entity table schema90- Test attribute creation on a clean install and with `setup:upgrade`9192Fetch the attribute development docs for exact `addAttribute()` parameters, source model patterns, and current entity type constants before implementing.