Monday, July 16, 2012

Creating Product And Category Attributes By Script

// product attribute

$installer->addAttribute('catalog_product', 'test',
    array(
    'attribute_set'     => 'Default',
    'group'             => 'General',
    'type' => 'int',
    'input' => 'select',
    'label' => 'Test',
    'source' => 'eav/entity_attribute_source_table',
    'required' => false,
    'visible'           => true,
    'user_defined' => true,
    'unique' => false,
    'used_for_sort_by' => false,
    'searchable'        => true,
    'filterable'        => true,
    'is_filterable_in_search' => true,
    'used_in_product_listing' => true,
    'default' => false,
    'global'        =>  Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
            'option'            => array (
                                   'value' => array(
                                            'optionone'            =>array(0=>'option1'),
                                            'optiontwo'            =>array(0=>'option2'),
                                            'optionthree'        =>array(0=>'option3'),
                                            'optionfour'        =>array(0=>'option4'),
                                            )
                               ),
    'configurable'        => true
   )
);

$installer->addAttribute('catalog_product', 'test',
    array(
    'attribute_set'     => 'Default',
    'group'             => 'General',
    'type' => 'varchar',
    'input' => 'text',
    'label' => 'Test',
    'source' => '',
    'required' => false,
    'user_defined' => true,
    'visible_on_front'           => false,  
    'visible'           => true,
    'unique' => false,
    'used_in_product_listing' => false,
    'default' => false,
    'global'        =>  Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
   )
);


//Category Attributes
//type image

$installer->addAttribute('catalog_category', 'image', array(
    'group'         => 'General',
    'input'         => 'image',
    'type'          => 'varchar',
    'label'         => 'Image',
    'backend'       => 'catalog/category_attribute_backend_image',
    'visible'       => 1,
    'required'        => 0,
    'user_defined' => 1,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));





No comments:

Post a Comment