What does backend Type Static mean in magento? Posted on
January 28,201 1
By
Fangcaoyuan owner
About
A year ago, I noticed some category or product attributes, for example,
SKU, path, Etc., were given backend type "static" in class
Mage_catalog_model_resource_eav_mysql4_setup. But I failed to find out
What static meant here, or I did not know what the difference was
Between static and datetime/decimal/INT/text/varchar. All I knew
That time was if I gave my user defined attribute a "static" type,
Attribute values were stored in _ varchar table.
Recently, I dived deeper into magento EAV module. Now I can answer my question.
An entity can have some "static" attributes, whose values are stored
In Entity main table. Take SKU for example, SKU values are stored in
Catalog_product_entity table. Although SKU is varchar type, its values
Are not stored in catalog_product_entity_varchar. magento does not
Lookup catalog_product_entity_varchar for SKU values because in
Eav_attribute table, SKU backend type is defined as "static ".
It also explains why I can get SKU values without add it to select, but I can not do the same with non static attributes.
View Source
Print
?
1 |
$collection = Mage::getModel(
'catalog/product'
)->getCollection(); |
2 |
echo $collection
->getFirstItem()->getSku(); |
It will output the SKU.
View Source
Print
?
1 |
$collection = Mage::getModel(
'catalog/product'
)->getCollection(); |
2 |
echo $collection
->getFirstItem()->getName(); |
It will not output the name.
View Source
Print
?
1 |
$collection = Mage::getModel(
'catalog/product'
)->getCollection()->addAttributeToSelect(
'name'
); |
2 |
echo $collection
->getFirstItem()->getName(); |
Calling addattributetoselect is a must to retrieve non static attribute values.
For user defined attributes of existing entity, if I do not change
The structure of main entity table, even I specify backend as "static"
In Entity setup class, magento has nowhere to store their values to
Fallback to _ varchar table.