I am using the code listed on the following link:
http://www.magentocommerce.com/wiki/5_-_modules_and_development/catalog/programmatically_adding_attributes_and_att
You will need to have a block in your modules config.xml that looks like so
Namespace_Module
Mage_Eav_Model_Entity_Setup
This will allow you to place your installer code in the directory that is in your XML. You need to make sure that the version listed on the installer file matches the
of your module otherwise Magento will not be able to run your installer. To add an attribute Set, you can use the following data, I have never use it, but the entityTypeId defines whether it is a customer, shipping, category, product entity, each 1, 2, 3, 4 respectively.
/**
* Add Attribute Set
*
* @param mixed $entityTypeId
* @param string $name
* @param int $sortOrder
* @return Mage_Eav_Model_Entity_Setup
*/
public function addAttributeSet($entityTypeId, $name, $sortOrder = null)
{
$data = array(
'entity_type_id' => $this->getEntityTypeId($entityTypeId),
'attribute_set_name' => $name,
'sort_order' => $this->getAttributeSetSortOrder($entityTypeId, $sortOrder),
);
$setId = $this->getAttributeSet($entityTypeId, $name, 'attribute_set_id');
if ($setId) {
$this->updateAttributeSet($entityTypeId, $setId, $data);
} else {
$this->_conn->insert($this->getTable('eav/attribute_set'), $data);
$this->addAttributeGroup($entityTypeId, $name, $this->_generalGroupName);
}
return $this;
}
This is the code for adding an attribute to a set, just change the attribute set data
//app/code/local/Namespace/Module/sql/Namespace_Module_setup/mysql4-install-1.0.0.php
$installer = $this;
/* @var $installer Mage_Eav_Model_Entity_Setup */
$installer->startSetup();
$data= array (
'attribute_set' => 'Default',
'group' => 'General',
'label' => 'Some Label',
'visible' => true,
'type' => 'varchar', // multiselect uses comma-sep storage
'input' => 'text',
'system' => true,
'required' => false,
'user_defined' => 1, //defaults to false; if true, define a group
);
$installer->addAttribute('catalog_product','attriute_code',$data)
$installer->endSetup();
The above is a working example of an attribute installation for a module.