Magento Certified Developer GuideCategory: 5. EAVWhich setup methods are available to work with EAV entities?
Manish Prakash Staff asked 2 years ago

There are many setup methods available in Mage_Eav_Model_Entity_Setup

$setup = new Mage_Eav_Model_Entity_Setup();
/*
$data = array(
            'entity_type_code'              => $code,
            'entity_model'                  => $params['entity_model'],
            'attribute_model'               => $this->_getValue($params, 'attribute_model'),
            'entity_table'                  => $this->_getValue($params, 'table', 'eav/entity'),
            'value_table_prefix'            => $this->_getValue($params, 'table_prefix'),
            'entity_id_field'               => $this->_getValue($params, 'id_field'),
            'increment_model'               => $this->_getValue($params, 'increment_model'),
            'increment_per_store'           => $this->_getValue($params, 'increment_per_store', 0),
            'increment_pad_length'          => $this->_getValue($params, 'increment_pad_length', 8),
            'increment_pad_char'            => $this->_getValue($params, 'increment_pad_char', 0),
            'additional_attribute_table'    => $this->_getValue($params, 'additional_attribute_table'),
            'entity_attribute_collection'   => $this->_getValue($params, 'entity_attribute_collection'),
        );
*/
$setup->addEntityType($code,$params);
$setup->updateEntityType($code,$field,$value);
$setup->getEntityType($id);
$setup->getEntityTypeId($id);
$setup->removeEntityType($id);

/** attribute sets **/
$setup->getAttributeSetSortOrder($entityTypeId);
$setup->addAttributeSet($entityTypeId,$name);
$setup->updateAttributeSet($entityTypeId,$id,$field,$value);
$setup->getAttributeSet($entityTypeId,$id);
$setup->getAttributeSetId($entityTypeId,$id);
$setup->removeAttributeSet($entityTypeId, $id);

/** attribute groups **/
$setup->addAttributeGroup($entityTypeId, $setId, $name);
$setup->updateAttributeGroup($entityTypeId, $setId, $id, $field, $value = null);
$setup->getAttributeGroupId($entityTypeId, $setId, $groupId);
$setup->removeAttributeGroup($entityTypeId, $setId, $id);
$setup->getDefaultAttributeGroupId($entityType, $attributeSetId);

/** attributes **/
/**
$data = array(
            'backend_model'   => $this->_getValue($attr, 'backend'),
            'backend_type'    => $this->_getValue($attr, 'type', 'varchar'),
            'backend_table'   => $this->_getValue($attr, 'table'),
            'frontend_model'  => $this->_getValue($attr, 'frontend'),
            'frontend_input'  => $this->_getValue($attr, 'input', 'text'),
            'frontend_label'  => $this->_getValue($attr, 'label'),
            'frontend_class'  => $this->_getValue($attr, 'frontend_class'),
            'source_model'    => $this->_getValue($attr, 'source'),
            'is_required'     => $this->_getValue($attr, 'required', 1),
            'is_user_defined' => $this->_getValue($attr, 'user_defined', 0),
            'default_value'   => $this->_getValue($attr, 'default'),
            'is_unique'       => $this->_getValue($attr, 'unique', 0),
            'note'            => $this->_getValue($attr, 'note'),
            'is_global'       => $this->_getValue($attr, 'global', 1),
        );
**/
$setup->addAttribute($entityTypeId, $code,$attr);
$setup->addAttributeOption($option);
$setup->updateAttribute($entityTypeId, $id, $field, $value, $sortOrder);
$setup->updateAttribute($entityTypeId, $id, $field, $value, $sortOrder);
$setup->getAttribute($entityTypeId, $id);
$setup->removeAttribute($entityTypeId, $code);
$setup->addAttributeToSet($entityTypeId, $setId, $groupId, $attributeId, $sortOrder);
$setup->addAttributeToGroup($entityType, $setId, $groupId, $attributeId, $sortOrder);