Install attribute in entity main table

Sometimes it is useful to add some fields to the attribute main table (f.e.: IDs from external systems like a middleware or a PIM). In the following example you can see how to add ID-fields to the category entity. Therefore I created a setupscript as an instance of Mage_Catalog_Model_Resource_Setup.

  • Setup-model declaration in config.xml:
    <?xml version="1.0"?>
                        <!-- #### Setup Model instance type declaration #### -->   
        <!-- ... -->
  • Setup-script:
    /* @var $oInstaller Mage_Catalog_Model_Resource_Setup */
    $oInstaller = $this;
    $aAttributes = array(
        'tb_id' => array(
            'label'             =>  Mage::helper('sheldon_module')->__('TB-ID'),
            'required'          =>  false,
            'type'              =>  'static', //TO BE FOUND IN THE MAIN-TABLE (f.e.:category_entity)
            'input'             =>  'text',
            'group'             =>  'Tradebyte',
            'global'            =>  Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
            'visible'           =>  1,
            'unique'            =>  1,
            'frontend_class'    =>  'disabled',
            'note'              =>  'Unique tradebyte category id',
            'sort_order'        =>  1,
            'input_renderer'    =>  'sheldon_module/adminhtml_catalog_form_renderer_element_text_disabled'
        'tb_parent_id'=> array(
            'label'             =>  Mage::helper('sheldon_module')->__('TB-Parent-ID'),
            'required'          =>  false,
            'type'              =>  'static',
            'input'             =>  'text',
            'group'             =>  'Tradebyte',
            'global'            =>  Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
            'visible'           =>  1,
            'frontend_class'    =>  'disabled',
            'note'              =>  'Unique tradebyte category id of parent category',
            'sort_order'        =>  2,
            'input_renderer'    =>  'sheldon_module/adminhtml_catalog_form_renderer_element_text_disabled'
    $iCategoryEntityTypeId = $oInstaller->getEntityTypeId('catalog_category');
    $sMainTable = $oInstaller->getTable('catalog/category');
    $oConnection = $oInstaller->getConnection();
    foreach($aAttributes as $sCode => $aConfig){
            'int(11) default NULL'
        $oInstaller->addAttribute($iCategoryEntityTypeId, $sCode, $aConfig);
    // mark index as "reindex required"
    $indexerCodes = array(
    $indexer = Mage::getModel('index/process');
    foreach ($indexerCodes as $code) {
        $indexer->load($code, 'indexer_code')
    //clear EAV Cache:


Hint: if you want to save the attribute via $oProduct->getResource()->saveAttribute($oProduct, $mCode);  you have to define a backend-model which extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract (or even Mage_Catalog_Model_Product_Attribute_Backend_Sku).

Otherwise you will run into errors like:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'catalog_product_entity.value_id' in 'field list', query was: SELECT `catalog_product_entity`.`value_id` FROM `catalog_product_entity` WHERE (entity_type_id=4 AND attribute_id='176' AND entity_id='2308')

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.