25

Can someone explain the importance/relevance of the backend_type static for an attribute?

I am having some problems with an attribute not being loaded and I'm wondering whether this backend_type has anything to do with it?

Also, is this related in some way as to what is put in the flat tables?

7ochem
7,61516 gold badges54 silver badges82 bronze badges
asked May 22, 2013 at 9:12

2 Answers 2

46

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. Please refer to the install scripts of Mage_Catalog to better understand how things work in this case.

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.

answered May 22, 2013 at 9:35
2
  • 2
    category_ids is static. it's not in the catalog_product_entity_varchar table. Commented Jul 29, 2016 at 18:31
  • summary: static means the value is a column in catalog_product_entity, and if it's not, it will fall back to checking in catalog_product_entity_varchar. Commented Apr 12, 2017 at 19:04
1

Here is the sample from core:

$installer->run("
 ALTER TABLE `{$installer->getTable('catalog/product')}` ADD `has_options` SMALLINT(1) NOT NULL DEFAULT '0';
");
$installer->addAttribute('catalog_product', 'has_options', array(
 'type' => 'static',
 'visible'=>false,
 'default' => false
));
answered Sep 19, 2013 at 8:31
3
  • 1
    What's this have to do with the question? Commented Sep 19, 2013 at 10:39
  • @Marius this is just a sample of how to add a static attribute. Commented Sep 19, 2013 at 15:57
  • Suppose you add the column directly to the DB via MySQL. How could you alter the TYPE of an existing product attribute to STATIC? Question: could we just update type=static in a certain table and it would work? Commented Jun 18, 2017 at 13:29

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.