Question

In the "eav_attribute" table I discovered that some attributes have the backend type set to "static".

Example, attribute_code = 'telephone' & entity_type_id = 2 resulted in a "static" backend type. Furthermore, most of the attributes entity_type_id = 2 are set to 'static'. (in my db id 2 is for address attributes)

What type does this value represent? Should I use it instead of using 'varchar' for similar attributes?

Was it helpful?

Solution

Static attributes are attributes stored in the main table of an entity - for catalog products, catalog_product_entity. For example, the attribute sku of catalog products is defined as static. Static attributes are always loaded by Magento, and are useful especially if you want to retrieve information quickly or to optimize lookup of data. A drawback of this type of attributes is that you can't have store-specific values, which is one of the advantages of Magento EAV system.

Even if you define an attribute as static, Magento won't treat it as such unless you have a corresponding column in the main entity table. If the column is not there, Magento treats the attribute as varchar by default and looks for it in the varchar EAV table for the model - for products, catalog_product_entity_varchar.

If you want to use static attributes in your project, you have to do 2 things in your install/upgrade scripts. First, you need to add a column to the main entity table, with the correct column definition. Next, you need to install your attribute using the addAttribute() method, and define your attribute as static.

If you plan to run often queries based on your custom static attributes, consider adding an index on the new column to speed up data fetching.

You can check the detailed MySql version answer on

https://mage2.pro/t/topic/655

https://blog.magestore.com/magento-certificate-databases-tables-for-eav-entities/

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top