I want to add options in an attributes programmatically like in Size attribute i want S,M,L,XL as an option . My code is creating attribute but i want options with attributes.
require_once '../app/Mage.php';
Mage::app();
// Attribute basic data
$attributeName = 'Sizes'; // Name of the attribute
$attributeCode = 'Sizes'; // Code of the attribute
//$attributeGroup = 'Custom Group'; // Group to add the attribute to
// Attribute configuration data
$data = array(
'type' => 'varchar', // Attribute type
'input' => 'select', // Input type
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // Attribute scope
'required' => true, // Is this attribute required?
'user_defined' => false,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'used_in_product_listing' => true,
// Adding basic data
'label' => $attributeName,
);
$data['value']['any_option_name'][0] = 'S';
// Installer code to create attribute with new installer class (can be used in non-EAV setup)
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
$installer->startSetup();
$installer->addAttribute('catalog_product', $attributeCode, $data);
// Notice: Default Attribute Set have ID 4
// Add the attribute to the all attribute proper sets and proper groups:
$entity = Mage_Catalog_Model_Product::ENTITY;
$attributeSetIds = $installer->getAllAttributeSetIds($entity);
foreach($attributeSetIds as $attributeSetId)
{
$installer->addAttributeToGroup('catalog_product', $attributeSetId, $attributeCode);
}
$installer->endSetup();