![]() |
VOOZH | about |
This document details the attribute system within Maho's catalog module, focusing on flexible product and category metadata management using the Entity-Attribute-Value (EAV) model. It covers attribute definitions, attribute sets, attribute groups, attribute scopes, attribute loading and caching, and specialized attribute handling.
For broader context, see EAV System for architecture details, Product Types for product-specific features, and Category Management for categories.
Attributes in Maho are defined once in the eav_attribute table but can be assigned to multiple entity types such as products and categories. Mage_Eav_Model_Entity_Attribute_Abstract (defined at app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php47-243) is the base attribute model, extended by catalog-specific class Mage_Catalog_Model_Resource_Eav_Attribute (app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php56-145) which adds catalog-specific behavior and properties.
Attributes map to data stored in backend tables depending on their backend_type (e.g., int, varchar, text). For product and category attributes, these backend data values are stored in entity-specific tables such as catalog_product_entity_int, catalog_product_entity_varchar, etc.
Sources:
app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php56-64
app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php47-243
app/code/core/Mage/Eav/Model/Entity/Abstract.php72-110
Attributes are defined by metadata fields mainly in eav_attribute and extended in entity-specific tables. The catalog attribute model (Mage_Catalog_Model_Resource_Eav_Attribute) manages additional properties and validation logic.
Key attribute properties include:
| Property | Type | Description | Getter Method / Location |
|---|---|---|---|
attribute_code | varchar | Unique code (e.g. name, price) | getAttributeCode() Entity/Attribute/Abstract.php211 |
entity_type_id | int | Entity type reference (product/category) | getTypeId() Entity/Abstract.php284 |
backend_type | varchar | Storage type (int, varchar, text, etc.) | getBackendType() Entity/Attribute/Abstract.php245 |
frontend_input | varchar | Input form type (e.g., text, select) | getFrontendInput() Entity/Attribute/Abstract.php21 |
is_required | int | Whether this is mandatory | getIsRequired() Entity/Attribute/Abstract.php29 |
is_user_defined | int | System (0) vs user-defined (1) | getIsUserDefined() Entity/Attribute/Abstract.php32 |
Attribute scope constants, defined in Mage_Catalog_Model_Resource_Eav_Attribute:
| Constant | Value | Description |
|---|---|---|
SCOPE_STORE | 0 | Scoped per store view |
SCOPE_GLOBAL | 1 | Global single value |
SCOPE_WEBSITE | 2 | Scoped per website |
Sources:
app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php58-60
app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php209-246
Attributes are organized into attribute sets, which group attributes logically and determine the attributes available for particular entities. Entity types (like catalog_product) have attribute sets identified by attribute_set_id. Each attribute set contains attribute groups which hold individual attributes for admin UI grouping and sorting.
Each attribute is mapped to a group within the set defining its position and organization. Attribute sets control which attributes apply to products or categories.
Sources:
app/code/core/Mage/Eav/Model/Entity/Type.php151-158
app/code/core/Mage/Eav/Model/Config.php57-69
System attributes (is_user_defined = 0) are core platform attributes created during setup scripts. They are protected against deletion and often have specialized handling. For example, the price attribute is automatically assigned a specific backend model during the _beforeSave phase if unset (app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php107-111).
User-defined attributes (is_user_defined = 1) can be created, modified, or deleted by store administrators programmatically or via the admin UI.
Sources:
app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php94-118
app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php32
Attributes can have values scoped to different levels to support multi-store.
The scope is checked using methods like isScopeGlobal(), isScopeWebsite(), and isScopeStore() in Mage_Catalog_Model_Resource_Eav_Attribute (app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php179-202).
Sources:
app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php58-60
app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php179-202
Mage_Eav_Model_Config acts as the central EAV configuration registry managing attribute type and attribute data caching, entity types, and attribute sets. This class loads and caches EAV metadata to avoid repeated database lookups during requests (app/code/core/Mage/Eav/Model/Config.php133-173).
Updating or deleting an attribute clears the EAV configuration cache to ensure changes propagate immediately. This is done explicitly in _afterSave and _afterDeleteCommit hooks in Mage_Catalog_Model_Resource_Eav_Attribute (app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php121-129 app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php154-162 respectively).
This system guarantees attribute data consistency and efficient retrieval.
Sources:
app/code/core/Mage/Eav/Model/Config.php133-173
app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php121-129
app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php120-145
Attributes with frontend input type price are automatically assigned the backend model catalog/product_attribute_backend_price if none is explicitly set during save (app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php107-111).
Attributes can be flagged for inclusion in price rules (is_used_for_promo_rules), customer segmentation (is_used_for_customer_segment), or target rules (app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php48-51) enabling advanced promotional and segment functionality.
Maho supports dynamic categories that select products via attribute-based rules leveraging the Mage_Rule subsystem. Mage_Catalog_Model_Category_Dynamic_Rule validates product attributes against conditions defined by Mage_Rule_Model_Condition_Abstract (app/code/core/Mage/Catalog/Model/Category/Dynamic/Rule.php150-165).
Mage_Rule models define reusable, composable conditions on attributes. The abstract condition Mage_Rule_Model_Condition_Abstract allows specifying attribute, operator (e.g., is, contains, in list), and value (app/code/core/Mage/Rule/Model/Condition/Abstract.php141-157). Complex logical combinations are modeled by Mage_Rule_Model_Condition_Combine, allowing AND/OR nesting (app/code/core/Mage/Rule/Model/Condition/Combine.php40-50).
Product and category SEO-friendly URLs are managed using attributes like url_key and url_path. The Mage_Catalog_Model_Url class handles URL path generation and rewriting (app/code/core/Mage/Catalog/Model/Url.php129-151). If a category's url_path is empty, it is generated dynamically from its hierarchy.
Sources:
app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php107-111
app/code/core/Mage/Catalog/Model/Category/Dynamic/Rule.php150-165
app/code/core/Mage/Rule/Model/Condition/Abstract.php141-157
app/code/core/Mage/Rule/Model/Condition/Combine.php40-50
app/code/core/Mage/Catalog/Model/Url.php129-151
Sources: Combination of all above source files
Sources: Synthesized from all relevant source files in EAV and Catalog modules
Mage_Eav_Model_Config — EAV configuration and attribute management app/code/core/Mage/Eav/Model/Config.phpMage_Eav_Model_Entity_Attribute_Abstract — Base EAV attribute model app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.phpMage_Catalog_Model_Resource_Eav_Attribute — Catalog attribute model and resource app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.phpMage_Eav_Model_Entity_Type — Entity type and attribute set loading app/code/core/Mage/Eav/Model/Entity/Type.phpMage_Rule_Model_Condition_Abstract — Rule condition base class app/code/core/Mage/Rule/Model/Condition/Abstract.phpMage_Rule_Model_Condition_Combine — Logical combination of rule conditions app/code/core/Mage/Rule/Model/Condition/Combine.phpMage_Catalog_Model_Url — URL and SEO attribute handling app/code/core/Mage/Catalog/Model/Url.phpMage_Catalog_Model_Category_Dynamic_Rule — Dynamic category rules using attribute conditions app/code/core/Mage/Catalog/Model/Category/Dynamic/Rule.phpThis page details the low-level workings of Maho's flexible attribute system, essential for catalog extensibility and powering complex rules and SEO-friendly URLs.
Refresh this wiki