VOOZH about

URL: https://deepwiki.com/MahoCommerce/maho/4.3-eav-system

⇱ EAV System | MahoCommerce/maho | DeepWiki


Loading...
Last indexed: 15 May 2026 (ea8ab8)
Menu

EAV System

Purpose and Scope

This document provides a deep dive into Maho's Entity-Attribute-Value (EAV) architecture. The EAV system is a data modeling pattern used to store entities where the number of attributes can be vast and varies significantly between instances (e.g., Products, Categories, Customers). This architecture allows for dynamic attribute management without database schema changes and supports multi-store data inheritance.

Core Architecture

The EAV system separates the definition of an entity from its attributes and their values. In Maho, this is implemented through a hierarchy of classes starting from Mage_Eav_Model_Entity_Abstract app/code/core/Mage/Eav/Model/Entity/Abstract.php13-14

Natural Language to Code Entity Mapping

The following diagram bridges the conceptual EAV space with the specific classes and tables used in the Maho codebase.


Sources: app/code/core/Mage/Eav/Model/Entity/Abstract.php250-254 app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php56-63

EAV Configuration and Initialization

Maho optimizes EAV performance by eagerly loading entity types and caching metadata. Mage_Eav_Model_Config serves as the central registry for all EAV metadata app/code/core/Mage/Eav/Model/Config.php13-14

Sources: app/code/core/Mage/Eav/Model/Config.php13-21 app/code/core/Mage/Eav/Model/Config.php179-200

Data Flow: Loading an EAV Entity

When an EAV model is loaded, the system first retrieves the static attributes from the main entity table and then joins or performs sub-queries to fetch dynamic attributes from type-specific value tables.


Sources: app/code/core/Mage/Eav/Model/Entity/Abstract.php179-200 app/code/core/Mage/Eav/Model/Entity/Abstract.php259-267

Attribute Management

Attributes are managed through the Mage_Eav_Model_Entity_Attribute class and its resource models. In the catalog module, Mage_Catalog_Model_Resource_Eav_Attribute extends this to add catalog-specific properties like searchability and frontend display logic app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php56-63

Attribute Types and Backend Storage

Attributes are categorized by their backend_type, which determines the database table used for storage app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php235-246:

Backend TypeValue Table ExampleData Type
staticcatalog_product_entityColumn in main table
varcharcatalog_product_entity_varcharvarchar(255)
intcatalog_product_entity_intint
textcatalog_product_entity_texttext / longtext
decimalcatalog_product_entity_decimaldecimal(12,4)
datetimecatalog_product_entity_datetimedatetime

Sources: app/code/core/Mage/Eav/Model/Entity/Abstract.php38-62 app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php49 app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php107-111

Attribute Scopes

Maho supports three levels of attribute scope, defined in Mage_Catalog_Model_Resource_Eav_Attribute app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php58-60:

  1. Global (SCOPE_GLOBAL): Value is shared across all websites and stores app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php179-182
  2. Website (SCOPE_WEBSITE): Value can vary between different websites app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php189-192
  3. Store (SCOPE_STORE): Value can vary between different store views app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php199-202

Collection Loading and Filtering

EAV collections manage complex queries involving the main entity table and multiple attribute value tables.

The Collection Pipeline


Sources: app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php143-152 app/code/core/Mage/Eav/Model/Entity/Abstract.php113-117

Rule System Integration

Maho integrates the EAV system with a flexible Rule engine. Rules consist of conditions (represented by Mage_Rule_Model_Condition_Abstract) and actions.

Condition Logic

Conditions allow for complex logical evaluations against entity attributes.

SQL Generation

Rules can generate SQL fragments to filter collections directly at the database level via prepareConditionSql() app/code/core/Mage/Rule/Model/Condition/Combine.php38-51

Sources: app/code/core/Mage/Rule/Model/Condition/Abstract.php43-100 app/code/core/Mage/Rule/Model/Condition/Combine.php23-51

Key Classes and Functions

Mage_Eav_Model_Entity_Abstract

The base class for all EAV resource models. It manages the connection to read/write adapters app/code/core/Mage/Eav/Model/Entity/Abstract.php179-199 and provides the logic for entity type initialization app/code/core/Mage/Eav/Model/Entity/Abstract.php250-254

Mage_Eav_Model_Config

The singleton that manages EAV metadata. It handles cache invalidation via clear() app/code/core/Mage/Eav/Model/Config.php95-108 and manages the mapping of attribute codes to IDs for performance app/code/core/Mage/Eav/Model/Config.php54

Mage_Catalog_Model_Resource_Eav_Attribute

Specialized attribute model for the catalog. It includes logic for determining if an attribute is used in configurable products app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php101-106 and handles indexing events during deletion app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php135-146

Performance Considerations

The EAV system is highly flexible but can be performance-intensive due to the number of joins required for a single entity load. Maho mitigates this through:

  1. Flat Catalog: Denormalizing EAV data into flat tables for frontend performance.
  2. Attribute Sets: Limiting the attributes loaded to only those relevant to the specific entity's set app/code/core/Mage/Eav/Model/Config.php69
  3. Metadata Caching: Caching entity type and attribute definitions in the EAV_DATA_CACHE app/code/core/Mage/Eav/Model/Config.php21
  4. Eager Loading: The Mage_Eav_Model_Config class loads entity types and attributes in bulk to minimize database roundtrips app/code/core/Mage/Eav/Model/Config.php133-164

Sources: app/code/core/Mage/Eav/Model/Config.php147-151 app/code/core/Mage/Eav/Model/Config.php153-164