Marceli Po
Marceli Po

Reputation: 743

How can I add custom dropdown product attribute with options and their positions programmatically?

Like in subject I would like to add custom dropdown product attribute with options and their positions programmatically so I will be able to achieve list like in attached image.

Upvotes: 1

Views: 4180

Answers (1)

You can use like following in your installer script.

$installer->addAttribute('catalog_product', "shirt_size", array(
'type'       => 'int',
'input'      => 'select',
'label'      => 'Size',
'source' => '',
'sort_order' => 1000,
'required'   => false,
'global'     => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'backend'    => 'eav/entity_attribute_backend_array',
'option'     => array (
    'values' => array(
        0 => 'Small',
        1 => 'Medium',
        2 => 'Large',
    )
),

));

Upvotes: 2

Related Questions