![]() |
VOOZH | about |
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.
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
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
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
EAV_DATA_CACHE key app/code/core/Mage/Eav/Model/Config.php21_loadEntityTypes() app/code/core/Mage/Eav/Model/Config.php179-184 It verifies that the entity_model class exists before processing to prevent errors from disabled modules app/code/core/Mage/Eav/Model/Config.php191-200Sources: app/code/core/Mage/Eav/Model/Config.php13-21 app/code/core/Mage/Eav/Model/Config.php179-200
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
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
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 Type | Value Table Example | Data Type |
|---|---|---|
static | catalog_product_entity | Column in main table |
varchar | catalog_product_entity_varchar | varchar(255) |
int | catalog_product_entity_int | int |
text | catalog_product_entity_text | text / longtext |
decimal | catalog_product_entity_decimal | decimal(12,4) |
datetime | catalog_product_entity_datetime | datetime |
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
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:
SCOPE_GLOBAL): Value is shared across all websites and stores app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php179-182SCOPE_WEBSITE): Value can vary between different websites app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php189-192SCOPE_STORE): Value can vary between different store views app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php199-202EAV collections manage complex queries involving the main entity table and multiple attribute value tables.
Sources: app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php143-152 app/code/core/Mage/Eav/Model/Entity/Abstract.php113-117
Maho integrates the EAV system with a flexible Rule engine. Rules consist of conditions (represented by Mage_Rule_Model_Condition_Abstract) and actions.
Conditions allow for complex logical evaluations against entity attributes.
Mage_Rule_Model_Condition_Combine allows nesting conditions using "ALL" or "ANY" aggregators app/code/core/Mage/Rule/Model/Condition/Combine.php23-51==, !=, >=, >, {}, and () are supported depending on the attribute input type app/code/core/Mage/Rule/Model/Condition/Abstract.php117-133Rules 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
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
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
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
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:
EAV_DATA_CACHE app/code/core/Mage/Eav/Model/Config.php21Mage_Eav_Model_Config class loads entity types and attributes in bulk to minimize database roundtrips app/code/core/Mage/Eav/Model/Config.php133-164Sources: app/code/core/Mage/Eav/Model/Config.php147-151 app/code/core/Mage/Eav/Model/Config.php153-164
Refresh this wiki