Adding Attributes To Other Entities With getDefaultEntities()

Posted . Visible to the public.

Don't do it!! I did the below:

public function getDefaultEntities()
{
    return array(
        'catalog_product' => array(
            'attributes' => array(
                'size_guide_id' => array(
                    'group'                      => 'General',
                    'label'                      => 'Size Guide',
                    'type'                       => 'int',
                    'input'                      => 'select',
                    'source_model'               => 'sizeguide/guide_adminhtml_source',
                    'default'                    => '0',
                    'class'                      => '',
                    'backend'                    => '',
                    'frontend'                   => '',
                    'source'                     => '',
                    'global'                     => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
                    'visible'                    => true,
                    'required'                   => false,
                    'user_defined'               => false,
                    'searchable'                 => false,
                    'filterable'                 => false,
                    'comparable'                 => false,
                    'visible_on_front'           => false,
                    'visible_in_advanced_search' => false,
                    'unique'                     => false
                )
            )
        ),
        'sizeguide_guide' => array(
            'entity_model' => 'sizeguide/guide',
            'table'        => 'sizeguide/guide',
            'attributes'   => array(
                'display_name' => array(
                    'type'       => 'varchar',
                    'label'      => 'Display Name',
                    'input'      => 'text',
                    'sort_order' => 10,
                    'global'     => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
                    'group'      => 'General Information',
                ),
                'status'       => array(
                    'type'       => 'int',
                    'label'      => 'Is Active',
                    'input'      => 'select',
                    'source'     => 'eav/entity_attribute_source_boolean',
                    'sort_order' => 15,
                    'global'     => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
                    'group'      => 'General Information',
                ),
                'content'      => array(
                    'type'       => 'text',
                    'label'      => 'Content',
                    'input'      => 'textarea',
                    'sort_order' => 20,
                    'global'     => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
                    'group'      => 'General Information',
                ),
            ),
        ),
    );
}

And look what happened:

mysql> select * from eav_entity_type where entity_type_id = 4\G
*************************** 1. row ***************************
             entity_type_id: 4
           entity_type_code: catalog_product
               entity_model: 
            attribute_model: NULL
               entity_table: eav/entity
         value_table_prefix: NULL
            entity_id_field: NULL
            is_data_sharing: 1
           data_sharing_key: default
   default_attribute_set_id: 4
            increment_model: NULL
        increment_per_store: 0
       increment_pad_length: 8
         increment_pad_char: 0
 additional_attribute_table: NULL
entity_attribute_collection: NULL
1 row in set (0.01 sec)

Basically it killed the entity type I was adding an attribute to.

Mike Whitby
Posted by Mike Whitby to Magento (2014-05-23 13:56)